Просмотр исходного кода

Optional delegate method onServerTimestamp
in PsiphonTunnel, function rename in the tunnel-core

Eugene Fryntov 8 лет назад
Родитель
Сommit
4d8b0208bb

+ 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) {

+ 3 - 3
psiphon/notice.go

@@ -416,9 +416,9 @@ func NoticeSLOKSeeded(slokID string, duplicate bool) {
 	outputNotice("SLOKSeeded", noticeIsDiagnostic, "slokID", slokID, "duplicate", duplicate)
 }
 
-// NoticeServerTimeStamp reports server side timestamp seen in the handshake
-func NoticeServerTimeStamp(serverTimestamp string) {
-	outputNotice("ServerTimeStamp", 0, "timestamp", serverTimestamp)
+// NoticeServerTimestamp reports server side timestamp as seen in the handshake
+func NoticeServerTimestamp(timestamp string) {
+	outputNotice("ServerTimestamp", 0, "timestamp", timestamp)
 }
 
 type repetitiveNoticeState struct {

+ 1 - 1
psiphon/serverApi.go

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