Only send broadcast ticks every 5 seconds when we have no neighbours

This commit is contained in:
Jeremy Lakeman 2014-06-13 15:34:47 +09:30
parent 628a52ca87
commit dabd482ad8
3 changed files with 23 additions and 3 deletions

View File

@ -739,8 +739,13 @@ static void overlay_interface_poll(struct sched_ent *alarm)
if (now >= interface->destination->last_tx+interface->destination->tick_ms)
overlay_send_tick_packet(interface->destination);
alarm->alarm=interface->destination->last_tx+interface->destination->tick_ms;
time_ms_t interval = interface->destination->tick_ms;
// only tick every 5s if we have no neighbours here
if (interval < 5000 && !link_interface_has_neighbours(interface))
interval = 5000;
alarm->alarm=interface->destination->last_tx+interval;
alarm->deadline=alarm->alarm+interface->destination->tick_ms/2;
}

View File

@ -167,6 +167,7 @@ struct link_state{
DEFINE_ALARM(link_send);
static int append_link(struct subscriber *subscriber, void *context);
static int neighbour_find_best_link(struct neighbour *n);
struct neighbour *neighbours=NULL;
int route_version=0;
@ -725,10 +726,23 @@ void link_neighbour_status_html(struct strbuf *b, struct subscriber *neighbour)
strbuf_puts(b, "Not found<br>");
}
int link_has_neighbours(){
int link_has_neighbours()
{
return neighbours?1:0;
}
int link_interface_has_neighbours(struct overlay_interface *interface)
{
struct neighbour *n = neighbours;
while(n){
neighbour_find_best_link(n);
if (n->best_link && n->best_link->interface == interface)
return 1;
n=n->_next;
}
return 0;
}
static int send_legacy_self_announce_ack(struct neighbour *neighbour, struct link_in *link, time_ms_t now){
struct overlay_frame *frame=emalloc_zero(sizeof(struct overlay_frame));
frame->type = OF_TYPE_SELFANNOUNCE_ACK;

View File

@ -333,6 +333,7 @@ void link_neighbour_short_status_html(struct strbuf *b, const char *link_prefix)
void link_neighbour_status_html(struct strbuf *b, struct subscriber *neighbour);
int link_stop_routing(struct subscriber *subscriber);
int link_has_neighbours();
int link_interface_has_neighbours(struct overlay_interface *interface);
int generate_nonce(unsigned char *nonce,int bytes);