From 9108fd5c5996d1de86544b855bda97688c116cfb Mon Sep 17 00:00:00 2001 From: gardners Date: Fri, 12 Aug 2011 09:58:25 +0200 Subject: [PATCH] Broadcast on each interface now works, at least for OSX. --- dna.c | 8 ++------ overlay_interface.c | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/dna.c b/dna.c index 68169ae2..1707d92c 100644 --- a/dna.c +++ b/dna.c @@ -262,12 +262,8 @@ int usage(char *complaint) fprintf(stderr," -G - Offer gateway services. Argument specifies locations of necessary files.\n"); fprintf(stderr," Use -G [potato|android|custom:...] to set defaults for your device type.\n"); fprintf(stderr," -N - Specify one or more interfaces for the DNA overlay mesh to operate.\n"); - fprintf(stderr," Interface specifications take the form IP[:speed[:type[:port]]], and\n"); - fprintf(stderr," multiple interfaces can be specified by comma separating them.\n"); - fprintf(stderr," Speed is the interface speed in bits per second (K,M or G suffixes allowed)\n"); - fprintf(stderr," Type is WiFi,ethernet,catear or other.\n"); - fprintf(stderr," Port specifies an alternate UDP port, otherwise %d is used.\n",PORT_DNA); - fprintf(stderr," e.g., -N 10.1.2.3,10.1.130.45:2M:wifi\n"); + fprintf(stderr," Interface specifications take the form <+|->[interface[=type][,...]\n"); + fprintf(stderr," e.g., -N -en0,+ to use all interfaces except en0\n"); fprintf(stderr,"\n"); exit(-1); } diff --git a/overlay_interface.c b/overlay_interface.c index a74ddcf0..bec01a94 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -178,7 +178,7 @@ int overlay_interface_init(char *name,struct sockaddr_in src_addr,struct sockadd I(mtu)=1200; I(bits_per_second)=speed_in_bits; - I(port)=ntohs(src_addr.sin_port); + I(port)=port; I(type)=type; I(tick_ms)=500; switch(type) { @@ -235,6 +235,7 @@ int overlay_broadcast_ensemble(int interface_number,unsigned char *bytes,int len memset(&s, '\0', sizeof(struct sockaddr_in)); s = overlay_interfaces[interface_number].broadcast_address; s.sin_family = AF_INET; + fprintf(stderr,"Port=%d\n",overlay_interfaces[interface_number].port); s.sin_port = htons( overlay_interfaces[interface_number].port ); if(sendto(overlay_interfaces[interface_number].socket, bytes, len, 0, (struct sockaddr *)&s, sizeof(struct sockaddr_in)) < 0) @@ -430,23 +431,29 @@ int overlay_check_ticks() struct timeval nowtv; long long now; + /* Check for changes to interfaces */ + overlay_interface_discover(); + if (gettimeofday(&nowtv,NULL)) return WHY("gettimeofday() failed"); - + /* Get current time in milliseconds */ now=nowtv.tv_sec*1000; now=now+nowtv.tv_usec/1000; + /* Now check if the next tick time for the interfaces is no later than that time. If so, trigger a tick on the interface. */ for(i=0;i=overlay_interfaces[i].last_tick_ms+overlay_interfaces[i].tick_ms) - { - /* This interface is due for a tick */ - overlay_tick_interface(i,now); - overlay_interfaces[i].last_tick_ms=now; - } + /* Only tick live interfaces */ + if (overlay_interfaces[i].observed>0) + if (now>=overlay_interfaces[i].last_tick_ms+overlay_interfaces[i].tick_ms) + { + /* This interface is due for a tick */ + overlay_tick_interface(i,now); + overlay_interfaces[i].last_tick_ms=now; + } } return 0;