mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 10:46:23 +00:00
Fix bug in self-announcements
On first tick, do not send s1 = 0, but s1 = s2 - 1 (1 ms window)
This commit is contained in:
parent
813cf94f79
commit
24b05eaeaa
@ -282,7 +282,7 @@ int overlay_interface_init(char *name,struct sockaddr_in *src_addr,struct sockad
|
||||
I(bits_per_second)=speed_in_bits;
|
||||
I(port)=port;
|
||||
I(type)=type;
|
||||
I(last_tick_ms)=0;
|
||||
I(last_tick_ms)= -1; // not ticked yet
|
||||
I(alarm.poll.fd)=0;
|
||||
switch (type) {
|
||||
case OVERLAY_INTERFACE_PACKETRADIO:
|
||||
@ -403,7 +403,7 @@ void overlay_dummy_poll(struct sched_ent *alarm)
|
||||
unsigned char transaction_id[8];
|
||||
unsigned long long now = gettime_ms();
|
||||
|
||||
if (interface->last_tick_ms + interface->tick_ms <= now){
|
||||
if (interface->last_tick_ms == -1 || now >= interface->last_tick_ms + interface->tick_ms) {
|
||||
// tick the interface
|
||||
int i = (interface - overlay_interfaces);
|
||||
overlay_tick_interface(i, now);
|
||||
@ -416,12 +416,10 @@ void overlay_dummy_poll(struct sched_ent *alarm)
|
||||
/* if there's no input, while we want to check for more soon,
|
||||
we need to allow all other low priority alarms to fire first,
|
||||
otherwise we'll dominate the scheduler without accomplishing anything */
|
||||
|
||||
alarm->alarm = gettime_ms()+20;
|
||||
alarm->deadline = alarm->alarm + 10000;
|
||||
|
||||
if (alarm->alarm > interface->last_tick_ms + interface->tick_ms)
|
||||
alarm->alarm = gettime_ms() + 20;
|
||||
if (interface->last_tick_ms != -1 && alarm->alarm > interface->last_tick_ms + interface->tick_ms)
|
||||
alarm->alarm = interface->last_tick_ms + interface->tick_ms;
|
||||
alarm->deadline = alarm->alarm + 10000;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -988,7 +986,8 @@ int overlay_tick_interface(int i, long long now)
|
||||
/* 1. Send announcement about ourselves, including one SID that we host if we host more than one SID
|
||||
(the first SID we host becomes our own identity, saving a little bit of data here).
|
||||
*/
|
||||
overlay_add_selfannouncement(i,packet.buffer);
|
||||
if (overlay_add_selfannouncement(i,packet.buffer) == -1)
|
||||
return WHY("tick failed");
|
||||
|
||||
/* Add advertisements for ROUTES */
|
||||
overlay_route_add_advertisements(packet.buffer);
|
||||
|
@ -344,15 +344,22 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
/* And the sender for any other addresses in this packet */
|
||||
overlay_abbreviate_set_current_sender(sid);
|
||||
|
||||
/* Sequence number range. Based on one tick per milli-second. */
|
||||
|
||||
if (ob_append_int(b,overlay_interfaces[interface].last_tick_ms))
|
||||
/* Sequence number range. Based on one tick per millisecond. */
|
||||
long long last_ms = overlay_interfaces[interface].last_tick_ms;
|
||||
// If this interface has not been ticked yet (no selfannounce sent) then invent the prior sequence
|
||||
// number: one millisecond ago.
|
||||
if (last_ms == -1)
|
||||
last_ms = now - 1;
|
||||
if (ob_append_int(b, last_ms))
|
||||
return WHY("Could not add low sequence number to self-announcement");
|
||||
if (ob_append_int(b,now))
|
||||
if (ob_append_int(b, now))
|
||||
return WHY("Could not add high sequence number to self-announcement");
|
||||
overlay_interfaces[interface].last_tick_ms=now;
|
||||
if (debug&DEBUG_OVERLAYINTERFACES)
|
||||
DEBUGF("last tick seq# = %lld", overlay_interfaces[interface].last_tick_ms);
|
||||
DEBUGF("interface #%d: last_tick_ms=%lld, now=%lld (delta=%lld)",
|
||||
interface, overlay_interfaces[interface].last_tick_ms, now,
|
||||
now - last_ms
|
||||
);
|
||||
overlay_interfaces[interface].last_tick_ms = now;
|
||||
|
||||
/* A byte that indicates which interface we are sending over */
|
||||
if (ob_append_byte(b,interface))
|
||||
|
@ -591,7 +591,6 @@ int overlay_route_ack_selfannounce(overlay_frame *f,
|
||||
However, if there is no known next-hop for this node (because the return path
|
||||
has not yet begun to be built), then we need to set the nexthop to broadcast. */
|
||||
out->nexthop_address_status=OA_UNINITIALISED;
|
||||
{
|
||||
if (overlay_resolve_next_hop(out)) {
|
||||
/* no open path, so convert to broadcast */
|
||||
int i;
|
||||
@ -602,8 +601,8 @@ int overlay_route_ack_selfannounce(overlay_frame *f,
|
||||
out->isBroadcast=1;
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUG("Broadcasting ack to selfannounce for hithero unroutable node");
|
||||
} else out->isBroadcast=0;
|
||||
}
|
||||
} else
|
||||
out->isBroadcast = 0;
|
||||
|
||||
/* 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
|
||||
@ -965,9 +964,9 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
||||
unsigned int interval=n->observations[i].s2-n->observations[i].s1;
|
||||
|
||||
/* Check the observation age, and ignore if too old */
|
||||
int obs_age=now-n->observations[i].time_ms;
|
||||
long long obs_age = now - n->observations[i].time_ms;
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUGF("tallying obs: %dms old, %dms long", obs_age,interval);
|
||||
DEBUGF("tallying obs: %lldms old, %ums long", obs_age,interval);
|
||||
|
||||
/* Ignore very large intervals (>1hour) as being likely to be erroneous.
|
||||
(or perhaps a clock wrap due to the modulo arithmatic)
|
||||
|
Loading…
Reference in New Issue
Block a user