mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Stub in place for processing selfannounce acks.
Some bug fixes with address expansion.
This commit is contained in:
parent
144f3ee4b1
commit
c65bc0d764
2
mphlr.h
2
mphlr.h
@ -788,3 +788,5 @@ int overlay_payload_enqueue(int q,overlay_frame *p);
|
||||
long long overlay_time_in_ms();
|
||||
int overlay_abbreviate_lookup_sender_id();
|
||||
int ob_dump(overlay_buffer *b,char *desc);
|
||||
unsigned int ob_get_int(overlay_buffer *b,int offset);
|
||||
char *overlay_render_sid(unsigned char *sid);
|
||||
|
@ -341,21 +341,22 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
|
||||
return r;
|
||||
case OA_CODE_PREVIOUS: /* Same as last address */
|
||||
(*inofs)++;
|
||||
fprintf(stderr,"copying %s to offset %d\n",overlay_render_sid(&overlay_abbreviate_previous_address.b[0]),*ofs);
|
||||
bcopy(&overlay_abbreviate_previous_address.b[0],&out[*ofs],SID_SIZE);
|
||||
(*ofs)+=SID_SIZE;
|
||||
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
|
||||
(*ofs)+=SID_SIZE;
|
||||
return OA_RESOLVED;
|
||||
case OA_CODE_PREFIX3: case OA_CODE_PREFIX3_INDEX1: /* 3-byte prefix */
|
||||
if (in[*inofs]==0x09) bytes=1;
|
||||
r=overlay_abbreviate_cache_lookup(&in[(*inofs)+1],out,ofs,3,bytes);
|
||||
(*inofs)+=1+3+bytes;
|
||||
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
|
||||
overlay_abbreviate_set_most_recent_address(&out[(*ofs)-SID_SIZE]);
|
||||
return r;
|
||||
case OA_CODE_PREFIX7: case OA_CODE_PREFIX7_INDEX1: /* 7-byte prefix */
|
||||
if (in[*inofs]==OA_CODE_PREFIX7_INDEX1) bytes=1;
|
||||
r=overlay_abbreviate_cache_lookup(&in[(*inofs)+1],out,ofs,7,bytes);
|
||||
(*inofs)+=1+7+bytes;
|
||||
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
|
||||
overlay_abbreviate_set_most_recent_address(&out[(*ofs)-SID_SIZE]);
|
||||
return r;
|
||||
case OA_CODE_PREFIX11: case OA_CODE_PREFIX11_INDEX1: case OA_CODE_PREFIX11_INDEX2: /* 11-byte prefix */
|
||||
bytes=0;
|
||||
@ -363,7 +364,7 @@ int overlay_abbreviate_expand_address(int interface,unsigned char *in,int *inofs
|
||||
if (in[*inofs]==OA_CODE_PREFIX11_INDEX2) bytes=2;
|
||||
r=overlay_abbreviate_cache_lookup(&in[(*inofs)+1],out,ofs,11,bytes);
|
||||
(*inofs)+=1+11+bytes;
|
||||
overlay_abbreviate_set_most_recent_address(&out[*ofs]);
|
||||
overlay_abbreviate_set_most_recent_address(&out[(*ofs)-SID_SIZE]);
|
||||
return r;
|
||||
case OA_CODE_BROADCAST: /* broadcast */
|
||||
memset(&out[*ofs],0xff,SID_SIZE);
|
||||
@ -475,5 +476,9 @@ int overlay_abbreviate_set_current_sender(unsigned char *in)
|
||||
int overlay_abbreviate_set_most_recent_address(unsigned char *in)
|
||||
{
|
||||
bcopy(in,&overlay_abbreviate_previous_address.b[0],SID_SIZE);
|
||||
if (debug>3) fprintf(stderr,"Most recent address=%s\n",
|
||||
overlay_render_sid(in));
|
||||
if (!in[0])
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
@ -108,6 +108,21 @@ int ob_append_int(overlay_buffer *b,unsigned int v)
|
||||
return ob_append_bytes(b,(unsigned char *)&s,sizeof(unsigned int));
|
||||
}
|
||||
|
||||
unsigned int ob_get_int(overlay_buffer *b,int offset)
|
||||
{
|
||||
if (!b) return WHY("b is NULL");
|
||||
if (offset<0) return WHY("passed illegal offset (<0)");
|
||||
if ((offset+sizeof(unsigned int))>b->length) return WHY("passed offset too large");
|
||||
|
||||
// Some platforms require alignment
|
||||
if (((int)&b->bytes[offset])&3) {
|
||||
unsigned char bb[4];
|
||||
bcopy(&b->bytes[offset],&bb[0],4);
|
||||
return ntohl(*(unsigned int *)&bb[0]);
|
||||
} else
|
||||
return ntohl(*((unsigned int *)&b->bytes[offset]));
|
||||
}
|
||||
|
||||
int ob_append_rfs(overlay_buffer *b,int l)
|
||||
{
|
||||
/* Encode the specified length and append it to the buffer */
|
||||
|
@ -764,8 +764,60 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
||||
|
||||
}
|
||||
|
||||
char ors_out[SID_SIZE*2+1];
|
||||
char *overlay_render_sid(unsigned char *sid)
|
||||
{
|
||||
int zero=0;
|
||||
|
||||
extractSid(sid,&zero,ors_out);
|
||||
ors_out[SID_SIZE*2]=0;
|
||||
return ors_out;
|
||||
}
|
||||
|
||||
/*
|
||||
Self-announcement acks bounce back to the self-announcer from immediate neighbours
|
||||
who report the link score they have calculated based on listening to self-announces
|
||||
from that peer. By acking them these scores then get to the originator, who then
|
||||
has a score for the link to their neighbour, which is measuring the correct
|
||||
direction of the link.
|
||||
|
||||
Frames consist of 32bit timestamp in milliseconds followed by zero or more entries
|
||||
of the format:
|
||||
|
||||
8bits - link score
|
||||
8bits - interface number
|
||||
|
||||
this is followed by a 00 byte to indicate the end.
|
||||
|
||||
That way we don't waste lots of bytes on single-interface nodes.
|
||||
(But I am sure we can do better).
|
||||
|
||||
These link scores should get stored in our node list as compared to our neighbour list,
|
||||
with the node itself listed as the nexthop that the score is associated with.
|
||||
*/
|
||||
int overlay_route_saw_selfannounce_ack(int interface,overlay_frame *f,long long now)
|
||||
{
|
||||
if (!overlay_neighbours) return 0;
|
||||
return WHY("Not implemented");
|
||||
ob_dump(f->payload,"selfannounce_ack");
|
||||
|
||||
int i;
|
||||
int iface;
|
||||
int score;
|
||||
unsigned int timestamp;
|
||||
|
||||
timestamp=ob_get_int(f->payload,0);
|
||||
i=4;
|
||||
|
||||
while(i<f->payload->length) {
|
||||
score=f->payload->bytes[i++];
|
||||
if (!score) break;
|
||||
iface=f->payload->bytes[i++];
|
||||
|
||||
// Call something like the following for each link
|
||||
fprintf(stderr,"route_record_link(0x%llx,%s,%s,0x%08x,%d,%d)\n",
|
||||
now,overlay_render_sid(f->source),overlay_render_sid(f->source),timestamp,score,interface);
|
||||
// overlay_route_record_link(now,f->source,f->source,timestamp,score,interface);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user