From e870c3542203a054f6d03d41ec53828d5abad054 Mon Sep 17 00:00:00 2001 From: gardners Date: Thu, 17 May 2012 17:07:46 +0930 Subject: [PATCH] Added very crude multi-hop route determination. --- overlay_abbreviations.c | 2 +- overlay_advertise.c | 2 +- overlay_route.c | 55 ++++++++++++++++++++++++++++++++--------- serval.h | 4 +-- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/overlay_abbreviations.c b/overlay_abbreviations.c index da4927d3..a1776e93 100644 --- a/overlay_abbreviations.c +++ b/overlay_abbreviations.c @@ -419,7 +419,7 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs int overlay_abbreviate_lookup_sender_id() { - overlay_neighbour *neh=overlay_route_get_neighbour_structure(overlay_abbreviate_current_sender.b,1 /* create if needed */); + overlay_neighbour *neh=overlay_route_get_neighbour_structure(overlay_abbreviate_current_sender.b,SID_SIZE,1 /* create if needed */); if (!neh) { overlay_abbreviate_current_sender_id=-1; return WHY("Could not find sender in neighbour list"); } /* Okay, so the following is a little tortuous in asking our parent who we are instead of just knowing, but it will do for now */ diff --git a/overlay_advertise.c b/overlay_advertise.c index 69167997..07f8716a 100644 --- a/overlay_advertise.c +++ b/overlay_advertise.c @@ -179,7 +179,7 @@ int overlay_route_saw_advertisements(int i,overlay_frame *f, long long now) int ofs=0; /* lookup score of current sender */ - overlay_node *sender=overlay_route_find_node(f->source,0); + overlay_node *sender=overlay_route_find_node(f->source,SID_SIZE,0); int sender_score=sender->best_link_score; if (debug&DEBUG_OVERLAYROUTEMONITOR) fprintf(stderr,"score to reach %s is %d\n", diff --git a/overlay_route.c b/overlay_route.c index 9df0e20b..f8be5306 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -371,8 +371,9 @@ int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen, if (!overlay_neighbours) return WHY("I have no neighbours"); - overlay_neighbour *neh=overlay_route_get_neighbour_structure(d,0 /* don't create if - missing */); + overlay_neighbour *neh=overlay_route_get_neighbour_structure(d,SID_SIZE, + 0 /* don't create if + missing */); if (neh) { /* Is a direct neighbour. @@ -396,9 +397,38 @@ int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen, if (0) printf("nexthop is %s\n",overlay_render_sid(nexthop)); return 0; } else { - /* Is not a direct neighbour */ - - return WHY("Calculating next-hop destination for nodes that are not direct neighbours is not yet implemented"); + /* Is not a direct neighbour. + XXX - Very simplistic for now. */ + overlay_node + *n=overlay_route_find_node(d,SID_SIZE,0 /* don't create if missing */ ); + if (n) { + int o; + int best_score=0; + int best_o=-1; + for(o=0;oobservations[o].observed_score; + overlay_neighbour *neh + =overlay_route_get_neighbour_structure + (n->observations[o].sender_prefix,OVERLAY_SENDER_PREFIX_LENGTH,0); + if (neh) { + for(i=1;iscores[i]*score>best_score) { + bcopy(&neh->node->sid[0],&nexthop[0],SID_SIZE); + *interface=i; + best_o=o; + best_score=score; + } + } + } + } + if (best_o>-1) { + return 0; + } else { + return WHYF("No open path to %s",overlay_render_sid(d)); + } + } else { + return WHYF("No open path to %s",overlay_render_sid(d)); + } } } @@ -429,7 +459,7 @@ unsigned int overlay_route_hash_sid(unsigned char *sid) return bin; } -overlay_node *overlay_route_find_node(unsigned char *sid,int createP) +overlay_node *overlay_route_find_node(unsigned char *sid,int prefixLen,int createP) { int bin_number=overlay_route_hash_sid(sid); int free_slot=-1; @@ -439,7 +469,7 @@ overlay_node *overlay_route_find_node(unsigned char *sid,int createP) for(slot=0;slotsource,1 /* make neighbour if not yet one */); + overlay_neighbour *n=overlay_route_get_neighbour_structure(f->source,SID_SIZE, + 1 /* make neighbour if not yet one */); if (!n) return WHY("overlay_route_get_neighbour_structure() failed"); @@ -1092,7 +1123,7 @@ int overlay_route_record_link(long long now,unsigned char *to, fprintf(stderr,"%s*,0x%08x-0x%08x,%d)\n", overlay_render_sid_prefix(via,7),s1,s2,score); - overlay_node *n=overlay_route_find_node(to,1 /* create node if missing */); + overlay_node *n=overlay_route_find_node(to,SID_SIZE,1 /* create node if missing */); if (!n) return WHY("Could not find or create entry for node"); for(i=0;i