]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_misc.c
Add meshlink_get_node_reachability().
[meshlink] / src / protocol_misc.c
index 727881bd1080476d2c5d9303b76d315f702cc2a0..af3caddf8957f38006a540ddc331cfe0823efcdd 100644 (file)
@@ -34,6 +34,9 @@ int maxoutbufsize = 0;
 /* Status and error notification routines */
 
 bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        int statusno;
        char statusstring[MAX_STRING_SIZE];
 
@@ -48,6 +51,9 @@ bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 }
 
 bool error_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        int err;
        char errorstring[MAX_STRING_SIZE];
 
@@ -65,6 +71,10 @@ bool termreq_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        (void)mesh;
        (void)c;
        (void)request;
+
+       assert(request);
+       assert(*request);
+
        return false;
 }
 
@@ -72,28 +82,37 @@ bool send_ping(meshlink_handle_t *mesh, connection_t *c) {
        c->status.pinged = true;
        c->last_ping_time = mesh->loop.now.tv_sec;
 
-       return send_request(mesh, c, "%d", PING);
+       return send_request(mesh, c, NULL, "%d", PING);
 }
 
 bool ping_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        (void)request;
+
+       assert(request);
+       assert(*request);
+
        return send_pong(mesh, c);
 }
 
 bool send_pong(meshlink_handle_t *mesh, connection_t *c) {
-       return send_request(mesh, c, "%d", PONG);
+       return send_request(mesh, c, NULL, "%d", PONG);
 }
 
 bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        (void)mesh;
        (void)request;
+
+       assert(request);
+       assert(*request);
+
        c->status.pinged = false;
 
-       /* Succesful connection, reset timeout if this is an outgoing connection. */
+       /* Successful connection, reset timeout if this is an outgoing connection. */
 
+       // TODO: completely remove this outgoing, let the autoconnect algorithm handle it
        if(c->outgoing) {
                c->outgoing->timeout = 0;
-               c->outgoing->cfg = NULL;
+               c->outgoing->state = OUTGOING_START;
 
                if(c->outgoing->ai) {
                        freeaddrinfo(c->outgoing->ai);
@@ -109,6 +128,9 @@ bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 /* Sending and receiving packets via TCP */
 
 bool tcppacket_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        short int len;
 
        if(sscanf(request, "%*d %hd", &len) != 1) {