X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprotocol.c;h=63b10b1e48ab6204476586ebe00a61d6b078e6b7;hp=2771405cd2f7cbf590f7edb865a0f07c0b2acdb0;hb=b6298e2c082035b8238ea08673ced15d0fb7b89a;hpb=66067cc9c1347fb2de35660d531fdd4be8aede6a diff --git a/src/protocol.c b/src/protocol.c index 2771405c..63b10b1e 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: protocol.c,v 1.28.4.111 2001/10/28 10:16:18 guus Exp $ + $Id: protocol.c,v 1.28.4.112 2001/10/28 22:42:49 guus Exp $ */ #include "config.h" @@ -526,18 +526,26 @@ int send_ack(connection_t *c) { /* ACK message contains rest of the information the other end needs to create node_t and edge_t structures. */ + + struct timeval now; + + /* Estimate weight */ + + gettimeofday(&now, NULL); + c->estimated_weight = (now.tv_sec - c->start.tv_sec) * 1000 + (now.tv_usec - c->start.tv_usec) / 1000; cp - return send_request(c, "%d %d", ACK, myself->port); + return send_request(c, "%d %hd %d", ACK, myself->port, c->estimated_weight); } int ack_h(connection_t *c) { port_t port; + int weight; node_t *n; subnet_t *s; avl_node_t *node, *node2; cp - if(sscanf(c->buffer, "%*d %hd", &port) != 1) + if(sscanf(c->buffer, "%*d %hd %d", &port, &weight) != 2) { syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name, c->hostname); return -1; @@ -600,7 +608,7 @@ cp c->edge->from = myself; c->edge->to = n; - c->edge->weight = 1; + c->edge->weight = (weight + c->estimated_weight) / 2; c->edge->connection = c; edge_add(c->edge);