X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink.c;fp=src%2Fmeshlink.c;h=048f72e502dae2e5873a3c75b67c2595db285099;hb=de1fbdf4403ea2a78f14925ffcc113198d87fc9d;hp=8da56922aa5735828f0e598773c613fb3b13d645;hpb=b8d9f9f97b63565bfe56c248428a49bc3f6a1e47;p=meshlink diff --git a/src/meshlink.c b/src/meshlink.c index 8da56922..048f72e5 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -38,7 +38,6 @@ typedef struct { #include "netutl.h" #include "node.h" #include "protocol.h" -#include "route.h" #include "sockaddr.h" #include "utils.h" #include "xalloc.h" @@ -1457,7 +1456,7 @@ void meshlink_close(meshlink_handle_t *mesh) { if(mesh->conffile) { fclose(mesh->conffile); - } + } memset(mesh, 0, sizeof(*mesh)); @@ -1535,10 +1534,8 @@ void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, me } bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len) { - meshlink_packethdr_t *hdr; - // Validate arguments - if(!mesh || !destination || len >= MAXSIZE - sizeof(*hdr)) { + if(!mesh || !destination || len >= MAXSIZE) { meshlink_errno = MESHLINK_EINVAL; return false; } @@ -1562,16 +1559,11 @@ bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const packet->probe = false; packet->tcp = false; - packet->len = len + sizeof(*hdr); - - hdr = (meshlink_packethdr_t *)packet->data; - memset(hdr, 0, sizeof(*hdr)); - // leave the last byte as 0 to make sure strings are always - // null-terminated if they are longer than the buffer - strncpy((char *)hdr->destination, destination->name, (sizeof(hdr)->destination) - 1); - strncpy((char *)hdr->source, mesh->self->name, (sizeof(hdr)->source) - 1); + packet->len = len; + packet->src = mesh->self->id; + packet->dst = ((node_t *)destination)->id; - memcpy(packet->data + sizeof(*hdr), data, len); + memcpy(packet->data, data, len); // Queue it if(!meshlink_queue_push(&mesh->outpacketqueue, packet)) { @@ -1596,7 +1588,13 @@ void meshlink_send_from_queue(event_loop_t *loop, meshlink_handle_t *mesh) { mesh->self->in_packets++; mesh->self->in_bytes += packet->len; - route(mesh, mesh->self, packet); + node_t *dest = lookup_node_id(mesh, packet->dst); + + if(dest) { + send_packet(mesh, dest, packet); + } + + free(packet); } ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination) {