From 05fe10612eaa989c5713e59976a7e62577b8bdfa Mon Sep 17 00:00:00 2001 From: Frederic Jacobs Date: Sun, 13 Jul 2014 00:40:05 +0200 Subject: [PATCH] Advanced network logging --- Signal/src/network/PacketHandler.m | 1 + Signal/src/network/tcp/tls/NetworkStream.m | 19 ++++++++++++++++--- .../signaling/ResponderSessionDescriptor.m | 2 -- .../network/http/HttpRequestResponseTest.m | 13 ++++++++----- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Signal/src/network/PacketHandler.m b/Signal/src/network/PacketHandler.m index e1f007cfa..4e472eb07 100644 --- a/Signal/src/network/PacketHandler.m +++ b/Signal/src/network/PacketHandler.m @@ -25,6 +25,7 @@ relatedInfo:(id)relatedInfo causedTermination:(bool)causedTermination { + DDLogError(@"Pack handler failed with error: %@ and info: %@", error, relatedInfo); errorHandler(error, relatedInfo, causedTermination); } diff --git a/Signal/src/network/tcp/tls/NetworkStream.m b/Signal/src/network/tcp/tls/NetworkStream.m index 04b13f522..d28c7a903 100644 --- a/Signal/src/network/tcp/tls/NetworkStream.m +++ b/Signal/src/network/tcp/tls/NetworkStream.m @@ -74,6 +74,7 @@ NSStreamStatus status = [outputStream streamStatus]; if (status < NSStreamStatusOpen) return; if (status >= NSStreamStatusAtEnd) { + DDLogError(@"Status of the stream: %lu", status); [rawDataHandler handleError:@"Wrote to ended/closed/errored stream." relatedInfo:nil causedTermination:false]; @@ -123,6 +124,7 @@ [futureOpenedSource trySetFailure:error]; [futureConnectedAndWritableSource trySetFailure:error]; [rawDataHandler handleError:error relatedInfo:nil causedTermination:true]; + DDLogError(@"Network failure happened on network stream: %@", error); [self terminate]; } } @@ -159,9 +161,20 @@ } -(void) onErrorOccurred:(id)fallbackError { - id error = [inputStream streamError]; - if (error == nil) error = [outputStream streamError]; - if (error == nil) error = fallbackError; + NSError *error; + + DDLogError(@"Stream status: %@", self.description); + + if ([inputStream streamError]) { + error = [inputStream streamError]; + DDLogError(@"Error on incoming stream : %@"); + } else if ([outputStream streamError]){ + error = [outputStream streamError]; + DDLogError(@"Error on outgoing stream: %@", error); + } else{ + error = fallbackError; + DDLogError(@"Fallback error: %@", fallbackError); + } [self onNetworkFailure:error]; } diff --git a/Signal/src/phone/signaling/ResponderSessionDescriptor.m b/Signal/src/phone/signaling/ResponderSessionDescriptor.m index e96b20799..6da69f8ad 100644 --- a/Signal/src/phone/signaling/ResponderSessionDescriptor.m +++ b/Signal/src/phone/signaling/ResponderSessionDescriptor.m @@ -78,8 +78,6 @@ NSString* relayServerName = parsedPayload.serverName; PhoneNumber* phoneNumber = [PhoneNumber phoneNumberFromE164:parsedPayload.initiator]; - DDLogDebug(@"Initiating call with session descriptor: %i UDP-Port:%hu sessionID:%lld, relayServerName:%@", interopVersion, relayUdpPort, sessionId, relayServerName); - return [ResponderSessionDescriptor responderSessionDescriptorWithInteropVersion:interopVersion andRelayUdpPort:relayUdpPort andSessionId:sessionId diff --git a/Signal/test/network/http/HttpRequestResponseTest.m b/Signal/test/network/http/HttpRequestResponseTest.m index a07a5b5cd..b138a344e 100644 --- a/Signal/test/network/http/HttpRequestResponseTest.m +++ b/Signal/test/network/http/HttpRequestResponseTest.m @@ -5,16 +5,19 @@ #import "HttpRequestUtil.h" #import "PreferencesUtil.h" #import "SignalUtil.h" +#import "SGNKeychainUtil.h" +#import @implementation HttpRequestResponseTest -(void) testRequestToInitiate { [Environment setCurrent:testEnv]; - [[[Environment getCurrent] preferences] setLocalNumberTo:[PhoneNumber phoneNumberFromE164:@"+19027778888"]]; - [[[Environment getCurrent] preferences] setValueForKey:@"Password" toValue:@"shall_not_password"]; + [SGNKeychainUtil setLocalNumberTo:[PhoneNumber phoneNumberFromE164:@"+19025555555"]]; + [UICKeyChainStore setString:@"shall_not_password" forKey:@"Password"]; [[[Environment getCurrent] preferences] setValueForKey:@"PasswordCounter" toValue:@2357]; HttpRequest* h = [HttpRequest httpRequestToInitiateToRemoteNumber:[PhoneNumber phoneNumberFromE164:@"+19023334444"]]; test([[h method] isEqualToString:@"GET"]); test([[h location] isEqualToString:@"/session/1/+19023334444"]); + NSLog(@"HTTP rep: %@", [h toHttp]); test([[h toHttp] isEqualToString:@"GET /session/1/+19023334444 HTTP/1.0\r\nAuthorization: OTP KzE5MDI3Nzc4ODg4OmluQ3lLcE1ZaFRQS0ZwN3BITlN3bUxVMVpCTT06MjM1Nw==\r\n\r\n"]); test([h isEqualToHttpRequest:[HttpRequest httpRequestFromData:[h serialize]]]); } @@ -27,9 +30,9 @@ } -(void) testRequestToRing { [Environment setCurrent:testEnv]; - [[[Environment getCurrent] preferences] setLocalNumberTo:[PhoneNumber phoneNumberFromE164:@"+19025555555"]]; - [[[Environment getCurrent] preferences] setValueForKey:@"Password" toValue:@"shall_not_password"]; - [[[Environment getCurrent] preferences] setValueForKey:@"PasswordCounter" toValue:@0]; + [SGNKeychainUtil setLocalNumberTo:[PhoneNumber phoneNumberFromE164:@"+19025555555"]]; + [UICKeyChainStore setString:@"shall_not_password" forKey:@"Password"]; + [UICKeyChainStore setString:[@0 stringValue] forKey:@"PasswordCounter"]; HttpRequest* h = [HttpRequest httpRequestToRingWithSessionId:458847238]; test([[h method] isEqualToString:@"RING"]); test([[h location] isEqualToString:@"/session/458847238"]);