/*
net.c -- most of the network code
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 Guus Sliepen <guus@meshlink.io>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <assert.h>
#if !defined(min)
-static const int min(int a, int b) {
+static inline int min(int a, int b) {
return a < b ? a : b;
}
#endif
- Check if we need to retry making an outgoing connection
*/
void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) {
- logger(mesh, MESHLINK_INFO, "Closing connection with %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Closing connection with %s", c->name);
c->status.active = false;
/* If the node is not reachable anymore but we remember it had an edge to us, clean it up */
- if(report && !c->node->status.reachable) {
+ if(report && c->node && !c->node->status.reachable) {
edge_t *e;
e = lookup_edge(c->node, mesh->self);
if(e) {
if(c->last_ping_time + mesh->pingtimeout <= mesh->loop.now.tv_sec) {
if(c->status.active) {
if(c->status.pinged)
- logger(mesh, MESHLINK_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, (long)mesh->loop.now.tv_sec - c->last_ping_time);
+ logger(mesh, MESHLINK_INFO, "%s didn't respond to PING in %ld seconds", c->name, (long)mesh->loop.now.tv_sec - c->last_ping_time);
else if(c->last_ping_time + mesh->pinginterval <= mesh->loop.now.tv_sec) {
send_ping(mesh, c);
continue;
continue;
} else {
if(c->status.connecting)
- logger(mesh, MESHLINK_WARNING, "Timeout while connecting to %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Timeout while connecting to %s", c->name);
else
- logger(mesh, MESHLINK_WARNING, "Timeout from %s (%s) during authentication", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Timeout from %s during authentication", c->name);
}
terminate_connection(mesh, c, c->status.active);
}
// get cur_connects
- int cur_connects = 0;
+ unsigned int cur_connects = 0;
for list_each(connection_t, c, mesh->connections) {
if(c->status.active)
assert(mesh->devclass >= 0 && mesh->devclass <= _DEV_CLASS_MAX);
- int min_connects = dev_class_traits[mesh->devclass].min_connects;
- int max_connects = dev_class_traits[mesh->devclass].max_connects;
+ unsigned int min_connects = dev_class_traits[mesh->devclass].min_connects;
+ unsigned int max_connects = dev_class_traits[mesh->devclass].max_connects;
logger(mesh, MESHLINK_DEBUG, "* min_connects = %d", min_connects);
logger(mesh, MESHLINK_DEBUG, "* max_connects = %d", max_connects);
if(!connect_to && min_connects <= cur_connects && cur_connects < max_connects) {
unsigned int connects = 0;
- for(int devclass = 0; devclass <= mesh->devclass; ++devclass) {
+ for(unsigned int devclass = 0; devclass <= mesh->devclass; ++devclass) {
for list_each(connection_t, c, mesh->connections) {
if(c->status.active && c->node && c->node->devclass == devclass)
connects += 1;
if(min_connects < cur_connects /*&& cur_connects <= max_connects*/) {
unsigned int connects = 0;
- for(int devclass = 0; devclass <= mesh->devclass; ++devclass) {
+ for(unsigned int devclass = 0; devclass <= mesh->devclass; ++devclass) {
for list_each(connection_t, c, mesh->connections) {
if(c->status.active && c->node && c->node->devclass == devclass)
connects += 1;