From 1d6d74406732f99d53b1773eec0614da5e6fe9a2 Mon Sep 17 00:00:00 2001 From: gardners Date: Sun, 4 Sep 2011 06:36:39 +0930 Subject: [PATCH] More work towards overlay mesh. Added single byte append to overlay_buffer type. Added source interface to self-announce packets. Probably other stuff, too. --- mphlr.h | 1 + overlay_buffer.c | 9 +++++++++ overlay_interface.c | 4 ++-- overlay_packetformats.c | 8 ++++++-- overlay_route.c | 14 +++++++++++--- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/mphlr.h b/mphlr.h index b3d8489c..bac89452 100644 --- a/mphlr.h +++ b/mphlr.h @@ -585,6 +585,7 @@ int ob_rewind(overlay_buffer *b); int ob_limitsize(overlay_buffer *b,int bytes); int ob_unlimitsize(overlay_buffer *b); int ob_makespace(overlay_buffer *b,int bytes); +int ob_append_byte(overlay_buffer *b,unsigned char byte); int ob_append_bytes(overlay_buffer *b,unsigned char *bytes,int count); int ob_append_short(overlay_buffer *b,unsigned short v); int ob_append_int(overlay_buffer *b,unsigned int v); diff --git a/overlay_buffer.c b/overlay_buffer.c index 91f849af..bcdb65fa 100644 --- a/overlay_buffer.c +++ b/overlay_buffer.c @@ -78,6 +78,15 @@ int ob_makespace(overlay_buffer *b,int bytes) return 0; } +int ob_append_byte(overlay_buffer *b,unsigned char byte) +{ + if (ob_makespace(b,1)) return WHY("ob_makespace() failed"); + + bcopy(&byte,&b->bytes[b->length],1); + b->length++; + return 0; +} + int ob_append_bytes(overlay_buffer *b,unsigned char *bytes,int count) { if (ob_makespace(b,count)) return WHY("ob_makespace() failed"); diff --git a/overlay_interface.c b/overlay_interface.c index b87355a9..29790261 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -277,7 +277,7 @@ int overlay_rx_messages() bzero(&transaction_id[0],8); bzero(&src_addr,sizeof(src_addr)); if ((packet[0]==0x01)&&!(packet[1]|packet[2]|packet[3])) - { if (!packetOk(i,&packet[128],plen,transaction_id,&src_addr,addrlen,1)) WHY("Malformed packet from dummy interface"); } + { if (!packetOk(i,&packet[128],plen,transaction_id,&src_addr,addrlen,1)) WHY("Malformed or unsupported packet from dummy interface (packetOK() failed)"); } else WHY("Invalid packet version in dummy interface"); } else { c[i]=0; count--; } @@ -423,7 +423,7 @@ int overlay_interface_discover() unsigned int broadcast_bits=local.sin_addr.s_addr|~netmask.sin_addr.s_addr; struct sockaddr_in broadcast=local; broadcast.sin_addr.s_addr=broadcast_bits; - if (debug>1) printf("%s: %08x %08x %08x\n",name,local.sin_addr.s_addr,netmask.sin_addr.s_addr,broadcast.sin_addr.s_addr); + if (debug>3) printf("%s: %08x %08x %08x\n",name,local.sin_addr.s_addr,netmask.sin_addr.s_addr,broadcast.sin_addr.s_addr); /* Now register the interface, or update the existing interface registration */ struct interface_rules *r=interface_filter,*me=NULL; while(r) { diff --git a/overlay_packetformats.c b/overlay_packetformats.c index 10d62440..68ff6529 100644 --- a/overlay_packetformats.c +++ b/overlay_packetformats.c @@ -252,11 +252,15 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b) /* Sequence number range. Based on one tick per milli-second. */ overlay_update_sequence_number(); if (ob_append_int(b,overlay_interfaces[interface].last_tick_ms)) - return WHY("ob_append_int() could not add sequence number to self-announcement"); + return WHY("ob_append_int() could not add low sequence number to self-announcement"); if (ob_append_int(b,overlay_sequence_number)) - return WHY("ob_append_int() could not add sequence number to self-announcement"); + return WHY("ob_append_int() could not add high sequence number to self-announcement"); overlay_interfaces[interface].last_tick_ms=overlay_sequence_number; + /* A byte that indicates which interface we are sending over */ + if (ob_append_byte(b,interface)) + return WHY("ob_append_int() could not add interface number to self-announcement"); + return 0; } diff --git a/overlay_route.c b/overlay_route.c index aa10f327..a93e4732 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -477,9 +477,17 @@ int overlay_someoneelse_can_hear(unsigned char *hearer,unsigned char *who,unsign return 0; } -/* Recalculate node reachability metric. - For now we will calculate a weighted sum of recent reachability. - The sequence numbers are all based on a milli-second clock +/* Recalculate node reachability metric, but only for directly connected nodes, + i.e., link-local neighbours. + + The scores should be calculated separately for each interface we can + hear the node on, so that this information can get back to the sender so that + they know the best interface to use when trying to talk to us. + + For now we will calculate a weighted sum of recent reachability over some fixed + length time interval. + The sequence numbers are all based on a milli-second clock. + */ int overlay_route_recalc_node_metrics(overlay_node *n) {