More work towards overlay mesh.

Added single byte append to overlay_buffer type.
Added source interface to self-announce packets.
Probably other stuff, too.
This commit is contained in:
gardners 2011-09-04 06:36:39 +09:30
parent 2104eddd31
commit 1d6d744067
5 changed files with 29 additions and 7 deletions

View File

@ -585,6 +585,7 @@ int ob_rewind(overlay_buffer *b);
int ob_limitsize(overlay_buffer *b,int bytes); int ob_limitsize(overlay_buffer *b,int bytes);
int ob_unlimitsize(overlay_buffer *b); int ob_unlimitsize(overlay_buffer *b);
int ob_makespace(overlay_buffer *b,int bytes); 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_bytes(overlay_buffer *b,unsigned char *bytes,int count);
int ob_append_short(overlay_buffer *b,unsigned short v); int ob_append_short(overlay_buffer *b,unsigned short v);
int ob_append_int(overlay_buffer *b,unsigned int v); int ob_append_int(overlay_buffer *b,unsigned int v);

View File

@ -78,6 +78,15 @@ int ob_makespace(overlay_buffer *b,int bytes)
return 0; 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) int ob_append_bytes(overlay_buffer *b,unsigned char *bytes,int count)
{ {
if (ob_makespace(b,count)) return WHY("ob_makespace() failed"); if (ob_makespace(b,count)) return WHY("ob_makespace() failed");

View File

@ -277,7 +277,7 @@ int overlay_rx_messages()
bzero(&transaction_id[0],8); bzero(&transaction_id[0],8);
bzero(&src_addr,sizeof(src_addr)); bzero(&src_addr,sizeof(src_addr));
if ((packet[0]==0x01)&&!(packet[1]|packet[2]|packet[3])) 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 WHY("Invalid packet version in dummy interface");
} }
else { c[i]=0; count--; } 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; unsigned int broadcast_bits=local.sin_addr.s_addr|~netmask.sin_addr.s_addr;
struct sockaddr_in broadcast=local; struct sockaddr_in broadcast=local;
broadcast.sin_addr.s_addr=broadcast_bits; 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 */ /* Now register the interface, or update the existing interface registration */
struct interface_rules *r=interface_filter,*me=NULL; struct interface_rules *r=interface_filter,*me=NULL;
while(r) { while(r) {

View File

@ -252,11 +252,15 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
/* Sequence number range. Based on one tick per milli-second. */ /* Sequence number range. Based on one tick per milli-second. */
overlay_update_sequence_number(); overlay_update_sequence_number();
if (ob_append_int(b,overlay_interfaces[interface].last_tick_ms)) 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)) 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; 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; return 0;
} }

View File

@ -477,9 +477,17 @@ int overlay_someoneelse_can_hear(unsigned char *hearer,unsigned char *who,unsign
return 0; return 0;
} }
/* Recalculate node reachability metric. /* Recalculate node reachability metric, but only for directly connected nodes,
For now we will calculate a weighted sum of recent reachability. i.e., link-local neighbours.
The sequence numbers are all based on a milli-second clock
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) int overlay_route_recalc_node_metrics(overlay_node *n)
{ {