]> git.meshlink.io Git - meshlink/blobdiff - src/route.c
Never automatically try to bind to ports >= 32768.
[meshlink] / src / route.c
index 9255712e22682d06759ec98efc094036240fe60c..c63c03732f4e39c8b93cff6233b105e3257ebefc 100644 (file)
@@ -25,9 +25,9 @@
 #include "route.h"
 #include "utils.h"
 
-bool decrement_ttl = false;
-
 static bool checklength(node_t *source, vpn_packet_t *packet, uint16_t length) {
+       assert(length);
+
        if(packet->len < length) {
                logger(source->mesh, MESHLINK_WARNING, "Got too short packet from %s", source->name);
                return false;
@@ -37,6 +37,8 @@ static bool checklength(node_t *source, vpn_packet_t *packet, uint16_t length) {
 }
 
 void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) {
+       assert(source);
+
        // TODO: route on name or key
 
        meshlink_packethdr_t *hdr = (meshlink_packethdr_t *) packet->data;
@@ -55,9 +57,16 @@ void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) {
                return;
        }
 
+       size_t len = packet->len - sizeof(*hdr);
+
+       // Channel traffic accounting
+       if(source == mesh->self) {
+               dest->out_data += len + SPTPS_OVERHEAD;
+       }
+
        if(dest == mesh->self) {
+               source->in_data += len + SPTPS_OVERHEAD;
                const void *payload = packet->data + sizeof(*hdr);
-               size_t len = packet->len - sizeof(*hdr);
 
                char hex[len * 2 + 1];
 
@@ -67,7 +76,9 @@ void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) {
 
                logger(mesh, MESHLINK_DEBUG, "I received a packet for me with payload: %s\n", hex);
 
-               if(mesh->receive_cb) {
+               if(source->utcp) {
+                       channel_receive(mesh, (meshlink_node_t *)source, payload, len);
+               } else if(mesh->receive_cb) {
                        mesh->receive_cb(mesh, (meshlink_node_t *)source, payload, len);
                }