mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 17:33:08 +00:00
Use configured reachable timeout for network links, read dummy files even when not ticking
This commit is contained in:
parent
943bca3bea
commit
fea91f3f82
@ -400,20 +400,25 @@ static int overlay_interface_init_any(int port)
|
||||
|
||||
static void calc_next_tick(struct overlay_interface *interface)
|
||||
{
|
||||
if (!interface->destination->ifconfig.tick_ms){
|
||||
interface->alarm.deadline=interface->alarm.alarm=TIME_MS_NEVER_WILL;
|
||||
return;
|
||||
}
|
||||
time_ms_t interval = interface->destination->ifconfig.tick_ms;
|
||||
// only tick every 5s if we have no neighbours here
|
||||
if (interval < 5000 && !link_interface_has_neighbours(interface))
|
||||
interval = 5000;
|
||||
|
||||
time_ms_t next_tick = interface->destination->last_tx+interval;
|
||||
if (!interface->destination->ifconfig.tick_ms){
|
||||
next_tick=TIME_MS_NEVER_WILL;
|
||||
}
|
||||
time_ms_t next_allowed = limit_next_allowed(&interface->destination->transfer_limit);
|
||||
if (next_tick < next_allowed)
|
||||
next_tick = next_allowed;
|
||||
|
||||
if (interface->ifconfig.socket_type==SOCK_FILE){
|
||||
time_ms_t next_read = gettime_ms()+10;
|
||||
if (next_tick > next_read)
|
||||
next_tick = next_read;
|
||||
}
|
||||
|
||||
interface->alarm.alarm = next_tick;
|
||||
interface->alarm.deadline=interface->alarm.alarm+interface->destination->ifconfig.tick_ms/2;
|
||||
}
|
||||
@ -725,12 +730,13 @@ static void interface_read_file(struct overlay_interface *interface)
|
||||
off_t length = lseek(interface->alarm.poll.fd, (off_t)0, SEEK_END);
|
||||
if (interface->recv_offset > length)
|
||||
FATALF("File shrunk? It shouldn't shrink! Ever");
|
||||
int new_packets = (length - interface->recv_offset) / sizeof packet;
|
||||
if (new_packets > 20)
|
||||
WARNF("Getting behind, there are %d unread packets (%"PRId64" vs %"PRId64")",
|
||||
new_packets, (int64_t)interface->recv_offset, (int64_t)length);
|
||||
|
||||
|
||||
if (interface->recv_offset<length){
|
||||
int new_packets = (length - interface->recv_offset) / sizeof packet;
|
||||
if (new_packets > 20)
|
||||
WARNF("Getting behind, there are %d unread packets (%"PRId64" vs %"PRId64")",
|
||||
new_packets, (int64_t)interface->recv_offset, (int64_t)length);
|
||||
|
||||
if (lseek(interface->alarm.poll.fd,interface->recv_offset,SEEK_SET) == -1){
|
||||
WHY_perror("lseek");
|
||||
OUT();
|
||||
@ -772,14 +778,14 @@ static void interface_read_file(struct overlay_interface *interface)
|
||||
otherwise we'll dominate the scheduler without accomplishing anything */
|
||||
time_ms_t now = gettime_ms();
|
||||
if (interface->recv_offset>=length){
|
||||
if (interface->alarm.alarm == -1 || now + 5 < interface->alarm.alarm){
|
||||
if (now + 5 < interface->alarm.alarm){
|
||||
interface->alarm.alarm = now + 5;
|
||||
interface->alarm.deadline = interface->alarm.alarm + 500;
|
||||
}
|
||||
}else{
|
||||
/* keep reading new packets as fast as possible,
|
||||
but don't completely prevent other high priority alarms */
|
||||
if (interface->alarm.alarm == -1 || now < interface->alarm.alarm){
|
||||
if (now < interface->alarm.alarm){
|
||||
interface->alarm.alarm = now;
|
||||
interface->alarm.deadline = interface->alarm.alarm + 100;
|
||||
}
|
||||
@ -811,7 +817,7 @@ static void overlay_interface_poll(struct sched_ent *alarm)
|
||||
time_ms_t now = gettime_ms();
|
||||
|
||||
if (alarm->poll.revents==0){
|
||||
alarm->alarm=-1;
|
||||
alarm->alarm=TIME_MS_NEVER_WILL;
|
||||
|
||||
if (interface->state==INTERFACE_STATE_UP
|
||||
&& interface->destination->ifconfig.tick_ms>0
|
||||
@ -838,7 +844,7 @@ static void overlay_interface_poll(struct sched_ent *alarm)
|
||||
}
|
||||
|
||||
unschedule(alarm);
|
||||
if (alarm->alarm!=-1 && interface->state==INTERFACE_STATE_UP) {
|
||||
if (alarm->alarm!=TIME_MS_NEVER_WILL && interface->state==INTERFACE_STATE_UP) {
|
||||
if (alarm->alarm < now) {
|
||||
alarm->alarm = now;
|
||||
alarm->deadline = alarm->alarm + interface->destination->ifconfig.tick_ms / 2;
|
||||
@ -988,16 +994,16 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
|
||||
return WHY_perror("lseek");
|
||||
DEBUGF("Write to interface %s at offset unknown: src_addr=%s dst_addr=%s pid=%d length=%d",
|
||||
interface->name,
|
||||
alloca_sockaddr(&packet.src_addr, sizeof packet.src_addr),
|
||||
alloca_sockaddr(&packet.dst_addr, sizeof packet.dst_addr),
|
||||
alloca_socket_address(&packet.src_addr),
|
||||
alloca_socket_address(&packet.dst_addr),
|
||||
packet.pid,
|
||||
packet.payload_length
|
||||
);
|
||||
} else
|
||||
DEBUGF("Write to interface %s at offset=%"PRId64": src_addr=%s dst_addr=%s pid=%d length=%d",
|
||||
interface->name, (int64_t)fsize,
|
||||
alloca_sockaddr(&packet.src_addr, sizeof packet.src_addr),
|
||||
alloca_sockaddr(&packet.dst_addr, sizeof packet.dst_addr),
|
||||
alloca_socket_address(&packet.src_addr),
|
||||
alloca_socket_address(&packet.dst_addr),
|
||||
packet.pid,
|
||||
packet.payload_length
|
||||
);
|
||||
|
@ -120,7 +120,7 @@ int load_subscriber_address(struct subscriber *subscriber)
|
||||
if (*hostc->interface){
|
||||
interface = overlay_interface_find_name(hostc->interface);
|
||||
if (!interface)
|
||||
return WHY("Can't fund configured interface");
|
||||
return WHY("Can't find configured interface");
|
||||
}
|
||||
struct socket_address addr;
|
||||
bzero(&addr, sizeof(addr));
|
||||
@ -178,7 +178,7 @@ int overlay_send_probe(struct subscriber *peer, struct network_destination *dest
|
||||
// though unicast probes don't typically use the same network destination,
|
||||
// we should still try to throttle when we can
|
||||
if (destination->last_tx + destination->ifconfig.tick_ms > now)
|
||||
return -1;
|
||||
return WHY("Throttling probe packet");
|
||||
|
||||
// TODO enhance overlay_send_frame to support pre-supplied network destinations
|
||||
|
||||
|
@ -276,6 +276,10 @@ int overlay_queue_schedule_next(time_ms_t next_allowed_packet){
|
||||
}
|
||||
|
||||
void frame_remove_destination(struct overlay_frame *frame, int i){
|
||||
if (config.debug.overlayframes)
|
||||
DEBUGF("Remove %s destination on interface %s",
|
||||
frame->destinations[i].destination->unicast?"unicast":"broadcast",
|
||||
frame->destinations[i].destination->interface->name);
|
||||
release_destination_ref(frame->destinations[i].destination);
|
||||
frame->destination_count --;
|
||||
if (i<frame->destination_count)
|
||||
@ -289,8 +293,8 @@ void frame_add_destination(struct overlay_frame *frame, struct subscriber *next_
|
||||
frame->destinations[i].destination=add_destination_ref(dest);
|
||||
frame->destinations[i].next_hop = next_hop;
|
||||
frame->destinations[i].sent_sequence=-1;
|
||||
if (config.debug.verbose && config.debug.overlayframes)
|
||||
DEBUGF("Sending %s on interface %s",
|
||||
if (config.debug.overlayframes)
|
||||
DEBUGF("Add %s destination on interface %s",
|
||||
frame->destinations[i].destination->unicast?"unicast":"broadcast",
|
||||
frame->destinations[i].destination->interface->name);
|
||||
}
|
||||
@ -400,6 +404,7 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
|
||||
continue;
|
||||
}
|
||||
if (frame->enqueued_at + dest->ifconfig.transmit_timeout_ms < now){
|
||||
WARNF("Skipping packet destination due to timeout");
|
||||
frame_remove_destination(frame, i);
|
||||
continue;
|
||||
}
|
||||
|
17
route_link.c
17
route_link.c
@ -1091,18 +1091,15 @@ int link_add_destinations(struct overlay_frame *frame)
|
||||
added_interface[id]=1;
|
||||
}
|
||||
|
||||
if (frame->destination_count < MAX_PACKET_DESTINATIONS)
|
||||
frame->destinations[frame->destination_count++].destination=add_destination_ref(dest);
|
||||
frame_add_destination(frame, NULL, dest);
|
||||
|
||||
}else if(!(neighbour->subscriber->reachable & REACHABLE)){
|
||||
// send broadcast packets to neighbours before link establishment
|
||||
struct link_out *out = neighbour->out_links;
|
||||
time_ms_t now = gettime_ms();
|
||||
while(out){
|
||||
if (out->timeout>=now && frame->destination_count < MAX_PACKET_DESTINATIONS){
|
||||
unsigned dest = frame->destination_count++;
|
||||
frame->destinations[dest].destination = add_destination_ref(out->destination);
|
||||
}
|
||||
if (out->timeout>=now)
|
||||
frame_add_destination(frame, NULL, out->destination);
|
||||
out = out->_next;
|
||||
}
|
||||
}
|
||||
@ -1210,7 +1207,7 @@ static struct link_out *create_out_link(struct neighbour *neighbour, overlay_int
|
||||
alloca_tohex_sid_t(neighbour->subscriber->sid),
|
||||
interface->name);
|
||||
time_ms_t now = gettime_ms();
|
||||
ret->timeout = now + ret->destination->ifconfig.tick_ms * 3;
|
||||
ret->timeout = now + ret->destination->ifconfig.reachable_timeout_ms;
|
||||
update_alarm(__WHENCE__, now + 5);
|
||||
return ret;
|
||||
}
|
||||
@ -1284,7 +1281,7 @@ int link_received_packet(struct decode_context *context, int sender_seq, char un
|
||||
if (neighbour->next_neighbour_update > now + 10)
|
||||
neighbour->next_neighbour_update = now + 10;
|
||||
}
|
||||
link->link_timeout = now + (context->interface->destination->ifconfig.tick_ms *5);
|
||||
link->link_timeout = now + context->interface->destination->ifconfig.reachable_timeout_ms;
|
||||
|
||||
// force an update soon when we need to promptly ack packets
|
||||
if (neighbour->using_us && link->ack_counter <=0){
|
||||
@ -1438,7 +1435,7 @@ int link_receive(struct internal_mdp_header *header, struct overlay_buffer *payl
|
||||
// start sending sequence numbers when our neighbour has acked a packet
|
||||
if (out->destination->sequence_number<0)
|
||||
out->destination->sequence_number=0;
|
||||
out->timeout=now + out->destination->ifconfig.tick_ms * 5;
|
||||
out->timeout=now + out->destination->ifconfig.reachable_timeout_ms;
|
||||
destination = out->destination;
|
||||
|
||||
}else if(transmitter == my_subscriber){
|
||||
@ -1581,7 +1578,7 @@ int link_state_legacy_ack(struct overlay_frame *frame, time_ms_t now)
|
||||
|
||||
// track the incoming link so we remember to send broadcasts
|
||||
struct link_in *nl = get_neighbour_link(neighbour, frame->interface, iface, 0);
|
||||
nl->link_timeout = now + (link->destination->ifconfig.tick_ms *5);
|
||||
nl->link_timeout = now + (link->destination->ifconfig.reachable_timeout_ms);
|
||||
|
||||
neighbour->legacy_protocol = 1;
|
||||
neighbour->link_in_timeout = now + link->destination->ifconfig.reachable_timeout_ms;
|
||||
|
2
server.c
2
server.c
@ -165,7 +165,7 @@ static int server()
|
||||
olsr_init_socket();
|
||||
|
||||
/* Calculate (and possibly show) CPU usage stats periodically */
|
||||
RESCHEDULE(&ALARM_STRUCT(fd_periodicstats), now+3000, now+30000, TIME_MS_NEVER_WILL);
|
||||
RESCHEDULE(&ALARM_STRUCT(fd_periodicstats), now+3000, TIME_MS_NEVER_WILL, now+3500);
|
||||
|
||||
cf_on_config_change();
|
||||
|
||||
|
@ -102,10 +102,13 @@ configure_node() {
|
||||
set log.console.show_time on \
|
||||
set debug.mdprequests Yes \
|
||||
set debug.overlayframes Yes \
|
||||
set debug.overlayinterfaces Yes \
|
||||
set debug.linkstate Yes \
|
||||
set interfaces.0.file dummy1 \
|
||||
set interfaces.0.socket_type file \
|
||||
set interfaces.0.broadcast.send off \
|
||||
set interfaces.0.broadcast.drop on \
|
||||
set interfaces.0.broadcast.reachable_timeout_ms 10000 \
|
||||
set interfaces.0.unicast.route off \
|
||||
set interfaces.0.default_route 1 \
|
||||
set interfaces.0.dummy_address 10.0.${instance_number}.1 \
|
||||
@ -127,9 +130,10 @@ setup_routing() {
|
||||
executeOk_servald config \
|
||||
set directory.service $SIDA \
|
||||
set hosts.$SIDA.address 10.0.1.1
|
||||
foreach_instance +A +B +C start_routing_instance
|
||||
set_instance +A
|
||||
start_routing_instance
|
||||
wait_until grep "DNAHELPER got STARTED ACK" $instance_servald_log
|
||||
foreach_instance +B +C start_routing_instance
|
||||
}
|
||||
|
||||
doc_routing="Ping via relay node"
|
||||
|
@ -414,7 +414,7 @@ setup_scan() {
|
||||
test_scan() {
|
||||
set_instance +A
|
||||
executeOk_servald scan
|
||||
wait_until scan_completed
|
||||
wait_until --timeout=10 scan_completed
|
||||
wait_until --timeout=10 has_seen_instances +B +C
|
||||
executeOk_servald route print
|
||||
link_matches --unicast $SIDB
|
||||
|
Loading…
x
Reference in New Issue
Block a user