Outage detection.

This commit is contained in:
Matthew Chen 2018-06-19 12:09:44 -04:00
parent 20b1a2606e
commit c96e2bb8b4
3 changed files with 46 additions and 4 deletions

View File

@ -78,6 +78,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
@property (nonatomic) NSLayoutConstraint *hideDeregisteredViewConstraint;
@property (nonatomic) NSLayoutConstraint *hideArchiveReminderViewConstraint;
@property (nonatomic) NSLayoutConstraint *hideMissingContactsPermissionViewConstraint;
@property (nonatomic) NSLayoutConstraint *outageViewConstraint;
@property (nonatomic) TSThread *lastThread;
@ -166,6 +167,10 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
selector:@selector(deregistrationStateDidChange:)
name:DeregistrationStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(outageStateDidChange:)
name:OutageDetection.outageStateDidChange
object:nil];
}
- (void)dealloc
@ -198,6 +203,13 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
[self updateReminderViews];
}
- (void)outageStateDidChange:(id)notification
{
OWSAssertIsOnMainThread();
[self updateReminderViews];
}
#pragma mark - View Life Cycle
- (void)loadView
@ -233,6 +245,13 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
self.hideDeregisteredViewConstraint = [deregisteredView autoSetDimension:ALDimensionHeight toSize:0];
self.hideDeregisteredViewConstraint.priority = UILayoutPriorityRequired;
ReminderView *outageView = [ReminderView
nagWithText:NSLocalizedString(@"OUTAGE_WARNING", @"Label warning the user that the Signal service may be down.")
tapAction:nil];
[reminderStackView addArrangedSubview:outageView];
self.outageViewConstraint = [outageView autoSetDimension:ALDimensionHeight toSize:0];
self.outageViewConstraint.priority = UILayoutPriorityRequired;
ReminderView *archiveReminderView =
[ReminderView explanationWithText:NSLocalizedString(@"INBOX_VIEW_ARCHIVE_MODE_REMINDER",
@"Label reminding the user that they are in archive mode.")];
@ -291,16 +310,19 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
BOOL shouldHideArchiveReminderView = self.homeViewMode != HomeViewMode_Archive;
BOOL shouldHideMissingContactsPermissionView = !self.shouldShowMissingContactsPermissionView;
BOOL shouldHideDeregisteredView = !TSAccountManager.sharedInstance.isDeregistered;
BOOL shouldHideOutageView = !OutageDetection.sharedManager.hasOutage;
if (self.hideArchiveReminderViewConstraint.active == shouldHideArchiveReminderView
&& self.hideMissingContactsPermissionViewConstraint.active == shouldHideMissingContactsPermissionView
&& self.hideDeregisteredViewConstraint.active == shouldHideDeregisteredView) {
&& self.hideDeregisteredViewConstraint.active == shouldHideDeregisteredView
&& self.outageViewConstraint.active == shouldHideOutageView) {
return;
}
self.hideArchiveReminderViewConstraint.active = shouldHideArchiveReminderView;
self.hideMissingContactsPermissionViewConstraint.active = shouldHideMissingContactsPermissionView;
self.hideDeregisteredViewConstraint.active = shouldHideDeregisteredView;
self.outageViewConstraint.active = shouldHideOutageView;
[self.view setNeedsLayout];
[self.view layoutSubviews];

View File

@ -1405,6 +1405,9 @@
/* Info Message when {{other user}} updates message expiration to {{time amount}}, see the *_TIME_AMOUNT strings for context. */
"OTHER_UPDATED_DISAPPEARING_MESSAGES_CONFIGURATION" = "%@ set disappearing message time to %@.";
/* Label warning the user that the Signal service may be down. */
"OUTAGE_WARNING" = "Signal is experiencing technical difficulties. We are working hard to restore service as quickly as possible.";
/* No comment provided by engineer. */
"OUTGOING_CALL" = "Outgoing call";

View File

@ -10,10 +10,15 @@ public class OutageDetection: NSObject {
@objc(sharedManager)
public static let shared = OutageDetection()
@objc public static let outageStateDidChange = Notification.Name("OutageStateDidChange")
// These properties should only be accessed on the main thread.
private var hasOutage = false {
@objc
public var hasOutage = false {
didSet {
SwiftAssertIsOnMainThread(#function)
NotificationCenter.default.postNotificationNameAsync(OutageDetection.outageStateDidChange, object: nil)
}
}
private var mayHaveOutage = false {
@ -23,7 +28,14 @@ public class OutageDetection: NSObject {
ensureCheckTimer()
}
}
<<<<<<< HEAD
||||||| merged common ancestors
=======
// We want to be conversative and only
>>>>>>> Outage detection.
private func checkForOutageSync() -> Bool {
let host = CFHostCreateWithName(nil, "uptime.signal.org" as CFString).takeRetainedValue()
CFHostStartInfoResolution(host, .addresses, nil)
@ -42,9 +54,14 @@ public class OutageDetection: NSObject {
if getnameinfo(address.bytes.assumingMemoryBound(to: sockaddr.self), socklen_t(address.length),
&hostname, socklen_t(hostname.count), nil, 0, NI_NUMERICHOST) == 0 {
let addressString = String(cString: hostname)
if addressString != "127.0.0.1" {
Logger.verbose("\(logTag) addressString: \(addressString)")
let kHealthyAddress = "127.0.0.1"
let kOutageAddress = "127.0.0.2"
if addressString == kHealthyAddress {
// Do nothing.
} else if addressString == kOutageAddress {
isOutageDetected = true
} else {
owsFail("\(logTag) unexpected address: \(addressString)")
}
}
}