X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fprotocol.c;h=63b10b1e48ab6204476586ebe00a61d6b078e6b7;hp=d1bb524fc2e53913aa68885c029d37ae194e70d5;hb=b6298e2c082035b8238ea08673ced15d0fb7b89a;hpb=94497336efc1cc60561575e74d420e9e8e8c657e diff --git a/src/protocol.c b/src/protocol.c index d1bb524f..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.110 2001/10/28 08:41:19 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->metric = 1; + c->edge->weight = (weight + c->estimated_weight) / 2; c->edge->connection = c; edge_add(c->edge); @@ -934,19 +942,19 @@ cp return 0; } -/* Vertices */ +/* Edges */ -int send_add_edge(connection_t *c, edge_t *v) +int send_add_edge(connection_t *c, edge_t *e) { cp return send_request(c, "%d %s %s %lx", ADD_NODE, - v->from->name, v->to->name, v->options); + e->from->name, e->to->name, e->options); } int add_edge_h(connection_t *c) { connection_t *other; - edge_t *v; + edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; @@ -993,19 +1001,19 @@ cp /* Check if node already exists */ - v = lookup_edge(from, to); + e = lookup_edge(from, to); - if(v) + if(e) { /* Check if it matches */ } else { - v = new_edge(); - v->from = from; - v->to = to; - v->options = options; - edge_add(v); + e = new_edge(); + e->from = from; + e->to = to; + e->options = options; + edge_add(e); } /* Tell the rest about the new edge */ @@ -1014,23 +1022,23 @@ cp { other = (connection_t *)node->data; if(other->status.active && other != c) - send_add_edge(other, v); + send_add_edge(other, e); } cp return 0; } -int send_del_edge(connection_t *c, edge_t *v) +int send_del_edge(connection_t *c, edge_t *e) { cp return send_request(c, "%d %s %s %lx", DEL_EDGE, - v->from->name, v->to->name, v->options); + e->from->name, e->to->name, e->options); } int del_edge_h(connection_t *c) { - edge_t *v; + edge_t *e; char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; node_t *from, *to; @@ -1079,9 +1087,9 @@ cp /* Check if edge exists */ - v = lookup_edge(from, to); + e = lookup_edge(from, to); - if(v) + if(e) { /* Check if it matches */ } @@ -1097,12 +1105,12 @@ cp { other = (connection_t *)node->data; if(other->status.active && other != c) - send_del_edge(other, v); + send_del_edge(other, e); } /* Delete the edge */ - edge_del(v); + edge_del(e); cp return 0; }