mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-05-29 13:34:27 +00:00
Reschedule alarm when tick_ms config changed
This commit is contained in:
parent
f7dbe06836
commit
b048e8874f
@ -69,14 +69,28 @@ public class Base64 {
|
|||||||
|
|
||||||
public static byte[] decode(String value)
|
public static byte[] decode(String value)
|
||||||
{
|
{
|
||||||
int len = value.length()/4 * 3;
|
int strlen = value.length();
|
||||||
if (value.endsWith("=="))
|
if (value.endsWith("=="))
|
||||||
len -=2;
|
strlen-=2;
|
||||||
else if(value.endsWith("="))
|
else if (value.endsWith("="))
|
||||||
len --;
|
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];
|
byte ret[] = new byte[len];
|
||||||
int pos=0;
|
int pos=0;
|
||||||
for (int i=0;i<value.length();i++){
|
for (int i=0;i<strlen;i++){
|
||||||
if (value.charAt(i)=='=')
|
if (value.charAt(i)=='=')
|
||||||
break;
|
break;
|
||||||
int val = charSet.indexOf(value.charAt(i));
|
int val = charSet.indexOf(value.charAt(i));
|
||||||
|
@ -398,6 +398,26 @@ static int overlay_interface_init_any(int port)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
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
|
static int
|
||||||
overlay_interface_init_socket(overlay_interface *interface)
|
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;
|
dest->ifconfig.tick_ms=0;
|
||||||
}else if (!dest->ifconfig.send){
|
}else if (!dest->ifconfig.send){
|
||||||
INFOF("Destination is not sending any traffic!");
|
INFOF("Destination is not sending any traffic!");
|
||||||
|
dest->ifconfig.tick_ms=0;
|
||||||
}else if (dest->ifconfig.tick_ms==0)
|
}else if (dest->ifconfig.tick_ms==0)
|
||||||
INFOF("Destination is running tickless");
|
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)
|
if (dest->ifconfig.reachable_timeout_ms<0)
|
||||||
dest->ifconfig.reachable_timeout_ms = tick_ms>0 ? tick_ms * 5 : 2500;
|
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);
|
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)
|
if (ifconfig->socket_type==SOCK_STREAM)
|
||||||
interface->ifconfig.unicast.send=0;
|
interface->ifconfig.unicast.send=0;
|
||||||
|
|
||||||
|
// schedule the first tick asap
|
||||||
|
unschedule(&interface->alarm);
|
||||||
|
calc_next_tick(interface);
|
||||||
|
schedule(&interface->alarm);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,9 +558,6 @@ overlay_interface_init(const char *name, struct socket_address *addr,
|
|||||||
set_destination_ref(&interface->destination, NULL);
|
set_destination_ref(&interface->destination, NULL);
|
||||||
interface->destination = new_destination(interface);
|
interface->destination = new_destination(interface);
|
||||||
|
|
||||||
if (overlay_interface_configure(interface, ifconfig)==-1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
interface->alarm.poll.fd=0;
|
interface->alarm.poll.fd=0;
|
||||||
interface->tx_count=0;
|
interface->tx_count=0;
|
||||||
interface->recv_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_poll_stats.name="overlay_interface_poll";
|
||||||
interface->alarm.stats=&interface_poll_stats;
|
interface->alarm.stats=&interface_poll_stats;
|
||||||
|
|
||||||
|
if (overlay_interface_configure(interface, ifconfig)==-1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
switch(ifconfig->socket_type){
|
switch(ifconfig->socket_type){
|
||||||
case SOCK_DGRAM:
|
case SOCK_DGRAM:
|
||||||
if (ifconfig->broadcast.drop || ifconfig->unicast.drop || ifconfig->drop_packets)
|
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;
|
interface->state=INTERFACE_STATE_UP;
|
||||||
monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:UP\n", interface->name);
|
monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%s:UP\n", interface->name);
|
||||||
INFOF("Interface %s addr %s, is up",interface->name, alloca_socket_address(addr));
|
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)
|
if (now >= interface->destination->last_tx+interface->destination->ifconfig.tick_ms)
|
||||||
overlay_send_tick_packet(interface->destination);
|
overlay_send_tick_packet(interface->destination);
|
||||||
|
|
||||||
time_ms_t interval = interface->destination->ifconfig.tick_ms;
|
calc_next_tick(interface);
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(interface->ifconfig.socket_type){
|
switch(interface->ifconfig.socket_type){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user