Change route announcement format, add please explain support

This commit is contained in:
Jeremy Lakeman 2012-10-09 12:04:02 +10:30
parent 6e45f264e9
commit 275aa49903
4 changed files with 33 additions and 34 deletions

View File

@ -145,9 +145,8 @@ static int walk_tree(struct tree_node *node, int pos,
if (walk_tree(node->tree_nodes[i], pos+1, start, start_len, end, end_len, callback, context))
return 1;
}else if(node->subscribers[i]){
if ((!start) || start_len<SID_SIZE || memcmp(node->subscribers[i]->sid, start, start_len)!=0)
if (callback(node->subscribers[i], context))
return 1;
if (callback(node->subscribers[i], context))
return 1;
}
// stop comparing the start sid after looking at the first branch of the tree
start=NULL;
@ -156,7 +155,7 @@ static int walk_tree(struct tree_node *node, int pos,
}
/*
walk the tree, starting at start, calling the supplied callback function
walk the tree, starting at start inclusive, calling the supplied callback function
*/
void enum_subscribers(struct subscriber *start, int(*callback)(struct subscriber *, void *), void *context){
walk_tree(&root, 0, start->sid, SID_SIZE, NULL, 0, callback, context);
@ -432,7 +431,7 @@ int find_subscr_buffer(struct decode_context *context, struct overlay_buffer *b,
if (!context->please_explain){
context->please_explain = calloc(sizeof(struct overlay_frame),1);
context->please_explain->payload=ob_new();
ob_limitsize(context->please_explain->payload, 1024);
ob_limitsize(context->please_explain->payload, MDP_MTU);
}
// And I'll tell you about any subscribers I know that match this abbreviation,

View File

@ -58,7 +58,7 @@ int overlay_route_please_advertise(overlay_node *n)
else return 1;
}
struct subscriber *last_advertised=NULL;
struct subscriber *next_advertisement=NULL;
int add_advertisement(struct subscriber *subscriber, void *context){
struct overlay_buffer *e=context;
@ -66,21 +66,17 @@ int add_advertisement(struct subscriber *subscriber, void *context){
if (subscriber->node){
overlay_node *n=subscriber->node;
ob_append_bytes(e,subscriber->sid,6);
ob_append_byte(e,n->best_link_score);
ob_append_byte(e,n->observations[n->best_observation].gateways_en_route);
// stop if we run out of space
if (ob_makespace(e,8)!=0){
last_advertised=subscriber;
if (overlay_address_append(e,subscriber) ||
ob_append_byte(e,n->best_link_score) ||
ob_append_byte(e,n->observations[n->best_observation].gateways_en_route)){
// stop if we run out of space, remember where we should start next time.
next_advertisement=subscriber;
ob_rewind(e);
return 1;
}
// or we've been called twice and looped around
if (subscriber == last_advertised){
last_advertised = NULL;
return 1;
}
ob_checkpoint(e);
}
return 0;
@ -149,14 +145,16 @@ int overlay_route_add_advertisements(overlay_interface *interface, struct overla
slots_used++;
}
*/
struct subscriber *start = last_advertised;
struct subscriber *start = next_advertisement;
next_advertisement=NULL;
int start_pos = e->position;
// append announcements starting from the last node we advertised
// append announcements starting from the last node we couldn't advertise last time
enum_subscribers(start, add_advertisement, e);
// if we didn't start at the beginning and still have space, start again from the beginning
if (start && e->sizeLimit - e->position >=8){
if (start && !next_advertisement && e->sizeLimit - e->position > 0){
enum_subscribers(NULL, add_advertisement, e);
}
@ -180,26 +178,27 @@ int overlay_route_add_advertisements(overlay_interface *interface, struct overla
of nodes from here to there. That seems silly, and is agains't the BATMAN
approach of each node just knowing single-hop information.
*/
int overlay_route_saw_advertisements(int i, struct overlay_frame *f, long long now)
int overlay_route_saw_advertisements(int i, struct overlay_frame *f, struct decode_context *context, time_ms_t now)
{
IN();
while(f->payload->position < f->payload->sizeLimit)
{
struct subscriber *subscriber;
unsigned char *sid = ob_get_bytes_ptr(f->payload, 6);
context->invalid_addresses=0;
if (overlay_address_parse(context, f->payload, NULL, &subscriber))
break;
int score=ob_get(f->payload);
int gateways_en_route=ob_get(f->payload);
// stop if hit end of payload
if (!sid || score<0 || gateways_en_route<0)
continue;
if (score<0 || gateways_en_route<0)
break;
subscriber = find_subscriber(sid, 6, 0);
if (!subscriber){
WARN("Dispatch PLEASEEXPLAIN not implemented");
// skip if we can't parse the subscriber id
if (context->invalid_addresses || !subscriber)
continue;
}
/* Don't record routes to ourselves */
if (subscriber->reachable==REACHABLE_SELF) {

View File

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
struct sockaddr_in loopback;
// a frame destined for one of our local addresses, or broadcast, has arrived. Process it.
int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, struct overlay_frame *f){
int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, struct overlay_frame *f, struct decode_context *context){
int id = (interface - overlay_interfaces);
switch(f->type)
{
@ -43,7 +43,7 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, s
case OF_TYPE_NODEANNOUNCE:
if (debug&DEBUG_OVERLAYFRAMES)
DEBUG("Processing OF_TYPE_NODEANNOUNCE");
overlay_route_saw_advertisements(id,f,now);
overlay_route_saw_advertisements(id,f,context,now);
break;
// data frames
@ -327,7 +327,7 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
// process payloads that are for me or everyone
if ((!f.destination) || f.destination->reachable==REACHABLE_SELF){
process_incoming_frame(now, interface, &f);
process_incoming_frame(now, interface, &f, &context);
}
next:

View File

@ -190,6 +190,7 @@ extern char *batman_peerfile;
struct subscriber;
struct decode_context;
typedef struct keypair {
int type;
@ -641,7 +642,7 @@ int overlay_route_dump();
int overlay_route_add_advertisements(overlay_interface *interface, struct overlay_buffer *e);
int ovleray_route_please_advertise(overlay_node *n);
int overlay_route_saw_advertisements(int i, struct overlay_frame *f, time_ms_t now);
int overlay_route_saw_advertisements(int i, struct overlay_frame *f, struct decode_context *context, time_ms_t now);
int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, time_ms_t now);
int overlay_route_please_advertise(overlay_node *n);
int rhizome_server_get_fds(struct pollfd *fds,int *fdcount,int fdmax);