From c06b75f5c921061548f083657f7131dd0ee70cd0 Mon Sep 17 00:00:00 2001 From: gardners Date: Sun, 4 Sep 2011 06:48:41 +0930 Subject: [PATCH] Fixed some sign mis-matches in overlay_abbreviations. Added infrastructure to keep track of receiver and sender interfaces for multi-homed nodes. --- mphlr.h | 7 ++++--- overlay.c | 4 ++-- overlay_abbreviations.c | 6 +++--- overlay_route.c | 16 ++++++++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/mphlr.h b/mphlr.h index bac89452..496c4dfe 100644 --- a/mphlr.h +++ b/mphlr.h @@ -661,7 +661,7 @@ extern int overlay_interface_count; #define OF_COMPRESS_RESERVED 0x03 /* Reserved for another compression system */ #define OVERLAY_ADDRESS_CACHE_SIZE 1024 -int overlay_abbreviate_address(unsigned char *in,char *out,int *ofs); +int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs); int overlay_abbreviate_append_address(overlay_buffer *b,unsigned char *a); int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs,unsigned char *out,int *ofs); @@ -720,6 +720,7 @@ typedef struct overlay_neighbour_observation { unsigned int s2; long long time_ms; unsigned char sender_interface; + unsigned char receiver_interface; unsigned char valid; } overlay_neighbour_observation; @@ -755,9 +756,9 @@ typedef struct overlay_neighbour { long long overlay_gettime_ms(); int overlay_route_init(int mb_ram); -int overlay_route_saw_selfannounce_ack(overlay_frame *f,long long now); +int overlay_route_saw_selfannounce_ack(int interface,overlay_frame *f,long long now); int overlay_route_recalc_node_metrics(overlay_node *n); -int overlay_route_saw_selfannounce(overlay_frame *f,long long now); +int overlay_route_saw_selfannounce(int interface,overlay_frame *f,long long now); overlay_node *overlay_route_find_node(unsigned char *sid,int createP); unsigned int overlay_route_hash_sid(unsigned char *sid); int overlay_route_init(int mb_ram); diff --git a/overlay.c b/overlay.c index 89205f46..ff051a10 100644 --- a/overlay.c +++ b/overlay.c @@ -227,10 +227,10 @@ int overlay_frame_process(int interface,overlay_frame *f) switch(f->type) { case OF_TYPE_SELFANNOUNCE: - overlay_route_saw_selfannounce(f,now); + overlay_route_saw_selfannounce(interface,f,now); break; case OF_TYPE_SELFANNOUNCE_ACK: - overlay_route_saw_selfannounce_ack(f,now); + overlay_route_saw_selfannounce_ack(interface,f,now); break; default: return WHY("Support for that f->type not yet implemented"); diff --git a/overlay_abbreviations.c b/overlay_abbreviations.c index 6f6ac9e4..40ea870c 100644 --- a/overlay_abbreviations.c +++ b/overlay_abbreviations.c @@ -189,7 +189,7 @@ int overlay_abbreviate_cache_address(unsigned char *sid) return 0; } -int overlay_abbreviate_try_byindex(unsigned char *in,char *out,int *ofs,int index) +int overlay_abbreviate_try_byindex(unsigned char *in,unsigned char *out,int *ofs,int index) { if(!bcmp(in,abbrs->sids[index],SID_SIZE)) { @@ -213,11 +213,11 @@ int overlay_abbreviate_append_address(overlay_buffer *b,unsigned char *a) return 0; } -int overlay_abbreviate_address(unsigned char *in,char *out,int *ofs) +int overlay_abbreviate_address(unsigned char *in,unsigned char *out,int *ofs) { int i; int wasInCachedP=overlay_abbreviate_cache_address(in); - + if (!in) return WHY("in==NULL"); if (in[0]<0x10) return WHY("Invalid address - 0x00-0x0f are reserved prefixes."); diff --git a/overlay_route.c b/overlay_route.c index a93e4732..d0161ea3 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -397,7 +397,7 @@ int overlay_route_make_neighbour(overlay_node *n) return 0; } -int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned int s1,unsigned int s2,long long now) +int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned int s1,unsigned int s2,int receiver_interface,long long now) { /* 1. Find (or create) node entry for the node. 2. Replace oldest observation with this observation. @@ -421,6 +421,7 @@ int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned in neh->observations[obs_index].s1=s1; neh->observations[obs_index].s2=s2; neh->observations[obs_index].sender_interface=sender_interface; + neh->observations[obs_index].receiver_interface=receiver_interface; neh->observations[obs_index].valid=1; neh->most_recent_observation_id=obs_index; neh->last_observation_time_ms=now; @@ -431,7 +432,7 @@ int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned in return WHY("Not implemented"); } -int overlay_route_saw_selfannounce(overlay_frame *f,long long now) +int overlay_route_saw_selfannounce(int interface,overlay_frame *f,long long now) { unsigned int s1,s2; unsigned char sender_interface; @@ -441,7 +442,7 @@ int overlay_route_saw_selfannounce(overlay_frame *f,long long now) sender_interface=ntohl(*((unsigned char*)&f->payload[8])); fprintf(stderr,"Received self-announcement for sequence range [%08x,%08x]\n",s1,s2); - overlay_route_i_can_hear(f->source,sender_interface,s1,s2,now); + overlay_route_i_can_hear(f->source,sender_interface,s1,s2,interface,now); overlay_route_ack_selfannounce(f); @@ -492,12 +493,19 @@ int overlay_someoneelse_can_hear(unsigned char *hearer,unsigned char *who,unsign int overlay_route_recalc_node_metrics(overlay_node *n) { int i; + + /* Somewhere to remember how many milliseconds we have seen */ + int ms_observed[OVERLAY_MAX_INTERFACES]; + for(i=0;i