X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_auth.c;h=76188f6ebdba79fa11837daffeea33b897750ad0;hb=326a86ef927e1f161a6742edfca041a945c7a547;hp=85a0fbe16237bfad1c01e9fb9553f39815b44a68;hpb=ae1d95cee66f3e5c6475f03b441d455e436e9ee8;p=meshlink diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 85a0fbe1..76188f6e 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -36,6 +36,8 @@ #include "utils.h" #include "xalloc.h" #include "ed25519/sha512.h" + +extern bool node_write_dclass(meshlink_handle_t *mesh, node_t *n); static bool send_proxyrequest(meshlink_handle_t *mesh, connection_t *c) { switch(mesh->proxytype) { @@ -124,8 +126,7 @@ static bool send_proxyrequest(meshlink_handle_t *mesh, connection_t *c) { } bool send_id(meshlink_handle_t *mesh, connection_t *c) { - gettimeofday(&c->start, NULL); - + int minor = mesh->self->connection->protocol_minor; if(mesh->proxytype && c->outgoing) @@ -353,22 +354,13 @@ bool id_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } bool send_ack(meshlink_handle_t *mesh, 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; /* Check some options */ if(mesh->self->options & OPTION_PMTU_DISCOVERY) c->options |= OPTION_PMTU_DISCOVERY; - return send_request(mesh, c, "%d %s %d %x", ACK, mesh->myport, c->estimated_weight, (c->options & 0xffffff) | (PROT_MINOR << 24)); + return send_request(mesh, c, "%d %s %d %x", ACK, mesh->myport, mesh->dclass, (c->options & 0xffffff) | (PROT_MINOR << 24)); } static void send_everything(meshlink_handle_t *mesh, connection_t *c) { @@ -383,11 +375,11 @@ static void send_everything(meshlink_handle_t *mesh, connection_t *c) { bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { char hisport[MAX_STRING_SIZE]; char *hisaddress; - int weight; + int dclass; uint32_t options; node_t *n; - if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &weight, &options) != 3) { + if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &dclass, &options) != 3) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ACK", c->name, c->hostname); return false; @@ -421,6 +413,9 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } } + n->dclass = dclass; + node_write_dclass(mesh, n); + n->connection = c; c->node = n; if(!(c->options & options & OPTION_PMTU_DISCOVERY)) { @@ -449,7 +444,7 @@ bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { sockaddr2str(&c->address, &hisaddress, NULL); c->edge->address = str2sockaddr(hisaddress, hisport); free(hisaddress); - c->edge->weight = (weight + c->estimated_weight) / 2; + c->edge->weight = weight_from_dclass(dclass); c->edge->connection = c; c->edge->options = c->options;