Outage detection.

pull/1/head
Matthew Chen 7 years ago
parent 20b1a2606e
commit c96e2bb8b4

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

@ -1405,6 +1405,9 @@
/* Info Message when {{other user}} updates message expiration to {{time amount}}, see the *_TIME_AMOUNT strings for context. */ /* 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 %@."; "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. */ /* No comment provided by engineer. */
"OUTGOING_CALL" = "Outgoing call"; "OUTGOING_CALL" = "Outgoing call";

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

Loading…
Cancel
Save