mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 17:33:08 +00:00
Fixed various compiler warnings.
Change overlay_frame payload to use an overlay_buffer structure for consistency and ease of payload construction. Added some sanity checking to peer score calculation. Getting closer to being able to TX acks to selfannouncements. Other little things to accomplish these.
This commit is contained in:
parent
b8dfa7becd
commit
cbb1939241
@ -36,7 +36,7 @@ int packetGetPrivateKeyForSid()
|
||||
int ofs=0;
|
||||
while(findHlr(hlr,&ofs,NULL,NULL)) {
|
||||
// XXX If the SIDs match, then this is it */
|
||||
if (!current_sid) {
|
||||
if (!current_sid_set) {
|
||||
/* we are using the first sid in the HLR */
|
||||
} else {
|
||||
/* Compare current SID with SID of this HLR record */
|
||||
@ -51,6 +51,7 @@ int packetGetPrivateKeyForSid()
|
||||
|
||||
int packetClearPrivateKeys()
|
||||
{
|
||||
return setReason("Not implemented");
|
||||
}
|
||||
|
||||
int packetDecipher(unsigned char *packet,int len,int cipher)
|
||||
@ -79,7 +80,7 @@ int packetDecipher(unsigned char *packet,int len,int cipher)
|
||||
}
|
||||
}
|
||||
|
||||
int packetEncipher(unsigned char *packet,int len,int cryptoflags)
|
||||
int packetEncipher(unsigned char *packet,int maxlen,int *len,int cryptoflags)
|
||||
{
|
||||
// Not encrypting for now
|
||||
return 0;
|
||||
|
21
mphlr.h
21
mphlr.h
@ -396,10 +396,7 @@ typedef struct overlay_frame {
|
||||
unsigned char *bytes;
|
||||
|
||||
/* Actual payload */
|
||||
unsigned int payloadlength;
|
||||
unsigned char *payload;
|
||||
int payloadFreeP; /* Set if this needs to be freed on disposal
|
||||
of the frame */
|
||||
struct overlay_buffer *payload;
|
||||
|
||||
int rfs; /* remainder of frame size */
|
||||
|
||||
@ -569,11 +566,12 @@ typedef struct overlay_txqueue {
|
||||
*/
|
||||
} overlay_txqueue;
|
||||
|
||||
extern overlay_txqueue overlay_tx[4];
|
||||
extern overlay_txqueue overlay_tx[5];
|
||||
#define OVERLAY_ISOCHRONOUS_VOICE 0
|
||||
#define OVERLAY_ISOCHRONOUS_VIDEO 1
|
||||
#define OVERLAY_ORDINARY 2
|
||||
#define OVERLAY_OPPORTUNISTIC 3
|
||||
#define OVERLAY_MESH_MANAGEMENT 1
|
||||
#define OVERLAY_ISOCHRONOUS_VIDEO 2
|
||||
#define OVERLAY_ORDINARY 3
|
||||
#define OVERLAY_OPPORTUNISTIC 4
|
||||
|
||||
int setReason(char *fmt, ...);
|
||||
#define WHY(X) setReason("%s:%d:%s() %s",__FILE__,__LINE__,__FUNCTION__,X)
|
||||
@ -769,3 +767,10 @@ int overlay_route_saw_selfannounce(int interface,overlay_frame *f,long long now)
|
||||
overlay_node *overlay_route_find_node(unsigned char *sid,int createP);
|
||||
unsigned int overlay_route_hash_sid(unsigned char *sid);
|
||||
int overlay_route_init(int mb_ram);
|
||||
overlay_neighbour *overlay_route_get_neighbour_structure(unsigned char *packed_sid);
|
||||
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_update_sequence_number();
|
||||
int packetEncipher(unsigned char *packet,int maxlen,int *len,int cryptoflags);
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
||||
|
||||
int overlayMode=0;
|
||||
|
||||
overlay_txqueue overlay_tx[4];
|
||||
overlay_txqueue overlay_tx[5];
|
||||
|
||||
int overlayServerMode()
|
||||
{
|
||||
|
@ -195,3 +195,27 @@ int ob_patch_rfs(overlay_buffer *b,int l)
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int asprintable(int c)
|
||||
{
|
||||
if (c<' ') return '.';
|
||||
if (c>0x7e) return '.';
|
||||
return c;
|
||||
}
|
||||
|
||||
int ob_dump(overlay_buffer *b)
|
||||
{
|
||||
fprintf(stderr,"Dumping overlay_buffer at %p : length=%d\n",b,b->length);
|
||||
int i,j;
|
||||
|
||||
for(i=0;i<b->length;i+=16)
|
||||
{
|
||||
fprintf(stderr,"%04x :",i);
|
||||
for(j=0;j<16&&(i+j<b->length);j++) fprintf(stderr," %02x",b->bytes[i+j]);
|
||||
for(;j<16;j++) fprintf(stderr," ");
|
||||
fprintf(stderr," ");
|
||||
for(j=0;j<16&&(i+j<b->length);j++) fprintf(stderr," %c",asprintable(b->bytes[i+j]));
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -473,11 +473,49 @@ int overlay_interface_discover()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,overlay_frame **p,long long now,overlay_frame *pax[],int *frame_pax,int frame_max_pax)
|
||||
{
|
||||
while(p&&*p)
|
||||
{
|
||||
/* Throw away any stale frames */
|
||||
overlay_frame *pp=*p;
|
||||
|
||||
if (!pp) break;
|
||||
|
||||
if (now>((*p)->enqueued_at+200)) {
|
||||
/* Stale, so remove from queue */
|
||||
*p=pp->next;
|
||||
pp->next->prev=*p;
|
||||
op_free(*p);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* XXX Filter for those which should be sent via this interface.
|
||||
To do that we need to know the nexthop, and the best route to the next hop. */
|
||||
|
||||
/* We keep trying to queue frames in case they will fit, as not all frames are of equal size.
|
||||
This means that lower bit-rate codecs will get higher priority, which is probably not all
|
||||
bad. The only hard limit is the maximum number of payloads we allow in a frame, which is
|
||||
set so high as to be irrelevant, even on loopback or gigabit ethernet interface */
|
||||
if (*frame_pax>=frame_max_pax) break;
|
||||
if (!overlay_frame_package_fmt1(*p,e))
|
||||
{
|
||||
/* Add payload to list of payloads we are sending with this frame so that we can dequeue them
|
||||
if we send them. */
|
||||
pax[(*frame_pax)++]=*p;
|
||||
}
|
||||
p=&(*p)->next;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_tick_interface(int i, long long now)
|
||||
{
|
||||
int frame_pax=0;
|
||||
#define MAX_FRAME_PAX 1024
|
||||
overlay_frame *pax[MAX_FRAME_PAX];
|
||||
overlay_frame **p;
|
||||
|
||||
if (overlay_interfaces[i].bits_per_second<1) {
|
||||
/* An interface with no speed budget is for listening only, so doesn't get ticked */
|
||||
@ -505,44 +543,15 @@ int overlay_tick_interface(int i, long long now)
|
||||
overlay_add_selfannouncement(i,e);
|
||||
|
||||
/* 2. Add any queued high-priority isochronous data (i.e. voice) to the frame. */
|
||||
overlay_frame **p=&overlay_tx[OVERLAY_ISOCHRONOUS_VOICE].first;
|
||||
while(p)
|
||||
{
|
||||
/* Throw away any stale frames */
|
||||
overlay_frame *pp=*p;
|
||||
|
||||
if (!pp) break;
|
||||
|
||||
if (now>((*p)->enqueued_at+200)) {
|
||||
/* Stale, so remove from queue */
|
||||
*p=pp->next;
|
||||
pp->next->prev=*p;
|
||||
op_free(*p);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* XXX Filter for those which should be sent via this interface.
|
||||
To do that we need to know the nexthop, and the best route to the next hop. */
|
||||
|
||||
/* We keep trying to queue frames in case they will fit, as not all frames are of equal size.
|
||||
This means that lower bit-rate codecs will get higher priority, which is probably not all
|
||||
bad. The only hard limit is the maximum number of payloads we allow in a frame, which is
|
||||
set so high as to be irrelevant, even on loopback or gigabit ethernet interface */
|
||||
if (frame_pax>=MAX_FRAME_PAX) break;
|
||||
if (!overlay_frame_package_fmt1(*p,e))
|
||||
{
|
||||
/* Add payload to list of payloads we are sending with this frame so that we can dequeue them
|
||||
if we send them. */
|
||||
pax[frame_pax++]=*p;
|
||||
}
|
||||
p=&(*p)->next;
|
||||
}
|
||||
}
|
||||
p=&overlay_tx[OVERLAY_ISOCHRONOUS_VOICE].first;
|
||||
overlay_stuff_packet_from_queue(i,e,p,now,pax,&frame_pax,MAX_FRAME_PAX);
|
||||
|
||||
/* 3. Add some mesh reachability reports (unlike BATMAN we announce reachability to peers progressively).
|
||||
Give priority to newly observed nodes so that good news travels quickly to help roaming.
|
||||
XXX - Don't forget about PONGing reachability reports to allow use of monodirectional links.
|
||||
*/
|
||||
p=&overlay_tx[OVERLAY_MESH_MANAGEMENT].first;
|
||||
overlay_stuff_packet_from_queue(i,e,p,now,pax,&frame_pax,MAX_FRAME_PAX);
|
||||
|
||||
/* 4. XXX Add lower-priority queued data */
|
||||
|
||||
|
@ -161,9 +161,13 @@ int overlay_frame_resolve_addresses(int interface,overlay_frame *f)
|
||||
f->destination_address_status=overlay_abbreviate_expand_address(interface,f->bytes,&offset,f->destination,&alen);
|
||||
alen=0;
|
||||
f->source_address_status=overlay_abbreviate_expand_address(interface,f->bytes,&offset,f->source,&alen);
|
||||
f->payload=&f->bytes[offset];
|
||||
f->payloadlength=f->bytecount-offset;
|
||||
if (f->payloadlength<0) return WHY("Abbreviated ddresses run past end of packet");
|
||||
|
||||
/* Copy payload into overlay_buffer structure */
|
||||
if (f->bytecount-offset<0) return WHY("Abbreviated ddresses run past end of packet");
|
||||
if (!f->payload) f->payload=ob_new(f->bytecount-offset); else f->payload->length=0;
|
||||
if (!f->payload) return WHY("calloc(overlay_buffer) failed.");
|
||||
if (ob_append_bytes(f->payload,&f->bytes[offset],f->bytecount-offset))
|
||||
return WHY("ob_append_bytes() failed.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -190,10 +194,7 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
*/
|
||||
|
||||
unsigned char c;
|
||||
int zero=0;
|
||||
|
||||
/* Make sure we can find our SID */
|
||||
if (!findHlr(hlr,&zero,NULL,NULL)) return WHY("Could not find first entry in HLR");
|
||||
unsigned char *sid=overlay_get_my_sid();
|
||||
|
||||
/* Header byte */
|
||||
c=OF_TYPE_SELFANNOUNCE;
|
||||
@ -238,14 +239,14 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
address in full an arbitrary 1 in 4 times.
|
||||
*/
|
||||
if (overlay_interfaces[interface].ticks_since_sent_full_address>3)
|
||||
{ if (ob_append_bytes(b,&hlr[zero+4],SID_SIZE)) return WHY("Could not append SID to self-announcement");
|
||||
{ if (ob_append_bytes(b,sid,SID_SIZE)) return WHY("Could not append SID to self-announcement");
|
||||
overlay_interfaces[interface].ticks_since_sent_full_address=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
c=OA_CODE_PREFIX7;
|
||||
if (ob_append_bytes(b,&c,1)) return WHY("ob_append_bytes() could not add address format code.");
|
||||
if (ob_append_bytes(b,&hlr[zero+4],7)) return WHY("Could not append SID prefix to self-announcement");
|
||||
if (ob_append_bytes(b,sid,7)) return WHY("Could not append SID prefix to self-announcement");
|
||||
overlay_interfaces[interface].ticks_since_sent_full_address++;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
we rely on context for abbreviating the addresses. So we write it initially and then patch it
|
||||
after.
|
||||
*/
|
||||
int max_len=((SID_SIZE+3)*3+headers->length+p->payloadlength);
|
||||
int max_len=((SID_SIZE+3)*3+headers->length+p->payload->length);
|
||||
ob_append_rfs(b,max_len);
|
||||
|
||||
int addrs_len=b->length;
|
||||
@ -95,7 +95,7 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
overlay_abbreviate_set_most_recent_address(p->source);
|
||||
|
||||
addrs_len=b->length-addrs_len;
|
||||
int actual_len=addrs_len+p->payloadlength;
|
||||
int actual_len=addrs_len+p->payload->length;
|
||||
ob_patch_rfs(b,actual_len);
|
||||
|
||||
if (fail) {
|
||||
@ -104,7 +104,7 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
}
|
||||
|
||||
/* Write payload format plus total length of header bits */
|
||||
if (ob_makespace(b,2+headers->length+p->payloadlength)) {
|
||||
if (ob_makespace(b,2+headers->length+p->payload->length)) {
|
||||
/* Not enough space free in output buffer */
|
||||
ob_free(headers);
|
||||
return WHY("Could not make enough space free in output buffer");
|
||||
@ -112,11 +112,11 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
|
||||
/* Package up headers and payload */
|
||||
ob_checkpoint(b);
|
||||
if (ob_append_short(b,0x1000|(p->payloadlength+headers->length)))
|
||||
if (ob_append_short(b,0x1000|(p->payload->length+headers->length)))
|
||||
{ fail++; WHY("could not append version and length bytes"); }
|
||||
if (ob_append_bytes(b,headers->bytes,headers->length))
|
||||
{ fail++; WHY("could not append header"); }
|
||||
if (ob_append_bytes(b,p->payload,p->payloadlength))
|
||||
if (ob_append_bytes(b,p->payload->bytes,p->payload->length))
|
||||
{ fail++; WHY("could not append payload"); }
|
||||
|
||||
/* XXX SIGN &/or ENCRYPT */
|
||||
@ -148,8 +148,37 @@ int op_free(overlay_frame *p)
|
||||
if (p->next&&p->next->prev==p) return WHY("p->next->prev still points here");
|
||||
p->prev=NULL;
|
||||
p->next=NULL;
|
||||
if (p->payload) free(p->payload);
|
||||
if (p->payload) ob_free(p->payload);
|
||||
p->payload=NULL;
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
f->source_address_status=OA_RESOLVED;
|
||||
|
||||
return WHY("Not implemented");
|
||||
}
|
||||
|
||||
unsigned char *overlay_get_my_sid()
|
||||
{
|
||||
|
||||
/* Make sure we can find our SID */
|
||||
int zero=0;
|
||||
if (!findHlr(hlr,&zero,NULL,NULL)) { WHY("Could not find first entry in HLR"); return NULL; }
|
||||
return &hlr[zero+4];
|
||||
}
|
||||
|
||||
int overlay_frame_set_me_as_source(overlay_frame *f)
|
||||
{
|
||||
unsigned char *sid=overlay_get_my_sid();
|
||||
if (!sid) return WHY("overlay_get_my_sid() failed.");
|
||||
bcopy(sid,f->source,SID_SIZE);
|
||||
|
||||
f->source_address_status=OA_RESOLVED;
|
||||
|
||||
return WHY("Not implemented");
|
||||
}
|
||||
|
150
overlay_route.c
150
overlay_route.c
@ -329,9 +329,11 @@ unsigned int overlay_route_hash_sid(unsigned char *sid)
|
||||
|
||||
/* Mask out extranous bits to return only a valid bin number */
|
||||
bin&=(overlay_bin_count-1);
|
||||
fprintf(stderr,"The following address resolves to bin #%d\n",bin);
|
||||
for(i=0;i<SID_SIZE;i++) fprintf(stderr,"%02x",sid[i]);
|
||||
fprintf(stderr,"\n");
|
||||
if (debug>2) {
|
||||
fprintf(stderr,"The following address resolves to bin #%d\n",bin);
|
||||
for(i=0;i<SID_SIZE;i++) fprintf(stderr,"%02x",sid[i]);
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
||||
@ -368,8 +370,104 @@ overlay_node *overlay_route_find_node(unsigned char *sid,int createP)
|
||||
return &overlay_nodes[bin_number][free_slot];
|
||||
}
|
||||
|
||||
int overlay_route_ack_selfannounce(overlay_frame *f)
|
||||
int overlay_route_ack_selfannounce(overlay_frame *f,overlay_neighbour *n)
|
||||
{
|
||||
/* Acknowledge the receipt of a self-announcement of an immediate neighbour.
|
||||
We could acknowledge immediately, but that requires the transmission of an
|
||||
extra packet with all the overhead that entails. However, there is no real
|
||||
need to send the ack out immediately. It should be entirely reasonable to
|
||||
send the ack out with the next interface tick.
|
||||
|
||||
So we can craft the ack and submit it to the queue. As the next-hop will get
|
||||
determined at TX time, this will ensure that we send the packet out on the
|
||||
right interface to reach the originator of the self-assessment.
|
||||
|
||||
So all we need to do is craft the payload and put it onto the queue for
|
||||
OVERLAY_MESH_MANAGEMENT messages.
|
||||
|
||||
Also, we should check for older such frames on the queue and drop them.
|
||||
*/
|
||||
|
||||
/* XXX Allocate overlay_frame structure and populate it */
|
||||
overlay_frame *out=NULL;
|
||||
out=calloc(sizeof(overlay_frame),1);
|
||||
if (!out) return WHY("calloc() failed to allocate an overlay frame");
|
||||
|
||||
out->type=OF_TYPE_SELFANNOUNCE_ACK;
|
||||
out->modifiers=0;
|
||||
out->ttl=6; /* maximum time to live for an ack taking an indirect route back
|
||||
to the originator. If it were 1, then we would not be able to
|
||||
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)) {
|
||||
op_free(out);
|
||||
return WHY("overlay_frame_set_neighbour_as_source() failed");
|
||||
}
|
||||
/* set source to ourselves */
|
||||
overlay_frame_set_me_as_source(out);
|
||||
/* (next-hop will get set at TX time, so no need to set it here) */
|
||||
out->nexthop_address_status=OA_UNINITIALISED;
|
||||
|
||||
/* Set the time in the ack. Use the last sequence number we have seen
|
||||
from this neighbour, as that may be helpful information for that neighbour
|
||||
down the track. My policy is to communicate that information which should
|
||||
be helpful for forming and maintaining the health of the mesh, as that way
|
||||
each node can in potentially implement a different mesh routing protocol,
|
||||
without breaking the wire protocol. This makes over-the-air software updates
|
||||
much safer.
|
||||
|
||||
Combining of adjacent observation reports may mean that the most recent
|
||||
observation is not the last one in the list, also the wrapping of the sequence
|
||||
numbers means we can't just take the highest-numbered sequence number.
|
||||
So we need to take the observation which was most recently received.
|
||||
*/
|
||||
int i;
|
||||
int best_obs_id=-1;
|
||||
long long best_obs_time=0;
|
||||
for(i=0;i<OVERLAY_MAX_OBSERVATIONS;i++) {
|
||||
if (n->observations[i].time_ms>best_obs_time) {
|
||||
best_obs_id=i;
|
||||
best_obs_time=n->observations[i].time_ms;
|
||||
}
|
||||
}
|
||||
ob_append_int(out->payload,n->observations[best_obs_id].s2);
|
||||
|
||||
/* The ack needs to contain the per-interface scores that we have built up
|
||||
for this neighbour.
|
||||
We expect that for most neighbours they will have many fewer than 32 interfaces,
|
||||
and even when they have multiple interfaces that we will only be able to hear
|
||||
them on one or a few.
|
||||
|
||||
So we will structure the format so that we use fewer bytes when fewer interfaces
|
||||
are involved.
|
||||
|
||||
Probably the simplest is to put each non-zero score followed by it's interface.
|
||||
That way the whole list will be easy to parse, and as short as 3 bytes for a
|
||||
single interface.
|
||||
|
||||
We could use the spare 2 bits at the top of the interface id to indicate
|
||||
multiple interfaces with same score?
|
||||
*/
|
||||
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
|
||||
{
|
||||
/* Only include interfaces with score >0 */
|
||||
if (n->scores[i]) {
|
||||
ob_append_byte(out->payload,n->scores[i]);
|
||||
ob_append_byte(out->payload,i);
|
||||
}
|
||||
}
|
||||
/* Terminate list */
|
||||
ob_append_byte(out->payload,0);
|
||||
|
||||
/* XXX Add to queue */
|
||||
|
||||
/* XXX Remove any stale versions (or should we just freshen, and forget making
|
||||
a new one, since it would be more efficient). */
|
||||
|
||||
/* XXX Temporary to stop memory leaks while writing the rest of this function */
|
||||
op_free(out);
|
||||
|
||||
return WHY("Not implemented");
|
||||
}
|
||||
|
||||
@ -397,7 +495,21 @@ int overlay_route_make_neighbour(overlay_node *n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned int s1,unsigned int s2,int receiver_interface,long long now)
|
||||
overlay_neighbour *overlay_route_get_neighbour_structure(unsigned char *packed_sid)
|
||||
{
|
||||
overlay_node *n=overlay_route_find_node(packed_sid,1 /* create if necessary */);
|
||||
if (!n) { WHY("Could not find node record for observed node"); return NULL; }
|
||||
|
||||
/* Check if node is already a neighbour, or if not, make it one */
|
||||
if (!n->neighbour_id) if (overlay_route_make_neighbour(n)) { WHY("overlay_route_make_neighbour() failed"); return NULL; }
|
||||
|
||||
/* Get neighbour structure */
|
||||
return &overlay_neighbours[n->neighbour_id];
|
||||
|
||||
}
|
||||
|
||||
int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned int s1,unsigned int s2,
|
||||
int receiver_interface,long long now)
|
||||
{
|
||||
/* 1. Find (or create) node entry for the node.
|
||||
2. Replace oldest observation with this observation.
|
||||
@ -429,7 +541,6 @@ int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned in
|
||||
neh->observations[obs_index].sender_interface=sender_interface;
|
||||
neh->observations[obs_index].receiver_interface=receiver_interface;
|
||||
neh->observations[obs_index].time_ms=now;
|
||||
fprintf(stderr,">>> Merging observations.\n");
|
||||
mergedP=1;
|
||||
break;
|
||||
}
|
||||
@ -453,8 +564,6 @@ int overlay_route_i_can_hear(unsigned char *who,int sender_interface,unsigned in
|
||||
neh->last_observation_time_ms=now;
|
||||
}
|
||||
|
||||
WHY("stored observation");
|
||||
|
||||
/* Update reachability metrics for node */
|
||||
if (overlay_route_recalc_neighbour_metrics(neh,now)) WHY("overlay_route_recalc_neighbour_metrics() failed");
|
||||
|
||||
@ -465,15 +574,18 @@ int overlay_route_saw_selfannounce(int interface,overlay_frame *f,long long now)
|
||||
{
|
||||
unsigned int s1,s2;
|
||||
unsigned char sender_interface;
|
||||
|
||||
s1=ntohl(*((int*)&f->payload[0]));
|
||||
s2=ntohl(*((int*)&f->payload[4]));
|
||||
sender_interface=ntohl(*((unsigned char*)&f->payload[8]));
|
||||
fprintf(stderr,"Received self-announcement for sequence range [%08x,%08x]\n",s1,s2);
|
||||
overlay_neighbour *n=overlay_route_get_neighbour_structure(f->source);
|
||||
|
||||
if (!n) return WHY("overlay_route_get_neighbour_structure() failed");
|
||||
|
||||
s1=ntohl(*((int*)&f->payload->bytes[0]));
|
||||
s2=ntohl(*((int*)&f->payload->bytes[4]));
|
||||
sender_interface=f->payload->bytes[8];
|
||||
fprintf(stderr,"Received self-announcement for sequence range [%08x,%08x] from interface %d\n",s1,s2,sender_interface);
|
||||
|
||||
overlay_route_i_can_hear(f->source,sender_interface,s1,s2,interface,now);
|
||||
|
||||
overlay_route_ack_selfannounce(f);
|
||||
overlay_route_ack_selfannounce(f,n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -544,8 +656,12 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
||||
if (n->observations[i].valid&&n->observations[i].s1&&((now-n->observations[i].time_ms)<200000)) {
|
||||
/* No need to do wrap-around calculation as the following is modulo 2^32 also */
|
||||
unsigned int interval=n->observations[i].s2-n->observations[i].s1;
|
||||
fprintf(stderr,"adding %dms\n",interval);
|
||||
ms_observed[n->observations[i].sender_interface]+=interval;
|
||||
/* Support interface tick speeds down to 1 per hour (well and truly slow enough to do
|
||||
50KB/12 hours which is the minimum traffic rate on an expensive BGAN satellite link) */
|
||||
if (interval<3600000) {
|
||||
fprintf(stderr,"adding %dms\n",interval);
|
||||
ms_observed[n->observations[i].sender_interface]+=interval;
|
||||
}
|
||||
|
||||
if (n->observations[i].time_ms>most_recent_observation) most_recent_observation=n->observations[i].time_ms;
|
||||
}
|
||||
@ -564,6 +680,8 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
||||
else if ((100+(ms_observed[i]/500-20))<200) score=100+(ms_observed[i]/500-20); // 100 - 199
|
||||
else if ((200+(ms_observed[i]/3000-20))<255) score=200+(ms_observed[i]/3000-20); // 200 - 254
|
||||
else score=255;
|
||||
/* Deal with invalid sequence number ranges */
|
||||
if (score<0) score=0;
|
||||
}
|
||||
|
||||
/* Reduce score by 1 point for each second we have not seen anything from it */
|
||||
|
@ -245,7 +245,7 @@ int packetFinalise(unsigned char *packet,int packet_maxlen,int *packet_len,int c
|
||||
packet[OFS_ROTATIONFIELD]=payloadRotation;
|
||||
if (debug>3) dump("rotated packet",packet,*packet_len);
|
||||
|
||||
if (cryptoflags) return packetEncipher(packet,packet_maxlen,packet_len);
|
||||
if (cryptoflags) return packetEncipher(packet,packet_maxlen,packet_len,cryptoflags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
4
server.c
4
server.c
@ -189,7 +189,7 @@ int processRequest(unsigned char *packet,int len,
|
||||
char emitterPhoneNumber[256];
|
||||
char message[256];
|
||||
pofs++;
|
||||
char messageType = packet[pofs];
|
||||
/* char messageType = packet[pofs]; */
|
||||
pofs++;
|
||||
char emitterPhoneNumberLen = packet[pofs];
|
||||
pofs++;
|
||||
@ -211,7 +211,7 @@ int processRequest(unsigned char *packet,int len,
|
||||
char amCommand[576]; // 64 char + 2*256(max) char = 576
|
||||
sprintf(amCommand, "am broadcast -a org.servalproject.DT -e number \"%s\" -e content \"%s\"", emitterPhoneNumber, message);
|
||||
if (debug>1) fprintf(stderr,"Delivering DT message via intent: %s\n",amCommand);
|
||||
int exitcode = runCommand(amCommand);
|
||||
runCommand(amCommand);
|
||||
respondSimple(hlrSid(hlr, ofs),ACTION_OKAY,NULL,0,transaction_id,sender,CRYPT_CIPHERED|CRYPT_SIGNED);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user