mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-21 20:08:21 +00:00
Use new typedef time_ms_t everywhere
This commit is contained in:
parent
e3bef80965
commit
12d8bc0c12
3
codecs.c
3
codecs.c
@ -41,8 +41,7 @@ int encodeAndDispatchRecordedAudio(int fd,int callSessionToken,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bufferAudioForPlayback(int codec,long long start_time,long long end_time,
|
||||
unsigned char *data,int dataLen)
|
||||
int bufferAudioForPlayback(int codec, time_ms_t start_time, time_ms_t end_time, unsigned char *data,int dataLen)
|
||||
{
|
||||
/* XXX We need to buffer and reorder out-of-order sample blocks and
|
||||
decode codecs etc here. */
|
||||
|
@ -443,12 +443,11 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
|
||||
|
||||
/* Now repeatedly send resolution request and collect results until we reach
|
||||
timeout. */
|
||||
unsigned long long timeout=gettime_ms()+3000;
|
||||
unsigned long long last_tx=0;
|
||||
|
||||
while(timeout>gettime_ms())
|
||||
time_ms_t timeout = gettime_ms() + 3000;
|
||||
time_ms_t last_tx = 0;
|
||||
time_ms_t now;
|
||||
while (timeout > (now = gettime_ms()))
|
||||
{
|
||||
unsigned long long now=gettime_ms();
|
||||
if ((last_tx+125)<now)
|
||||
{
|
||||
mdp.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT;
|
||||
@ -468,7 +467,7 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
|
||||
overlay_mdp_send(&mdp,0,0);
|
||||
last_tx=now;
|
||||
}
|
||||
long long short_timeout=125;
|
||||
time_ms_t short_timeout=125;
|
||||
while(short_timeout>0) {
|
||||
if (overlay_mdp_client_poll(short_timeout))
|
||||
{
|
||||
@ -647,7 +646,7 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti
|
||||
}
|
||||
}
|
||||
/* Main process. Allow a few seconds for the child process to report for duty. */
|
||||
long long timeout = gettime_ms() + 5000;
|
||||
time_ms_t timeout = gettime_ms() + 5000;
|
||||
do {
|
||||
struct timespec delay;
|
||||
delay.tv_sec = 0;
|
||||
@ -676,7 +675,7 @@ int app_server_stop(int argc, const char *const *argv, struct command_line_optio
|
||||
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
||||
int pid, tries, running;
|
||||
const char *instancepath;
|
||||
long long timeout;
|
||||
time_ms_t timeout;
|
||||
struct timespec delay;
|
||||
|
||||
if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1)
|
||||
@ -808,11 +807,11 @@ int app_mdp_ping(int argc, const char *const *argv, struct command_line_option *
|
||||
/* XXX Eventually we should try to resolve SID to phone number and vice versa */
|
||||
printf("MDP PING %s (%s): 12 data bytes\n", alloca_tohex_sid(ping_sid), alloca_tohex_sid(ping_sid));
|
||||
|
||||
long long rx_mintime=-1;
|
||||
long long rx_maxtime=-1;
|
||||
time_ms_t rx_mintime=-1;
|
||||
time_ms_t rx_maxtime=-1;
|
||||
time_ms_t rx_ms=0;
|
||||
time_ms_t rx_times[1024];
|
||||
long long rx_count=0,tx_count=0;
|
||||
long long rx_ms=0;
|
||||
long long rx_times[1024];
|
||||
|
||||
if (broadcast)
|
||||
WHY("WARNING: broadcast ping packets will not be encryped.");
|
||||
@ -840,11 +839,11 @@ int app_mdp_ping(int argc, const char *const *argv, struct command_line_option *
|
||||
|
||||
/* Now look for replies until one second has passed, and print any replies
|
||||
with appropriate information as required */
|
||||
long long now=gettime_ms();
|
||||
long long timeout=now+1000;
|
||||
time_ms_t now = gettime_ms();
|
||||
time_ms_t timeout = now + 1000;
|
||||
|
||||
while(now<timeout) {
|
||||
long long timeout_ms=timeout-gettime_ms();
|
||||
time_ms_t timeout_ms = timeout - gettime_ms();
|
||||
int result = overlay_mdp_client_poll(timeout_ms);
|
||||
|
||||
if (result>0) {
|
||||
@ -858,7 +857,7 @@ int app_mdp_ping(int argc, const char *const *argv, struct command_line_option *
|
||||
{
|
||||
int *rxseq=(int *)&mdp.in.payload;
|
||||
long long *txtime=(long long *)&mdp.in.payload[4];
|
||||
long long delay=gettime_ms()-*txtime;
|
||||
time_ms_t delay = gettime_ms() - *txtime;
|
||||
printf("%s: seq=%d time=%lld ms%s%s\n",
|
||||
alloca_tohex_sid(mdp.in.src.sid),(*rxseq)-firstSeq+1,delay,
|
||||
mdp.packetTypeAndFlags&MDP_NOCRYPT?"":" ENCRYPTED",
|
||||
@ -1042,7 +1041,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_
|
||||
if (debug & DEBUG_RHIZOME) DEBUGF("manifest contains service=%s", service);
|
||||
}
|
||||
if (rhizome_manifest_get(m, "date", NULL, 0) == NULL) {
|
||||
rhizome_manifest_set_ll(m, "date", gettime_ms());
|
||||
rhizome_manifest_set_ll(m, "date", (long long) gettime_ms());
|
||||
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'date', set default date=%s", rhizome_manifest_get(m, "date", NULL, 0));
|
||||
}
|
||||
if (strcasecmp(RHIZOME_SERVICE_FILE, service) == 0) {
|
||||
@ -1545,18 +1544,16 @@ int app_crypt_test(int argc, const char *const *argv, struct command_line_option
|
||||
|
||||
int len,i;
|
||||
|
||||
gettime_ms();
|
||||
|
||||
for(len=16;len<=65536;len*=2) {
|
||||
unsigned long long start=gettime_ms();
|
||||
time_ms_t start = gettime_ms();
|
||||
for (i=0;i<1000;i++) {
|
||||
bzero(&plain_block[0],crypto_box_curve25519xsalsa20poly1305_ZEROBYTES);
|
||||
crypto_box_curve25519xsalsa20poly1305_afternm
|
||||
(plain_block,plain_block,len,nonce,k);
|
||||
}
|
||||
unsigned long long end=gettime_ms();
|
||||
time_ms_t end = gettime_ms();
|
||||
printf("%d bytes - 100 tests took %lldms - mean time = %.2fms\n",
|
||||
len,end-start,(end-start)*1.0/i);
|
||||
len, (long long) end - start, (end - start) * 1.0 / i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1612,9 +1609,9 @@ int app_node_info(int argc, const char *const *argv, struct command_line_option
|
||||
if (overlay_mdp_bind(srcsid,port)) port=0;
|
||||
|
||||
if (port) {
|
||||
unsigned long long now = gettime_ms();
|
||||
unsigned long long timeout = now+3000;
|
||||
unsigned long long next_send = now;
|
||||
time_ms_t now = gettime_ms();
|
||||
time_ms_t timeout = now + 3000;
|
||||
time_ms_t next_send = now;
|
||||
|
||||
while(now < timeout){
|
||||
now=gettime_ms();
|
||||
@ -1633,7 +1630,7 @@ int app_node_info(int argc, const char *const *argv, struct command_line_option
|
||||
continue;
|
||||
}
|
||||
|
||||
long long timeout_ms = (next_send>timeout?timeout:next_send) - now;
|
||||
time_ms_t timeout_ms = (next_send>timeout?timeout:next_send) - now;
|
||||
if (overlay_mdp_client_poll(timeout_ms)<=0)
|
||||
continue;
|
||||
|
||||
|
@ -32,7 +32,7 @@ struct profile_total poll_stats={NULL,0,"Idle (in poll)",0,0,0};
|
||||
|
||||
void list_alarms() {
|
||||
DEBUG("Alarms;");
|
||||
long long now = gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
struct sched_ent *alarm;
|
||||
for (alarm = next_alarm; alarm; alarm = alarm->_next)
|
||||
DEBUGF("%s in %lldms", (alarm->stats ? alarm->stats->name : "Unnamed"), alarm->alarm - now);
|
||||
@ -184,7 +184,7 @@ int fd_poll()
|
||||
{
|
||||
int i, r;
|
||||
int ms=60000;
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
|
||||
/* move alarms that have elapsed to the deadline queue */
|
||||
while (next_alarm!=NULL&&next_alarm->alarm <=now){
|
||||
|
13
keyring.c
13
keyring.c
@ -1145,7 +1145,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
||||
struct sid_sas_mapping {
|
||||
unsigned char sid[SID_SIZE];
|
||||
unsigned char sas_public[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES];
|
||||
unsigned long long last_request_time_in_ms;
|
||||
time_ms_t last_request_time_in_ms;
|
||||
unsigned char validP;
|
||||
};
|
||||
|
||||
@ -1263,7 +1263,7 @@ int keyring_mapping_request(keyring_file *k,overlay_mdp_frame *req)
|
||||
alloca_tohex_sid(sid_sas_mappings[i].sid),
|
||||
alloca_tohex_sid(sid_sas_mappings[i].sas_public));
|
||||
sid_sas_mappings[i].validP=1;
|
||||
sid_sas_mappings[i].last_request_time_in_ms=0;
|
||||
sid_sas_mappings[i].last_request_time_in_ms = -1;
|
||||
if (debug & DEBUG_KEYRING)
|
||||
DEBUG("Stored mapping");
|
||||
return 0;
|
||||
@ -1292,7 +1292,7 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
|
||||
*/
|
||||
IN();
|
||||
int i;
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
for(i=0;i<sid_sas_mapping_count;i++)
|
||||
{
|
||||
if (memcmp(sid,sid_sas_mappings[i].sid,SID_SIZE)) continue;
|
||||
@ -1302,9 +1302,8 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
|
||||
RETURN(sid_sas_mappings[i].sas_public);
|
||||
}
|
||||
/* Don't flood the network with mapping requests */
|
||||
if (((now-sid_sas_mappings[i].last_request_time_in_ms)<1000)
|
||||
&&((now-sid_sas_mappings[i].last_request_time_in_ms)>=0))
|
||||
{ RETURN(WHYNULL("Too soon to ask for SAS mapping again.")); }
|
||||
if (sid_sas_mappings[i].last_request_time_in_ms != -1 && now < sid_sas_mappings[i].last_request_time_in_ms + 1000)
|
||||
RETURN(WHYNULL("Too soon to ask for SAS mapping again."));
|
||||
/* we can request again, so fall out to where we do that.
|
||||
i is set to this mapping, so the request process will update this
|
||||
record. */
|
||||
@ -1325,7 +1324,7 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
|
||||
bzero(&sid_sas_mappings[i].sas_public,
|
||||
crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES);
|
||||
sid_sas_mappings[i].validP=0;
|
||||
sid_sas_mappings[i].last_request_time_in_ms=now;
|
||||
sid_sas_mappings[i].last_request_time_in_ms = now;
|
||||
|
||||
/* request mapping (send request auth-crypted). */
|
||||
overlay_mdp_frame mdp;
|
||||
|
@ -195,7 +195,7 @@ int callState=0;
|
||||
int processLine(char *cmd,unsigned char *data,int dataLen)
|
||||
{
|
||||
int l_id,r_id,l_state,r_state,codec;
|
||||
long long start_time,end_time;
|
||||
time_ms_t start_time, end_time;
|
||||
if (showReceived) {
|
||||
printf("> %s\n",cmd);
|
||||
if (data) {
|
||||
@ -215,11 +215,10 @@ int processLine(char *cmd,unsigned char *data,int dataLen)
|
||||
}
|
||||
}
|
||||
if (sscanf(cmd,"AUDIOPACKET:%x:%x:%d:%d:%d:%lld:%lld",
|
||||
&l_id,&r_id,&l_state,&r_state,
|
||||
&codec,&start_time,&end_time)==7)
|
||||
&l_id,&r_id,&l_state,&r_state, &codec, &start_time, &end_time)==7)
|
||||
{
|
||||
if (pipeAudio&&audev&&fast_audio) {
|
||||
bufferAudioForPlayback(codec,start_time,end_time,data,dataLen);
|
||||
bufferAudioForPlayback(codec, start_time, end_time, data, dataLen);
|
||||
}
|
||||
}
|
||||
char msg[1024];
|
||||
|
@ -182,7 +182,7 @@ int overlay_frame_process(struct overlay_interface *interface,overlay_frame *f)
|
||||
IN();
|
||||
if (!f) RETURN(WHY("f==NULL"));
|
||||
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
|
||||
if (debug&DEBUG_OVERLAYFRAMES)
|
||||
DEBUGF(">>> Received frame (type=%02x, bytes=%d)",f->type,f->payload?f->payload->length:-1);
|
||||
|
@ -54,7 +54,7 @@ struct outgoing_packet{
|
||||
struct sched_ent next_packet;
|
||||
struct profile_total send_packet;
|
||||
|
||||
int overlay_tick_interface(int i, long long now);
|
||||
int overlay_tick_interface(int i, time_ms_t now);
|
||||
|
||||
unsigned char magic_header[]={/* Magic */ 'O',0x10,
|
||||
/* Version */ 0x00,0x01};
|
||||
@ -359,7 +359,7 @@ void overlay_interface_poll(struct sched_ent *alarm)
|
||||
|
||||
if (interface->state==INTERFACE_STATE_UP){
|
||||
// tick the interface
|
||||
unsigned long long now = gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
int i = (interface - overlay_interfaces);
|
||||
overlay_tick_interface(i, now);
|
||||
alarm->alarm=now+interface->tick_ms;
|
||||
@ -403,7 +403,7 @@ void overlay_dummy_poll(struct sched_ent *alarm)
|
||||
struct sockaddr src_addr;
|
||||
size_t addrlen = sizeof(src_addr);
|
||||
unsigned char transaction_id[8];
|
||||
unsigned long long now = gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
|
||||
if (interface->last_tick_ms == -1 || now >= interface->last_tick_ms + interface->tick_ms) {
|
||||
// tick the interface
|
||||
@ -793,7 +793,7 @@ void overlay_init_packet(struct outgoing_packet *packet, int interface){
|
||||
// update the alarm time and return 1 if changed
|
||||
int overlay_calc_queue_time(overlay_txqueue *queue, overlay_frame *frame){
|
||||
int ret=0;
|
||||
long long int send_time;
|
||||
time_ms_t send_time;
|
||||
|
||||
if (frame->nexthop_address_status==OA_UNINITIALISED)
|
||||
overlay_resolve_next_hop(frame);
|
||||
@ -821,7 +821,7 @@ int overlay_calc_queue_time(overlay_txqueue *queue, overlay_frame *frame){
|
||||
return ret;
|
||||
}
|
||||
|
||||
void overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, long long now){
|
||||
void overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, time_ms_t now){
|
||||
overlay_frame *frame = queue->first;
|
||||
|
||||
// TODO stop when the packet is nearly full?
|
||||
@ -913,7 +913,7 @@ void overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue
|
||||
}
|
||||
|
||||
// fill a packet from our outgoing queues and send it
|
||||
int overlay_fill_send_packet(struct outgoing_packet *packet, long long now){
|
||||
int overlay_fill_send_packet(struct outgoing_packet *packet, time_ms_t now){
|
||||
int i;
|
||||
IN();
|
||||
// while we're looking at queues, work out when to schedule another packet
|
||||
@ -964,7 +964,7 @@ void overlay_update_queue_schedule(overlay_txqueue *queue, overlay_frame *frame)
|
||||
}
|
||||
}
|
||||
|
||||
int overlay_tick_interface(int i, long long now)
|
||||
int overlay_tick_interface(int i, time_ms_t now)
|
||||
{
|
||||
struct outgoing_packet packet;
|
||||
IN();
|
||||
|
@ -111,7 +111,7 @@ int mdp_bindings_initialised=0;
|
||||
sockaddr_mdp mdp_bindings[MDP_MAX_BINDINGS];
|
||||
char mdp_bindings_sockets[MDP_MAX_BINDINGS][MDP_MAX_SOCKET_NAME_LEN];
|
||||
int mdp_bindings_socket_name_lengths[MDP_MAX_BINDINGS];
|
||||
unsigned long long mdp_bindings_time[MDP_MAX_BINDINGS];
|
||||
time_ms_t mdp_bindings_time[MDP_MAX_BINDINGS];
|
||||
|
||||
int overlay_mdp_reply_error(int sock,
|
||||
struct sockaddr_un *recvaddr,int recvaddrlen,
|
||||
@ -352,7 +352,7 @@ unsigned char *overlay_mdp_decrypt(overlay_frame *f,overlay_mdp_frame *mdp,
|
||||
RETURN(b);
|
||||
}
|
||||
|
||||
int overlay_saw_mdp_containing_frame(overlay_frame *f,long long now)
|
||||
int overlay_saw_mdp_containing_frame(overlay_frame *f, time_ms_t now)
|
||||
{
|
||||
IN();
|
||||
/* Take frame source and destination and use them to populate mdp->in->{src,dst}
|
||||
@ -400,7 +400,7 @@ int overlay_mdp_swap_src_dst(overlay_mdp_frame *mdp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_saw_mdp_frame(overlay_mdp_frame *mdp,long long now)
|
||||
int overlay_saw_mdp_frame(overlay_mdp_frame *mdp, time_ms_t now)
|
||||
{
|
||||
IN();
|
||||
int i;
|
||||
@ -1244,7 +1244,7 @@ int overlay_mdp_client_done()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_mdp_client_poll(long long timeout_ms)
|
||||
int overlay_mdp_client_poll(time_ms_t timeout_ms)
|
||||
{
|
||||
fd_set r;
|
||||
int ret;
|
||||
|
@ -279,7 +279,7 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
*/
|
||||
|
||||
unsigned char *sid=overlay_get_my_sid();
|
||||
long long now = gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
|
||||
/* Header byte */
|
||||
if (ob_append_byte(b, OF_TYPE_SELFANNOUNCE))
|
||||
@ -345,7 +345,7 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
overlay_abbreviate_set_current_sender(sid);
|
||||
|
||||
/* Sequence number range. Based on one tick per millisecond. */
|
||||
long long last_ms = overlay_interfaces[interface].last_tick_ms;
|
||||
time_ms_t 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)
|
||||
@ -356,8 +356,10 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
return WHY("Could not add high sequence number to self-announcement");
|
||||
if (debug&DEBUG_OVERLAYINTERFACES)
|
||||
DEBUGF("interface #%d: last_tick_ms=%lld, now=%lld (delta=%lld)",
|
||||
interface, overlay_interfaces[interface].last_tick_ms, now,
|
||||
now - last_ms
|
||||
interface,
|
||||
(long long)overlay_interfaces[interface].last_tick_ms,
|
||||
(long long)now,
|
||||
(long long)(now - last_ms)
|
||||
);
|
||||
overlay_interfaces[interface].last_tick_ms = now;
|
||||
|
||||
@ -369,5 +371,3 @@ int overlay_add_selfannouncement(int interface,overlay_buffer *b)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -396,7 +396,7 @@ int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *interface)
|
||||
return -1;
|
||||
}
|
||||
|
||||
long long now = gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
overlay_neighbour *direct_neighbour=NULL;
|
||||
|
||||
if (n->neighbour_id) {
|
||||
@ -527,7 +527,7 @@ overlay_node *overlay_route_find_node(const unsigned char *sid, int prefixLen, i
|
||||
overlay_nodes[bin_number][free_slot].best_link_score=0;
|
||||
overlay_nodes[bin_number][free_slot].best_observation=0;
|
||||
for(i=0;i<OVERLAY_MAX_INTERFACES;i++) {
|
||||
overlay_nodes[bin_number][free_slot].most_recent_advertisment[i]=0;
|
||||
overlay_nodes[bin_number][free_slot].most_recent_advertisment_ms[i]=0;
|
||||
overlay_nodes[bin_number][free_slot].most_recent_advertised_score[i]=0;
|
||||
}
|
||||
}
|
||||
@ -730,7 +730,7 @@ overlay_neighbour *overlay_route_get_neighbour_structure(unsigned char *packed_s
|
||||
|
||||
int overlay_route_i_can_hear_node(unsigned char *who,int sender_interface,
|
||||
unsigned int s1,unsigned int s2,
|
||||
long long now)
|
||||
time_ms_t now)
|
||||
{
|
||||
if (0) DEBUGF("I can hear node %s (but I really only care who can hear me)",
|
||||
alloca_tohex_sid(who));
|
||||
@ -740,7 +740,7 @@ int overlay_route_i_can_hear_node(unsigned char *who,int sender_interface,
|
||||
|
||||
int overlay_route_node_can_hear_me(unsigned char *who,int sender_interface,
|
||||
unsigned int s1,unsigned int s2,
|
||||
long long now)
|
||||
time_ms_t now)
|
||||
{
|
||||
/* 1. Find (or create) node entry for the node.
|
||||
2. Replace oldest observation with this observation.
|
||||
@ -776,7 +776,7 @@ int overlay_route_node_can_hear_me(unsigned char *who,int sender_interface,
|
||||
}
|
||||
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUGF("assign observation slot #%d: s1=%u s2=%u time_ms=%lld", obs_index, s1, s2, now);
|
||||
DEBUGF("assign observation slot #%d: s1=%u s2=%u time_ms=%lld", obs_index, s1, s2, (long long)now);
|
||||
neh->observations[obs_index].s1=s1;
|
||||
neh->observations[obs_index].s2=s2;
|
||||
neh->observations[obs_index].sender_interface=sender_interface;
|
||||
@ -796,7 +796,7 @@ int overlay_route_node_can_hear_me(unsigned char *who,int sender_interface,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_route_saw_selfannounce(overlay_frame *f,long long now)
|
||||
int overlay_route_saw_selfannounce(overlay_frame *f, time_ms_t now)
|
||||
{
|
||||
IN();
|
||||
unsigned int s1,s2;
|
||||
@ -826,7 +826,7 @@ int overlay_route_saw_selfannounce(overlay_frame *f,long long now)
|
||||
}
|
||||
|
||||
/* XXX Think about scheduling this node's score for readvertising? */
|
||||
int overlay_route_recalc_node_metrics(overlay_node *n,long long now)
|
||||
int overlay_route_recalc_node_metrics(overlay_node *n, time_ms_t now)
|
||||
{
|
||||
int o;
|
||||
int best_score=0;
|
||||
@ -911,10 +911,10 @@ int overlay_route_recalc_node_metrics(overlay_node *n,long long now)
|
||||
200 seconds perhaps?). Also, if no recent observations, then we further
|
||||
limit the score.
|
||||
*/
|
||||
int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
||||
int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n, time_ms_t now)
|
||||
{
|
||||
int i;
|
||||
long long most_recent_observation=0;
|
||||
time_ms_t most_recent_observation=0;
|
||||
|
||||
if (!n->node)
|
||||
return 0;
|
||||
@ -927,14 +927,14 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUG("last update was never");
|
||||
} else {
|
||||
long long ago = now - n->last_metric_update;
|
||||
time_ms_t ago = now - n->last_metric_update;
|
||||
if (ago < 500) {
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUGF("last update was %lldms ago -- skipping", ago);
|
||||
DEBUGF("last update was %lldms ago -- skipping", (long long)ago);
|
||||
return 0;
|
||||
}
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUGF("last update was %lldms ago", ago);
|
||||
DEBUGF("last update was %lldms ago", (long long)ago);
|
||||
}
|
||||
n->last_metric_update = now;
|
||||
|
||||
@ -964,7 +964,7 @@ 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 */
|
||||
long long obs_age = now - n->observations[i].time_ms;
|
||||
time_ms_t obs_age = now - n->observations[i].time_ms;
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUGF("tallying obs: %lldms old, %ums long", obs_age,interval);
|
||||
|
||||
@ -1079,7 +1079,7 @@ int overlay_route_saw_selfannounce_ack(overlay_frame *f,long long now)
|
||||
|
||||
/* if to and via are the same, then this is evidence that we can get to the
|
||||
node directly. */
|
||||
int overlay_route_record_link(long long now,unsigned char *to,
|
||||
int overlay_route_record_link(time_ms_t now, unsigned char *to,
|
||||
unsigned char *via,int sender_interface,
|
||||
unsigned int s1,unsigned int s2,int score,
|
||||
int gateways_en_route)
|
||||
@ -1169,7 +1169,7 @@ int overlay_address_is_local(unsigned char *s)
|
||||
int overlay_route_dump()
|
||||
{
|
||||
int bin,slot,o,n,i;
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
strbuf b = strbuf_alloca(8192);
|
||||
|
||||
strbuf_sprintf(b,"Overlay Local Identities\n------------------------\n");
|
||||
@ -1194,7 +1194,7 @@ int overlay_route_dump()
|
||||
{
|
||||
strbuf_sprintf(b," %s* : %lldms ago :",
|
||||
alloca_tohex(overlay_neighbours[n].node->sid, 7),
|
||||
now - overlay_neighbours[n].last_observation_time_ms);
|
||||
(long long)(now - overlay_neighbours[n].last_observation_time_ms));
|
||||
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
|
||||
if (overlay_neighbours[n].scores[i])
|
||||
strbuf_sprintf(b," %d(via #%d)",
|
||||
@ -1248,7 +1248,7 @@ void overlay_route_tick(struct sched_ent *alarm)
|
||||
{
|
||||
int n;
|
||||
|
||||
long long start_time=gettime_ms();
|
||||
time_ms_t start_time = gettime_ms();
|
||||
|
||||
if (debug&DEBUG_OVERLAYROUTING)
|
||||
DEBUGF("Neighbours: %d@%d, Nodes: %d@%d",
|
||||
@ -1269,7 +1269,7 @@ void overlay_route_tick(struct sched_ent *alarm)
|
||||
|
||||
/* Tweak neighbour bundle size to spread it out over the required time.
|
||||
XXX Does this behave correctly when there are no neighbours? */
|
||||
long long neighbour_time=gettime_ms()-start_time;
|
||||
time_ms_t neighbour_time = gettime_ms() - start_time;
|
||||
if (neighbour_time>2) overlay_route_tick_neighbour_bundle_size/=neighbour_time;
|
||||
else if (neighbour_time==0) overlay_route_tick_neighbour_bundle_size*=2;
|
||||
if (overlay_route_tick_neighbour_bundle_size<1) overlay_route_tick_neighbour_bundle_size=1;
|
||||
@ -1292,7 +1292,7 @@ void overlay_route_tick(struct sched_ent *alarm)
|
||||
/* Tweak neighbour bundle size to spread it out over the required time.
|
||||
Allow 2ms here instead of 1ms, as neighbour processing may have taken the
|
||||
bulk of the tick. */
|
||||
long long node_time=gettime_ms()-neighbour_time-start_time;
|
||||
time_ms_t node_time = gettime_ms() - neighbour_time - start_time;
|
||||
if (node_time>1) overlay_route_tick_node_bundle_size/=node_time;
|
||||
else if (node_time==0) overlay_route_tick_node_bundle_size*=2;
|
||||
if (overlay_route_tick_node_bundle_size<1) overlay_route_tick_node_bundle_size=1;
|
||||
@ -1325,7 +1325,7 @@ void overlay_route_tick(struct sched_ent *alarm)
|
||||
/* Ticking neighbours is easy; we just pretend we have heard from them again,
|
||||
and recalculate the score that way, which already includes a mechanism for
|
||||
taking into account the age of the most recent observation */
|
||||
int overlay_route_tick_neighbour(int neighbour_id,long long now)
|
||||
int overlay_route_tick_neighbour(int neighbour_id, time_ms_t now)
|
||||
{
|
||||
if (neighbour_id>0)
|
||||
if (overlay_route_recalc_neighbour_metrics(&overlay_neighbours[neighbour_id],now))
|
||||
@ -1344,7 +1344,7 @@ int overlay_route_tick_neighbour(int neighbour_id,long long now)
|
||||
most part we can tolerate these without any special action, as their high
|
||||
scores will keep them reachable for longer anyway.
|
||||
*/
|
||||
int overlay_route_tick_node(int bin,int slot,long long now)
|
||||
int overlay_route_tick_node(int bin,int slot, time_ms_t now)
|
||||
{
|
||||
return overlay_route_recalc_node_metrics(&overlay_nodes[bin][slot],now);
|
||||
}
|
||||
@ -1353,7 +1353,7 @@ int overlay_route_node_info(overlay_mdp_frame *mdp,
|
||||
struct sockaddr_un *addr,int addrlen)
|
||||
{
|
||||
int bin,slot,n;
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
|
||||
if (0)
|
||||
DEBUGF("Looking for node %s* (prefix len=0x%x)",
|
||||
@ -1381,7 +1381,7 @@ int overlay_route_node_info(overlay_mdp_frame *mdp,
|
||||
mdp->nodeinfo.foundP=1;
|
||||
mdp->nodeinfo.localP=1;
|
||||
mdp->nodeinfo.neighbourP=0;
|
||||
mdp->nodeinfo.time_since_last_observation=0;
|
||||
mdp->nodeinfo.time_since_last_observation = 0;
|
||||
mdp->nodeinfo.score=256;
|
||||
mdp->nodeinfo.interface_number=-1;
|
||||
bcopy(&keyring->contexts[cn]->identities[in]
|
||||
@ -1430,9 +1430,7 @@ int overlay_route_node_info(overlay_mdp_frame *mdp,
|
||||
mdp->nodeinfo.foundP=1;
|
||||
mdp->nodeinfo.localP=0;
|
||||
mdp->nodeinfo.neighbourP=1;
|
||||
mdp->nodeinfo.time_since_last_observation
|
||||
=gettime_ms()
|
||||
-overlay_neighbours[n].last_observation_time_ms;
|
||||
mdp->nodeinfo.time_since_last_observation = gettime_ms() - overlay_neighbours[n].last_observation_time_ms;
|
||||
mdp->nodeinfo.score=-1;
|
||||
mdp->nodeinfo.interface_number=-1;
|
||||
mdp->nodeinfo.resolve_did=0;
|
||||
@ -1466,7 +1464,7 @@ int overlay_route_node_info(overlay_mdp_frame *mdp,
|
||||
mdp->nodeinfo.foundP=1;
|
||||
mdp->nodeinfo.localP=0;
|
||||
mdp->nodeinfo.neighbourP=0;
|
||||
mdp->nodeinfo.time_since_last_observation=gettime_ms();
|
||||
mdp->nodeinfo.time_since_last_observation = gettime_ms();
|
||||
mdp->nodeinfo.score=-1;
|
||||
mdp->nodeinfo.interface_number=-1;
|
||||
mdp->nodeinfo.resolve_did=0;
|
||||
@ -1479,9 +1477,8 @@ int overlay_route_node_info(overlay_mdp_frame *mdp,
|
||||
if (ob->corrected_score>mdp->nodeinfo.score) {
|
||||
mdp->nodeinfo.score=ob->corrected_score;
|
||||
}
|
||||
if ((now-ob->rx_time)
|
||||
<mdp->nodeinfo.time_since_last_observation)
|
||||
mdp->nodeinfo.time_since_last_observation=now-ob->rx_time;
|
||||
if (now - ob->rx_time < mdp->nodeinfo.time_since_last_observation)
|
||||
mdp->nodeinfo.time_since_last_observation = now - ob->rx_time;
|
||||
}
|
||||
|
||||
bcopy(&overlay_nodes[bin][slot].sid[0],
|
||||
|
@ -40,10 +40,10 @@ int fd_tallystats(struct profile_total *total,struct profile_total *a)
|
||||
int fd_showstat(struct profile_total *total, struct profile_total *a)
|
||||
{
|
||||
INFOF("%lldms (%2.1f%%) in %d calls (max %lldms, avg %.1fms, +child avg %.1fms) : %s",
|
||||
a->total_time,
|
||||
(long long) a->total_time,
|
||||
a->total_time*100.0/total->total_time,
|
||||
a->calls,
|
||||
a->max_time,
|
||||
(long long) a->max_time,
|
||||
a->total_time*1.00/a->calls,
|
||||
(a->total_time+a->child_time)*1.00/a->calls,
|
||||
a->name);
|
||||
@ -194,8 +194,8 @@ int fd_func_exit(struct call_stats *this_call)
|
||||
if (current_call != this_call)
|
||||
WHYF("stack mismatch, exited through %s()",this_call->totals->name);
|
||||
|
||||
long long now = gettime_ms();
|
||||
long long elapsed=now - this_call->enter_time;
|
||||
time_ms_t now = gettime_ms();
|
||||
time_ms_t elapsed = now - this_call->enter_time;
|
||||
current_call = this_call->prev;
|
||||
|
||||
if (this_call->totals && !this_call->totals->_initialised){
|
||||
@ -220,4 +220,3 @@ int fd_func_exit(struct call_stats *this_call)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -386,13 +386,14 @@ int rhizome_bundle_push_update(char *id,long long version,unsigned char *data,in
|
||||
/* When voice traffic is being carried, we need to throttle Rhizome down
|
||||
to a more sensible level. Or possibly even supress it entirely.
|
||||
*/
|
||||
long long rhizome_voice_timeout=0;
|
||||
time_ms_t rhizome_voice_timeout = -1;
|
||||
int rhizome_saw_voice_traffic()
|
||||
{
|
||||
/* We are in "voice mode" for a second after sending a voice frame */
|
||||
if (rhizome_voice_timeout<gettime_ms()) {
|
||||
WHY("Suppressing Rhizome due to voice traffic");
|
||||
rhizome_voice_timeout=gettime_ms()+1000;
|
||||
time_ms_t now = gettime_ms();
|
||||
if (rhizome_voice_timeout < now) {
|
||||
INFO("Suppressing Rhizome due to voice traffic");
|
||||
rhizome_voice_timeout = now + 1000;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define RHIZOME_HTTP_PORT 4110
|
||||
#define RHIZOME_HTTP_PORT_MAX 4150
|
||||
|
||||
extern long long rhizome_voice_timeout;
|
||||
extern time_ms_t rhizome_voice_timeout;
|
||||
|
||||
#define RHIZOME_PRIORITY_HIGHEST RHIZOME_PRIORITY_SERVAL_CORE
|
||||
#define RHIZOME_PRIORITY_SERVAL_CORE 5
|
||||
|
@ -567,7 +567,7 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 1, manifestid, -1, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_blob(stmt, 2, m->manifestdata, m->manifest_bytes, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 3, m->version);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 4, gettime_ms());
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 4, (long long) gettime_ms());
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_blob(stmt, 5, bar, RHIZOME_BAR_BYTES, SQLITE_TRANSIENT);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 6, m->fileLength);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_text(stmt, 7, filehash, -1, SQLITE_TRANSIENT);
|
||||
@ -577,7 +577,7 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
// we might need to leave the old file around for a bit
|
||||
// clean out unreferenced files first
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_prepare_v2_retry(rhizome_db, "DELETE FROM FILES WHERE inserttime < ? AND NOT EXISTS( SELECT 1 FROM MANIFESTS WHERE MANIFESTS.filehash = FILES.id);", -1, &stmt, NULL);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 1, gettime_ms() - 60000);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_bind_int64(stmt, 1, (long long)(gettime_ms() - 60000));
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_step_retry(stmt);
|
||||
if (SQLITE_CODE_OK(sql_ret)) sql_ret = sqlite3_finalize(stmt);
|
||||
|
||||
@ -827,7 +827,7 @@ int rhizome_store_file(rhizome_manifest *m,const unsigned char *key)
|
||||
sqlite3_exec(rhizome_db,"DELETE FROM FILES WHERE datavalid=0;",NULL,NULL,NULL);
|
||||
|
||||
snprintf(sqlcmd,1024,"INSERT OR REPLACE INTO FILES(id,data,length,highestpriority,datavalid,inserttime) VALUES('%s',?,%lld,%d,0,%lld);",
|
||||
hash,(long long)m->fileLength,priority,gettime_ms());
|
||||
hash,(long long)m->fileLength,priority,(long long)gettime_ms());
|
||||
sqlite3_stmt *statement;
|
||||
if (sqlite3_prepare_v2(rhizome_db,sqlcmd,strlen(sqlcmd)+1,&statement,&cmdtail)
|
||||
!= SQLITE_OK)
|
||||
|
@ -269,7 +269,7 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
|
||||
typedef struct ignored_manifest {
|
||||
unsigned char bid[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES];
|
||||
struct sockaddr_in peer;
|
||||
long long timeout;
|
||||
time_ms_t timeout;
|
||||
} ignored_manifest;
|
||||
|
||||
#define IGNORED_BIN_SIZE 8
|
||||
|
@ -92,7 +92,7 @@ struct profile_total connection_stats;
|
||||
|
||||
unsigned short rhizome_http_server_port = 0;
|
||||
static int rhizome_server_socket = -1;
|
||||
static long long rhizome_server_last_start_attempt = -1;
|
||||
static time_ms_t rhizome_server_last_start_attempt = -1;
|
||||
|
||||
// Format icon data using:
|
||||
// od -vt u1 ~/Downloads/favicon.ico | cut -c9- | sed 's/ */,/g'
|
||||
@ -138,10 +138,10 @@ int rhizome_http_server_start()
|
||||
return 1;
|
||||
|
||||
/* Only try to start http server every five seconds. */
|
||||
long long now_ms = gettime_ms();
|
||||
if (now_ms < rhizome_server_last_start_attempt + 5000)
|
||||
time_ms_t now = gettime_ms();
|
||||
if (now < rhizome_server_last_start_attempt + 5000)
|
||||
return 2;
|
||||
rhizome_server_last_start_attempt = now_ms;
|
||||
rhizome_server_last_start_attempt = now;
|
||||
if (debug & DEBUG_RHIZOME_TX)
|
||||
DEBUGF("Starting rhizome HTTP server");
|
||||
|
||||
|
@ -87,7 +87,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
|
||||
easy here (also would let us order advertisements by size of payload).
|
||||
For now, we will just advertised only occassionally.
|
||||
*/
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
if (now<rhizome_voice_timeout) voice_mode=1;
|
||||
if (voice_mode) if (random()&3) { RETURN(0); }
|
||||
|
||||
|
101
serval.h
101
serval.h
@ -113,6 +113,27 @@ struct in_addr {
|
||||
#include "log.h"
|
||||
#include "conf.h"
|
||||
|
||||
/* All wall clock times in the Serval daemon are represented in milliseconds
|
||||
* since the Unix epoch. The gettime_ms() function uses gettimeofday(2) to
|
||||
* return this value when called. The time_ms_t typedef should be used
|
||||
* wherever this time value is handled or stored.
|
||||
*
|
||||
* This type could perfectly well be unsigned, but is defined as signed to
|
||||
* avoid the need to cast or define a special signed timedelta_ms_t type at **
|
||||
* (1):
|
||||
*
|
||||
* static time_ms_t then = 0;
|
||||
* time_ms_t now = gettime_ms();
|
||||
* time_ms_t ago = now - then; // ** (1)
|
||||
* if (then && ago < 0) {
|
||||
* ... time going backwards ...
|
||||
* } else {
|
||||
* ... time has advanced ...
|
||||
* then = now;
|
||||
* }
|
||||
*/
|
||||
typedef long long time_ms_t;
|
||||
|
||||
/* bzero(3) is deprecated in favour of memset(3). */
|
||||
#define bzero(addr,len) memset((addr), 0, (len))
|
||||
|
||||
@ -325,7 +346,7 @@ typedef struct overlay_frame {
|
||||
|
||||
int rfs; /* remainder of frame size */
|
||||
|
||||
long long enqueued_at;
|
||||
time_ms_t enqueued_at;
|
||||
|
||||
} overlay_frame;
|
||||
|
||||
@ -333,15 +354,15 @@ struct profile_total {
|
||||
struct profile_total *_next;
|
||||
int _initialised;
|
||||
const char *name;
|
||||
long long max_time;
|
||||
long long total_time;
|
||||
long long child_time;
|
||||
time_ms_t max_time;
|
||||
time_ms_t total_time;
|
||||
time_ms_t child_time;
|
||||
int calls;
|
||||
};
|
||||
|
||||
struct call_stats{
|
||||
long long enter_time;
|
||||
long long child_time;
|
||||
time_ms_t enter_time;
|
||||
time_ms_t child_time;
|
||||
struct profile_total *totals;
|
||||
struct call_stats *prev;
|
||||
};
|
||||
@ -358,9 +379,9 @@ struct sched_ent{
|
||||
void *context;
|
||||
struct pollfd poll;
|
||||
// when we should first consider the alarm
|
||||
long long alarm;
|
||||
time_ms_t alarm;
|
||||
// the order we will prioritise the alarm
|
||||
long long deadline;
|
||||
time_ms_t deadline;
|
||||
struct profile_total *stats;
|
||||
int _poll_index;
|
||||
};
|
||||
@ -396,7 +417,7 @@ typedef struct overlay_interface {
|
||||
int tick_ms; /* milliseconds per tick */
|
||||
|
||||
/* The time of the last tick on this interface in milli seconds */
|
||||
long long last_tick_ms;
|
||||
time_ms_t last_tick_ms;
|
||||
/* How many times have we abbreviated our address since we last announced it in full? */
|
||||
int ticks_since_sent_full_address;
|
||||
|
||||
@ -526,7 +547,7 @@ int respondSimple(keyring_identity *id,
|
||||
int action,unsigned char *action_text,int action_len,
|
||||
unsigned char *transaction_id,int recvttl,
|
||||
struct sockaddr *recvaddr,int cryptoFlags);
|
||||
long long gettime_ms();
|
||||
time_ms_t gettime_ms();
|
||||
int server_pid();
|
||||
void server_save_argv(int argc, const char *const *argv);
|
||||
int server(char *backing_file);
|
||||
@ -657,7 +678,7 @@ long long parse_quantity(char *q);
|
||||
int overlay_interface_init(char *name,struct sockaddr_in *src_addr,struct sockaddr_in *broadcast,
|
||||
int speed_in_bits,int port,int type);
|
||||
int overlay_interface_init_socket(int i);
|
||||
long long overlay_time_until_next_tick();
|
||||
time_ms_t overlay_time_until_next_tick();
|
||||
int overlay_rx_messages();
|
||||
|
||||
void logServalPacket(int level, const char *file, unsigned int line, const char *function, const char *message, const unsigned char *packet, size_t len);
|
||||
@ -707,7 +728,7 @@ typedef struct overlay_neighbour_observation {
|
||||
e.g., for gigabit type links. So lets go with 1ms granularity. */
|
||||
unsigned int s1;
|
||||
unsigned int s2;
|
||||
long long time_ms;
|
||||
time_ms_t time_ms;
|
||||
unsigned char sender_interface;
|
||||
unsigned char valid;
|
||||
} overlay_neighbour_observation;
|
||||
@ -718,7 +739,7 @@ typedef struct overlay_node_observation {
|
||||
unsigned char gateways_en_route;
|
||||
unsigned char RESERVED; /* for alignment */
|
||||
unsigned char interface;
|
||||
long long rx_time;
|
||||
time_ms_t rx_time;
|
||||
unsigned char sender_prefix[OVERLAY_SENDER_PREFIX_LENGTH];
|
||||
} overlay_node_observation;
|
||||
|
||||
@ -730,17 +751,17 @@ typedef struct overlay_node {
|
||||
int best_link_score;
|
||||
int best_observation;
|
||||
unsigned int last_first_hand_observation_time_millisec;
|
||||
long long last_observation_time_ms;
|
||||
time_ms_t last_observation_time_ms;
|
||||
/* When did we last advertise this node on each interface, and what score
|
||||
did we advertise? */
|
||||
long long most_recent_advertisment[OVERLAY_MAX_INTERFACES];
|
||||
time_ms_t most_recent_advertisment_ms[OVERLAY_MAX_INTERFACES];
|
||||
unsigned char most_recent_advertised_score[OVERLAY_MAX_INTERFACES];
|
||||
overlay_node_observation observations[OVERLAY_MAX_OBSERVATIONS];
|
||||
} overlay_node;
|
||||
|
||||
typedef struct overlay_neighbour {
|
||||
long long last_observation_time_ms;
|
||||
long long last_metric_update;
|
||||
time_ms_t last_observation_time_ms;
|
||||
time_ms_t last_metric_update;
|
||||
int most_recent_observation_id;
|
||||
overlay_neighbour_observation observations[OVERLAY_MAX_OBSERVATIONS];
|
||||
overlay_node *node;
|
||||
@ -755,12 +776,11 @@ typedef struct overlay_neighbour {
|
||||
} overlay_neighbour;
|
||||
extern overlay_neighbour *overlay_neighbours;
|
||||
|
||||
long long overlay_gettime_ms();
|
||||
int overlay_route_init(int mb_ram);
|
||||
int overlay_route_saw_selfannounce_ack(overlay_frame *f,long long now);
|
||||
int overlay_route_recalc_node_metrics(overlay_node *n,long long now);
|
||||
int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now);
|
||||
int overlay_route_saw_selfannounce(overlay_frame *f,long long now);
|
||||
int overlay_route_saw_selfannounce_ack(overlay_frame *f, time_ms_t now);
|
||||
int overlay_route_recalc_node_metrics(overlay_node *n, time_ms_t now);
|
||||
int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n, time_ms_t now);
|
||||
int overlay_route_saw_selfannounce(overlay_frame *f, time_ms_t now);
|
||||
overlay_node *overlay_route_find_node(const unsigned char *sid,int prefixLen,int createP);
|
||||
unsigned int overlay_route_hash_sid(const unsigned char *sid);
|
||||
int overlay_route_init(int mb_ram);
|
||||
@ -775,14 +795,13 @@ int overlay_broadcast_generate_address(unsigned char *a);
|
||||
int packetEncipher(unsigned char *packet,int maxlen,int *len,int cryptoflags);
|
||||
int overlayServerMode();
|
||||
int overlay_payload_enqueue(int q,overlay_frame *p,int forceBroadcastP);
|
||||
long long overlay_time_in_ms();
|
||||
int overlay_abbreviate_lookup_sender_id();
|
||||
int overlay_route_record_link(long long now,unsigned char *to,
|
||||
int overlay_route_record_link( time_ms_t now,unsigned char *to,
|
||||
unsigned char *via,int sender_interface,
|
||||
unsigned int s1,unsigned int s2,int score,int gateways_en_route);
|
||||
int overlay_route_dump();
|
||||
int overlay_route_tick_neighbour(int neighbour_id,long long now);
|
||||
int overlay_route_tick_node(int bin,int slot,long long now);
|
||||
int overlay_route_tick_neighbour(int neighbour_id, time_ms_t now);
|
||||
int overlay_route_tick_node(int bin,int slot, time_ms_t now);
|
||||
int overlay_route_add_advertisements(overlay_buffer *e);
|
||||
int ovleray_route_please_advertise(overlay_node *n);
|
||||
int overlay_abbreviate_set_current_sender(unsigned char *in);
|
||||
@ -792,12 +811,12 @@ extern int overlay_bin_size; /* associativity, i.e., entries per bin */
|
||||
extern int overlay_bin_bytes;
|
||||
extern overlay_node **overlay_nodes;
|
||||
|
||||
int overlay_route_saw_advertisements(int i,overlay_frame *f, long long now);
|
||||
int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now);
|
||||
int overlay_route_saw_advertisements(int i,overlay_frame *f, time_ms_t now);
|
||||
int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, time_ms_t now);
|
||||
int overlay_route_please_advertise(overlay_node *n);
|
||||
int rhizome_server_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||
int rhizome_saw_voice_traffic();
|
||||
int overlay_saw_mdp_containing_frame(overlay_frame *f,long long now);
|
||||
int overlay_saw_mdp_containing_frame(overlay_frame *f, time_ms_t now);
|
||||
|
||||
#include "nacl.h"
|
||||
|
||||
@ -896,9 +915,9 @@ typedef struct overlay_mdp_vompevent {
|
||||
/* Once a call has been established, this is how the MDP/VoMP server
|
||||
and user-end process talk about the call. */
|
||||
unsigned int call_session_token;
|
||||
unsigned long long audio_sample_endtime;
|
||||
unsigned long long audio_sample_starttime;
|
||||
unsigned long long last_activity;
|
||||
unsigned int audio_sample_endtime;
|
||||
unsigned int audio_sample_starttime;
|
||||
time_ms_t last_activity;
|
||||
unsigned int flags;
|
||||
unsigned short audio_sample_bytes;
|
||||
unsigned char audio_sample_codec;
|
||||
@ -935,7 +954,7 @@ typedef struct overlay_mdp_nodeinfo {
|
||||
int score;
|
||||
int interface_number;
|
||||
int resolve_did;
|
||||
unsigned long long time_since_last_observation;
|
||||
time_ms_t time_since_last_observation;
|
||||
int index; /* which record to return or was returned (incase there are multiple matches) */
|
||||
int count; /* number of matching records */
|
||||
} overlay_mdp_nodeinfo;
|
||||
@ -962,12 +981,12 @@ int keyring_mapping_request(keyring_file *k,overlay_mdp_frame *req);
|
||||
extern int mdp_client_socket;
|
||||
int overlay_mdp_client_init();
|
||||
int overlay_mdp_client_done();
|
||||
int overlay_mdp_client_poll(long long timeout_ms);
|
||||
int overlay_mdp_client_poll(time_ms_t timeout_ms);
|
||||
int overlay_mdp_recv(overlay_mdp_frame *mdp,int *ttl);
|
||||
int overlay_mdp_send(overlay_mdp_frame *mdp,int flags,int timeout_ms);
|
||||
|
||||
/* Server-side MDP functions */
|
||||
int overlay_saw_mdp_frame(overlay_mdp_frame *mdp,long long now);
|
||||
int overlay_saw_mdp_frame(overlay_mdp_frame *mdp, time_ms_t now);
|
||||
int overlay_mdp_swap_src_dst(overlay_mdp_frame *mdp);
|
||||
int overlay_mdp_reply(int sock,struct sockaddr_un *recvaddr,int recvaddrlen,
|
||||
overlay_mdp_frame *mdpreply);
|
||||
@ -1004,8 +1023,8 @@ typedef struct vomp_call_half {
|
||||
|
||||
typedef struct vomp_sample_block {
|
||||
unsigned int codec;
|
||||
unsigned long long starttime;
|
||||
unsigned long long endtime;
|
||||
time_ms_t starttime;
|
||||
time_ms_t endtime;
|
||||
unsigned char bytes[1024];
|
||||
} vomp_sample_block;
|
||||
|
||||
@ -1016,9 +1035,9 @@ typedef struct vomp_call_state {
|
||||
int initiated_call;
|
||||
int ringing;
|
||||
int fast_audio;
|
||||
unsigned long long create_time;
|
||||
unsigned long long last_activity;
|
||||
unsigned long long audio_clock;
|
||||
time_ms_t create_time;
|
||||
time_ms_t last_activity;
|
||||
time_ms_t audio_clock;
|
||||
int audio_started;
|
||||
// last local & remote status we sent to all interested parties
|
||||
int last_sent_status;
|
||||
@ -1128,7 +1147,7 @@ int encodeAndDispatchRecordedAudio(int fd,int callSessionToken,
|
||||
int scrapeProcNetRoute();
|
||||
int lsif();
|
||||
int doifaddrs();
|
||||
int bufferAudioForPlayback(int codec,long long start_time,long long end_time,
|
||||
int bufferAudioForPlayback(int codec, time_ms_t start_time, time_ms_t end_time,
|
||||
unsigned char *data,int dataLen);
|
||||
int startAudio();
|
||||
int stopAudio();
|
||||
|
21
server.c
21
server.c
@ -112,11 +112,14 @@ ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl,
|
||||
return len;
|
||||
}
|
||||
|
||||
long long gettime_ms()
|
||||
time_ms_t gettime_ms()
|
||||
{
|
||||
struct timeval nowtv;
|
||||
if (gettimeofday(&nowtv, NULL))
|
||||
FATAL_perror("gettimeofday"); // If this fails, all else is lost!
|
||||
// If gettimeofday() fails or returns an invalid value, all else is lost!
|
||||
if (gettimeofday(&nowtv, NULL) == -1)
|
||||
FATAL_perror("gettimeofday");
|
||||
if (nowtv.tv_sec < 0 || nowtv.tv_usec < 0 || nowtv.tv_usec >= 1000000)
|
||||
FATALF("gettimeofday returned tv_sec=%ld tv_usec=%ld", nowtv.tv_sec, nowtv.tv_usec);
|
||||
return nowtv.tv_sec * 1000LL + nowtv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
@ -245,18 +248,18 @@ void server_shutdown_check(struct sched_ent *alarm)
|
||||
/* If this server has been supplanted with another or Serval has been uninstalled, then its PID
|
||||
file will change or be unaccessible. In this case, shut down without all the cleanup.
|
||||
Perform this check at most once per second. */
|
||||
static long long server_pid_time_ms = 0;
|
||||
long long time_ms = gettime_ms();
|
||||
if (server_pid_time_ms == 0 || time_ms - server_pid_time_ms > 1000) {
|
||||
server_pid_time_ms = time_ms;
|
||||
static time_ms_t server_pid_time_ms = 0;
|
||||
time_ms_t now = gettime_ms();
|
||||
if (server_pid_time_ms == 0 || now - server_pid_time_ms > 1000) {
|
||||
server_pid_time_ms = now;
|
||||
if (server_pid() != server_getpid) {
|
||||
WARNF("Server pid file no longer contains pid=%d -- shutting down without cleanup", server_getpid);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (alarm){
|
||||
alarm->alarm = gettime_ms()+1000;
|
||||
alarm->deadline = alarm->alarm+5000;
|
||||
alarm->alarm = now + 1000;
|
||||
alarm->deadline = alarm->alarm + 5000;
|
||||
schedule(alarm);
|
||||
}
|
||||
}
|
||||
|
22
vomp.c
22
vomp.c
@ -49,7 +49,7 @@ int vomp_interested_usock_count=0;
|
||||
#define VOMP_MAX_INTERESTED 128
|
||||
struct sockaddr_un *vomp_interested_usocks[VOMP_MAX_INTERESTED];
|
||||
int vomp_interested_usock_lengths[VOMP_MAX_INTERESTED];
|
||||
unsigned long long vomp_interested_expiries[VOMP_MAX_INTERESTED];
|
||||
time_ms_t vomp_interested_expiries[VOMP_MAX_INTERESTED];
|
||||
|
||||
vomp_call_state *vomp_find_call_by_session(int session_token)
|
||||
{
|
||||
@ -207,7 +207,7 @@ int vomp_send_status_remote_audio(vomp_call_state *call, int audio_codec, const
|
||||
mdp.out.payload[3]=(call->remote.sequence>>0)&0xff;
|
||||
mdp.out.payload[4]=(call->local.sequence>>8)&0xff;
|
||||
mdp.out.payload[5]=(call->local.sequence>>0)&0xff;
|
||||
unsigned long long call_millis=gettime_ms()-call->create_time;
|
||||
time_ms_t call_millis = gettime_ms() - call->create_time;
|
||||
mdp.out.payload[6]=(call_millis>>8)&0xff;
|
||||
mdp.out.payload[7]=(call_millis>>0)&0xff;
|
||||
mdp.out.payload[8]=(call->remote.session>>16)&0xff;
|
||||
@ -344,7 +344,7 @@ int vomp_send_mdp_status_audio(vomp_call_state *call, int audio_codec, unsigned
|
||||
}
|
||||
|
||||
int i;
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
for(i=0;i<vomp_interested_usock_count;i++)
|
||||
if (vomp_interested_expiries[i]>=now) {
|
||||
overlay_mdp_reply(mdp_named.poll.fd,
|
||||
@ -423,7 +423,7 @@ int vomp_process_audio(vomp_call_state *call,unsigned int sender_duration,overla
|
||||
|
||||
sender_duration = (e&0xFFFF0000)|sender_duration;
|
||||
if (debug & DEBUG_VOMP)
|
||||
DEBUGF("Jitter %d, %d",sender_duration -e,(gettime_ms()-call->create_time)-e);
|
||||
DEBUGF("Jitter %d, %lld", sender_duration - e, (long long)((gettime_ms() - call->create_time) - e));
|
||||
|
||||
while(ofs<mdp->in.payload_length)
|
||||
{
|
||||
@ -597,7 +597,7 @@ int vomp_mdp_event(overlay_mdp_frame *mdp, struct sockaddr_un *recvaddr,int recv
|
||||
{
|
||||
int i;
|
||||
int candidate=-1;
|
||||
long long now=gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
for(i=0;i<vomp_interested_usock_count;i++)
|
||||
{
|
||||
if (vomp_interested_usock_lengths[i]==recvaddrlen)
|
||||
@ -622,7 +622,7 @@ int vomp_mdp_event(overlay_mdp_frame *mdp, struct sockaddr_un *recvaddr,int recv
|
||||
bcopy(recvaddr,vomp_interested_usocks[i],
|
||||
recvaddrlen);
|
||||
vomp_interested_usock_lengths[i]=recvaddrlen;
|
||||
vomp_interested_expiries[i]=gettime_ms()+60000;
|
||||
vomp_interested_expiries[i] = gettime_ms() + 60000;
|
||||
if (i==vomp_interested_usock_count) vomp_interested_usock_count++;
|
||||
|
||||
if (mdp->vompevent.supported_codecs[0]) {
|
||||
@ -663,7 +663,7 @@ int vomp_mdp_event(overlay_mdp_frame *mdp, struct sockaddr_un *recvaddr,int recv
|
||||
vomp_interested_usock_lengths[i]
|
||||
=vomp_interested_usock_lengths[swap];
|
||||
vomp_interested_usocks[i]=vomp_interested_usocks[swap];
|
||||
vomp_interested_expiries[i]=vomp_interested_expiries[swap];
|
||||
vomp_interested_expiries[i] = vomp_interested_expiries[swap];
|
||||
}
|
||||
vomp_interested_usock_count--;
|
||||
return overlay_mdp_reply_error
|
||||
@ -1389,9 +1389,9 @@ int app_vomp_monitor(int argc, const char *const *argv, struct command_line_opti
|
||||
DEBUGF(" attached audio sample: codec=%s, len=%d",
|
||||
vomp_describe_codec(rx.vompevent.audio_sample_codec),
|
||||
rx.vompevent.audio_sample_bytes);
|
||||
DEBUGF(" sample covers %lldms - %lldms of call.",
|
||||
rx.vompevent.audio_sample_starttime,
|
||||
rx.vompevent.audio_sample_endtime);
|
||||
DEBUGF(" sample covers %ldms - %ldms of call.",
|
||||
(long) rx.vompevent.audio_sample_starttime,
|
||||
(long) rx.vompevent.audio_sample_endtime);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1417,7 +1417,7 @@ static void vomp_process_tick(struct sched_ent *alarm)
|
||||
{
|
||||
char msg[32];
|
||||
int len;
|
||||
unsigned long long now = gettime_ms();
|
||||
time_ms_t now = gettime_ms();
|
||||
|
||||
vomp_call_state *call = (vomp_call_state *)alarm;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user