From f6fc8cd9bd5977251b4660ac8a19716dd3e67993 Mon Sep 17 00:00:00 2001 From: Jeroen Leenarts Date: Sun, 12 Aug 2018 21:40:44 +0200 Subject: [PATCH] Universal logging. Signed-off-by: Jason A. Donenfeld --- WireGuardNetworkExtension/WireGuardGoWrapper.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.m b/WireGuardNetworkExtension/WireGuardGoWrapper.m index 2d6056d..8deb527 100644 --- a/WireGuardNetworkExtension/WireGuardGoWrapper.m +++ b/WireGuardNetworkExtension/WireGuardGoWrapper.m @@ -84,6 +84,7 @@ static void do_log(int level, const char *tag, const char *msg); static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len) { +// os_log_debug([WireGuardGoWrapper log], "do_read - start - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx; if (wrapper.isClosed) return -1; @@ -99,9 +100,11 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len) [wrapper.packetFlow readPacketsWithCompletionHandler:^(NSArray * _Nonnull packets, NSArray * _Nonnull protocols) { [wrapper.packets addObjectsFromArray:packets]; [wrapper.protocols addObjectsFromArray:protocols]; + os_log_debug([WireGuardGoWrapper log], "do_read - signal - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); [wrapper.condition signal]; }]; }); + os_log_debug([WireGuardGoWrapper log], "do_read - wait - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); [wrapper.condition wait]; } @@ -113,15 +116,18 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len) NSUInteger packetLength = [packet length]; if (packetLength > len) { // The packet will be dropped when we end up here. + os_log_debug([WireGuardGoWrapper log], "do_read - drop - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); return 0; } memcpy(buf, [packet bytes], packetLength); - + os_log_debug([WireGuardGoWrapper log], "do_read - packet - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); return packetLength; } static ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len) { + os_log_debug([WireGuardGoWrapper log], "do_write - start"); + WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx; //TODO: determine IPv4 or IPv6 status. NSData *packet = [[NSData alloc] initWithBytes:buf length:len];