]> git.meshlink.io Git - meshlink/blobdiff - src/net_packet.c
Try addresses found by Catta for UDP probes.
[meshlink] / src / net_packet.c
index 7dae0fe0a558c3ac5eed8920de4f00ef290e2f14..8bc363d229a8f45350a09e3d18a53ad5ca264681 100644 (file)
@@ -308,6 +308,12 @@ static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const s
                return;
        }
 
+       /* If we have learned an address via Catta, try this once every batch */
+       if(mesh->udp_choice == 1 && n->catta_address.sa.sa_family != AF_UNSPEC) {
+               *sa = &n->catta_address;
+               goto check_socket;
+       }
+
        /* Otherwise, address are found in edges to this node.
           So we pick a random edge and a random socket. */
 
@@ -327,6 +333,7 @@ static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const s
                *sock = prng(mesh, mesh->listen_sockets);
        }
 
+check_socket:
        /* Make sure we have a suitable socket for the chosen address */
        if(mesh->listen_socket[*sock].sa.sa.sa_family != (*sa)->sa.sa_family) {
                for(int i = 0; i < mesh->listen_sockets; i++) {
@@ -370,7 +377,7 @@ bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len) {
 
        /* Send it via TCP if it is a handshake packet, TCPOnly is in use, or this packet is larger than the MTU. */
 
-       if(type >= SPTPS_HANDSHAKE || (type != PKT_PROBE && len > to->minmtu)) {
+       if(type >= SPTPS_HANDSHAKE || (type != PKT_PROBE && (len - 21) > to->minmtu)) {
                char buf[len * 4 / 3 + 5];
                b64encode(data, buf, len);
 
@@ -433,8 +440,8 @@ bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t
                return true;
        }
 
-       if(len > MTU) {
-               logger(mesh, MESHLINK_ERROR, "Packet from %s larger than maximum supported size (%d > %d)", from->name, len, MTU);
+       if(len > MAXSIZE) {
+               logger(mesh, MESHLINK_ERROR, "Packet from %s larger than maximum supported size (%d > %d)", from->name, len, MAXSIZE);
                return false;
        }