Browse Source

Merge pull request #418 from efryntov/server-timestamp-notice

Added NoticeServerTimestamp
Rod Hynes 8 years ago
parent
commit
b6d1ebd9b5

+ 7 - 0
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.h

@@ -278,6 +278,13 @@ Swift: @code func onInternetReachabilityChanged(_ currentReachability: Reachabil
  */
 - (void)onHomepage:(NSString * _Nonnull)url;
 
+/*!
+ Called when tunnel-core receives server timetamp in the handshake
+ @param timestamp  The server timestamp in RFC3339 format.
+ Swift: @code func onServerTimestamp(_ timestamp: String) @endcode
+ */
+- (void)onServerTimestamp:(NSString * _Nonnull)timestamp;
+
 @end
 
 /*!

+ 13 - 0
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

@@ -763,6 +763,19 @@
             });
         }
     }
+	else if ([noticeType isEqualToString:@"ServerTimestamp"]) {
+		id timestamp = [notice valueForKeyPath:@"data.timestamp"];
+		if (![timestamp isKindOfClass:[NSString class]]) {
+			[self logMessage:[NSString stringWithFormat: @"ServerTimestamp notice missing data.timestamp: %@", noticeJSON]];
+			return;
+		}
+
+		if ([self.tunneledAppDelegate respondsToSelector:@selector(onServerTimestamp:)]) {
+			dispatch_async(self->callbackQueue, ^{
+				[self.tunneledAppDelegate onServerTimestamp:timestamp];
+			});
+		}
+	}
     
     // Pass diagnostic messages to onDiagnosticMessage.
     if (diagnostic) {

+ 5 - 0
psiphon/notice.go

@@ -416,6 +416,11 @@ func NoticeSLOKSeeded(slokID string, duplicate bool) {
 	outputNotice("SLOKSeeded", noticeIsDiagnostic, "slokID", slokID, "duplicate", duplicate)
 }
 
+// NoticeServerTimestamp reports server side timestamp as seen in the handshake
+func NoticeServerTimestamp(timestamp string) {
+	outputNotice("ServerTimestamp", 0, "timestamp", timestamp)
+}
+
 type repetitiveNoticeState struct {
 	message string
 	repeats int

+ 1 - 0
psiphon/serverApi.go

@@ -244,6 +244,7 @@ func (serverContext *ServerContext) doHandshakeRequest(
 	}
 
 	serverContext.serverHandshakeTimestamp = handshakeResponse.ServerTimestamp
+	NoticeServerTimestamp(serverContext.serverHandshakeTimestamp)
 
 	return nil
 }