mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 10:46:23 +00:00
Now sends acks to self-announcements, but uses index-based-abbreviation
to save space, which we have not yet implemented.
This commit is contained in:
parent
e7a6ed2b44
commit
74efa738be
4
mphlr.h
4
mphlr.h
@ -751,7 +751,6 @@ typedef struct overlay_node {
|
||||
} overlay_node;
|
||||
|
||||
typedef struct overlay_neighbour {
|
||||
unsigned char sid[SID_SIZE];
|
||||
long long last_observation_time_ms;
|
||||
int most_recent_observation_id;
|
||||
overlay_neighbour_observation observations[OVERLAY_MAX_OBSERVATIONS];
|
||||
@ -776,7 +775,8 @@ overlay_neighbour *overlay_route_get_neighbour_structure(unsigned char *packed_s
|
||||
int createP);
|
||||
unsigned char *overlay_get_my_sid();
|
||||
int overlay_frame_set_me_as_source(overlay_frame *f);
|
||||
int overlay_frame_set_neighbour_as_source(overlay_frame *f,overlay_neighbour *n);
|
||||
int overlay_frame_set_neighbour_as_source(overlay_frame *f,overlay_neighbour *n);
|
||||
int overlay_frame_set_neighbour_as_destination(overlay_frame *f,overlay_neighbour *n);
|
||||
int overlay_update_sequence_number();
|
||||
int packetEncipher(unsigned char *packet,int maxlen,int *len,int cryptoflags);
|
||||
int overlayServerMode();
|
||||
|
@ -293,9 +293,10 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
|
||||
/* Unsupported codes, so tell the sender
|
||||
if the frame was addressed to us as next-hop */
|
||||
(*inofs)++;
|
||||
WHY("Reserved address abbreviation code");
|
||||
return OA_UNSUPPORTED;
|
||||
case OA_CODE_INDEX: /* single byte index look up */
|
||||
WHY("Unimplemented address abbreviation code");
|
||||
WHY("Unimplemented address abbreviation code (single byte index lookup)");
|
||||
overlay_interface_repeat_abbreviation_policy[interface]=1;
|
||||
return OA_UNSUPPORTED;
|
||||
case OA_CODE_PREVIOUS: /* Same as last address */
|
||||
@ -332,8 +333,9 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
|
||||
default: /* Full address, optionally followed by index for us to remember */
|
||||
if (in[*inofs]==OA_CODE_FULL_INDEX1) bytes=1;
|
||||
if (in[*inofs]==OA_CODE_FULL_INDEX2) bytes=2;
|
||||
if (bytes) (*inofs)++; /* Skip leading control code if present */
|
||||
bcopy(&in[*inofs],&out[*ofs],SID_SIZE);
|
||||
if (bytes) overlay_abbreviate_remember_index(bytes,in,&in[(*inofs)+SID_SIZE]);
|
||||
if (bytes) overlay_abbreviate_remember_index(bytes,&in[*inofs],&in[(*inofs)+SID_SIZE]);
|
||||
overlay_abbreviate_cache_address(&in[*inofs]);
|
||||
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
|
||||
(*inofs)+=SID_SIZE+bytes;
|
||||
@ -341,14 +343,15 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
|
||||
}
|
||||
}
|
||||
|
||||
int overlay_abbreviate_remember_index(int index_byte_count,unsigned char *in,unsigned char *index_bytes)
|
||||
int overlay_abbreviate_remember_index(int index_byte_count,unsigned char *sid_to_remember,unsigned char *index_bytes)
|
||||
{
|
||||
int zero=0;
|
||||
char sid[SID_SIZE*2+1];
|
||||
int index=index_bytes[0];
|
||||
if (index_byte_count>1) index=(index<<8)|index_bytes[1];
|
||||
fprintf(stderr,"index=%d\n",index);
|
||||
|
||||
sid[0]=0; extractSid(in,&zero,sid);
|
||||
sid[0]=0; extractSid(sid_to_remember,&zero,sid);
|
||||
fprintf(stderr,"We need to remember that the sender #%d has assigned index #%d to the following:\n [%s]\n",
|
||||
overlay_abbreviate_current_sender_id,index,sid);
|
||||
return WHY("Not implemented");
|
||||
@ -373,6 +376,7 @@ int overlay_abbreviate_cache_lookup(unsigned char *in,unsigned char *out,int *of
|
||||
if (memcmp(in,&cache->sids[index].b[0],prefix_bytes))
|
||||
{
|
||||
/* No, it isn't in the cache. */
|
||||
WHY("Encountered unresolvable address -- are we asking for explanation?");
|
||||
return OA_PLEASEEXPLAIN;
|
||||
}
|
||||
|
||||
@ -394,6 +398,7 @@ int overlay_abbreviate_cache_lookup(unsigned char *in,unsigned char *out,int *of
|
||||
corrective action in case it is never required.
|
||||
*/
|
||||
overlay_abbreviate_remember_index(index_bytes,&cache->sids[index].b[0],&in[prefix_bytes]);
|
||||
(*ofs)+=index_bytes;
|
||||
}
|
||||
return OA_RESOLVED;
|
||||
}
|
||||
|
@ -177,12 +177,21 @@ int op_free(overlay_frame *p)
|
||||
int overlay_frame_set_neighbour_as_source(overlay_frame *f,overlay_neighbour *n)
|
||||
{
|
||||
if (!n) return WHY("Neighbour was null");
|
||||
bcopy(n->sid,f->source,SID_SIZE);
|
||||
bcopy(n->node->sid,f->source,SID_SIZE);
|
||||
f->source_address_status=OA_RESOLVED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_frame_set_neighbour_as_destination(overlay_frame *f,overlay_neighbour *n)
|
||||
{
|
||||
if (!n) return WHY("Neighbour was null");
|
||||
bcopy(n->node->sid,f->destination,SID_SIZE);
|
||||
f->destination_address_status=OA_RESOLVED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char *overlay_get_my_sid()
|
||||
{
|
||||
|
||||
|
@ -337,7 +337,7 @@ int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen,
|
||||
int *interface)
|
||||
{
|
||||
int i;
|
||||
if (!overlay_neighbours) return 0;
|
||||
if (!overlay_neighbours) return WHY("I have no neighbours");
|
||||
|
||||
overlay_neighbour *neh=overlay_route_get_neighbour_structure(d,0 /* don't create if
|
||||
missing */);
|
||||
@ -351,8 +351,9 @@ int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen,
|
||||
(*nexthoplen)=SID_SIZE;
|
||||
|
||||
*interface=0;
|
||||
for(i=1;i<OVERLAY_MAX_INTERFACES;i++)
|
||||
for(i=1;i<OVERLAY_MAX_INTERFACES;i++) {
|
||||
if (neh->scores[i]>neh->scores[*interface]) *interface=i;
|
||||
}
|
||||
if (neh->scores[*interface]<1) return WHY("No open path to node");
|
||||
return 0;
|
||||
} else {
|
||||
@ -448,7 +449,7 @@ int overlay_route_ack_selfannounce(overlay_frame *f,overlay_neighbour *n)
|
||||
handle mono-directional links (which WiFi is notorious for). */
|
||||
|
||||
/* Set destination of ack to source of observed frame */
|
||||
if (overlay_frame_set_neighbour_as_source(out,n)) {
|
||||
if (overlay_frame_set_neighbour_as_destination(out,n)) {
|
||||
op_free(out);
|
||||
return WHY("overlay_frame_set_neighbour_as_source() failed");
|
||||
}
|
||||
@ -742,6 +743,7 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
||||
|
||||
/* Reduce score by 1 point for each second we have not seen anything from it */
|
||||
score-=(now-most_recent_observation)/1000;
|
||||
if (score<0) score=0;
|
||||
|
||||
n->scores[i]=score;
|
||||
if (debug>2&&score) fprintf(stderr,"Neighbour score on interface #%d = %d (observations for %dms)\n",i,score,ms_observed[i]);
|
||||
|
Loading…
Reference in New Issue
Block a user