From b048e8874fe1e77e379fc6ffd65a6711e955aa0c Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Mon, 23 Mar 2015 13:33:15 +1030 Subject: [PATCH] Reschedule alarm when tick_ms config changed --- java/org/servalproject/codec/Base64.java | 24 +++++++++--- overlay_interface.c | 48 +++++++++++++++--------- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/java/org/servalproject/codec/Base64.java b/java/org/servalproject/codec/Base64.java index 89df7773..9b3b673e 100644 --- a/java/org/servalproject/codec/Base64.java +++ b/java/org/servalproject/codec/Base64.java @@ -69,14 +69,28 @@ public class Base64 { public static byte[] decode(String value) { - int len = value.length()/4 * 3; + int strlen = value.length(); if (value.endsWith("==")) - len -=2; - else if(value.endsWith("=")) - len --; + strlen-=2; + else if (value.endsWith("=")) + strlen--; + + int len = (strlen+3)/4 * 3; + switch(strlen%4){ + case 0: + break; + case 1: + case 2: + len -=2; + break; + case 3: + len --; + break; + } + byte ret[] = new byte[len]; int pos=0; - for (int i=0;idestination->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; + time_ms_t next_allowed = limit_next_allowed(&interface->destination->transfer_limit); + if (next_tick < next_allowed) + next_tick = next_allowed; + + interface->alarm.alarm = next_tick; + interface->alarm.deadline=interface->alarm.alarm+interface->destination->ifconfig.tick_ms/2; +} + static int overlay_interface_init_socket(overlay_interface *interface) { @@ -472,6 +492,7 @@ int overlay_destination_configure(struct network_destination *dest, const struct dest->ifconfig.tick_ms=0; }else if (!dest->ifconfig.send){ INFOF("Destination is not sending any traffic!"); + dest->ifconfig.tick_ms=0; }else if (dest->ifconfig.tick_ms==0) INFOF("Destination is running tickless"); @@ -481,8 +502,6 @@ int overlay_destination_configure(struct network_destination *dest, const struct if (dest->ifconfig.reachable_timeout_ms<0) dest->ifconfig.reachable_timeout_ms = tick_ms>0 ? tick_ms * 5 : 2500; - if (dest->ifconfig.mtu < 400) - dest->ifconfig.encapsulation=ENCAP_SINGLE; limit_init(&dest->transfer_limit, dest->ifconfig.packet_interval); @@ -497,7 +516,12 @@ int overlay_interface_configure(struct overlay_interface *interface, const struc if (ifconfig->socket_type==SOCK_STREAM) interface->ifconfig.unicast.send=0; - + + // schedule the first tick asap + unschedule(&interface->alarm); + calc_next_tick(interface); + schedule(&interface->alarm); + return 0; } @@ -534,9 +558,6 @@ overlay_interface_init(const char *name, struct socket_address *addr, set_destination_ref(&interface->destination, NULL); interface->destination = new_destination(interface); - if (overlay_interface_configure(interface, ifconfig)==-1) - return -1; - interface->alarm.poll.fd=0; interface->tx_count=0; interface->recv_count=0; @@ -549,6 +570,9 @@ overlay_interface_init(const char *name, struct socket_address *addr, interface_poll_stats.name="overlay_interface_poll"; interface->alarm.stats=&interface_poll_stats; + if (overlay_interface_configure(interface, ifconfig)==-1) + return -1; + switch(ifconfig->socket_type){ case SOCK_DGRAM: if (ifconfig->broadcast.drop || ifconfig->unicast.drop || ifconfig->drop_packets) @@ -603,10 +627,6 @@ overlay_interface_init(const char *name, struct socket_address *addr, } } - // schedule the first tick asap - interface->alarm.alarm=gettime_ms(); - interface->alarm.deadline=interface->alarm.alarm; - schedule(&interface->alarm); interface->state=INTERFACE_STATE_UP; monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:UP\n", interface->name); INFOF("Interface %s addr %s, is up",interface->name, alloca_socket_address(addr)); @@ -801,13 +821,7 @@ static void overlay_interface_poll(struct sched_ent *alarm) if (now >= interface->destination->last_tx+interface->destination->ifconfig.tick_ms) overlay_send_tick_packet(interface->destination); - 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; - - alarm->alarm=interface->destination->last_tx+interval; - alarm->deadline=alarm->alarm+interface->destination->ifconfig.tick_ms/2; + calc_next_tick(interface); } switch(interface->ifconfig.socket_type){