Skip to content

Commit

Permalink
added som notifications and the dlog method for osx
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Jelveh committed Sep 3, 2010
1 parent bfaf1cf commit 14a5c41
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 12 additions & 0 deletions debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _DEBUG_H
#define _DEBUG_H

#ifdef _DARWIN_
#ifdef DEBUG
#define DLog( s, ... ) NSLog( @"<%s : (%d)> %@",__FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog(format, ...) do {} while (0)
#endif
#endif

#endif /* _DEBUG_H */
16 changes: 12 additions & 4 deletions osx/N2NThread.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "N2NThread.h"
#import "debug.h"

#import "n2n.h"

Expand Down Expand Up @@ -52,6 +53,8 @@ - (void)runLoop:(n2n_edge_t *)eee {

if([edgeThread isCancelled]){
NSLog(@"N2NThread was cancelled");
[[NSDistributedNotificationCenter defaultCenter]
postNotification:[NSNotification notificationWithName:@"N2NedgeDisconnecting" object:nil]];
break;
}

Expand Down Expand Up @@ -121,6 +124,9 @@ - (void)runLoop:(n2n_edge_t *)eee {
} /* while */

[self edgeCleanup:eee];
[[NSDistributedNotificationCenter defaultCenter]
postNotification:[NSNotification notificationWithName:@"N2NedgeDisconnected" object:nil]];

}

- (void) threadMethod:(id)theObject
Expand Down Expand Up @@ -150,6 +156,9 @@ - (void) threadMethod:(id)theObject

n2n_edge_t eee; /* single instance for this program */

[[NSDistributedNotificationCenter defaultCenter]
postNotification:[NSNotification notificationWithName:@"N2NedgeConnecting" object:nil]];

if (-1 == edge_init(&eee) ){
traceEvent( TRACE_ERROR, "Failed in edge_init" );
exit(1);
Expand Down Expand Up @@ -217,22 +226,21 @@ - (void) threadMethod:(id)theObject
update_supernode_reg(&eee, time(NULL) );


[[NSDistributedNotificationCenter defaultCenter]
postNotification:[NSNotification notificationWithName:@"N2NedgeConnecting" object:nil]];

traceEvent(TRACE_NORMAL, "");
traceEvent(TRACE_NORMAL, "Ready");

// autorelease again
[autoreleasePool release];

[[NSDistributedNotificationCenter defaultCenter]
postNotification:[NSNotification notificationWithName:@"N2NedgeConnected" object:nil]];
[self runLoop:&eee];

}

- (void) edgeConnect:(NSNotification *)notification
{
NSLog(@"hello world");
DLog(@"create thread and try to connect");

edgeThread = [[NSThread alloc] initWithTarget:self
selector:@selector(threadMethod:)
Expand Down
2 changes: 2 additions & 0 deletions osx/TunHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ int main (int argc, const char * argv[]) {
if(fd > 0) {
NSLog(@"Succesfully opened %s, fd: %d", tap_device, fd);

setuid(0);

snprintf(buf, sizeof(buf), "ifconfig tap%d %s netmask %s mtu %d up",
i, ip_address, "255.255.255.0", 1400);
system(buf);
Expand Down

0 comments on commit 14a5c41

Please sign in to comment.