]> git.meshlink.io Git - meshlink/blob - src/net.c
Allow sptps_force_kex() while a key exchange is in progress
[meshlink] / src / net.c
1 /*
2     net.c -- most of the network code
3     Copyright (C) 2014-2017 Guus Sliepen <guus@meshlink.io>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "system.h"
21
22 #include "utils.h"
23 #include "conf.h"
24 #include "connection.h"
25 #include "devtools.h"
26 #include "graph.h"
27 #include "logger.h"
28 #include "meshlink_internal.h"
29 #include "meta.h"
30 #include "net.h"
31 #include "netutl.h"
32 #include "protocol.h"
33 #include "sptps.h"
34 #include "xalloc.h"
35
36 #include <assert.h>
37
38 #if !defined(min)
39 static inline int min(int a, int b) {
40         return a < b ? a : b;
41 }
42 #endif
43
44 static const int default_timeout = 5;
45 static const int default_interval = 60;
46
47 /*
48   Terminate a connection:
49   - Mark it as inactive
50   - Remove the edge representing this connection
51   - Kill it with fire
52   - Check if we need to retry making an outgoing connection
53 */
54 void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) {
55         logger(mesh, MESHLINK_INFO, "Closing connection with %s", c->name);
56
57         if(c->node && c->node->connection == c) {
58                 if(c->status.active && mesh->meta_status_cb) {
59                         mesh->meta_status_cb(mesh, (meshlink_node_t *)c->node, false);
60                 }
61
62                 c->node->connection = NULL;
63         }
64
65         c->status.active = false;
66
67         if(c->edge) {
68                 if(report) {
69                         send_del_edge(mesh, mesh->everyone, c->edge, 0);
70                 }
71
72                 edge_del(mesh, c->edge);
73                 c->edge = NULL;
74
75                 /* Run MST and SSSP algorithms */
76
77                 graph(mesh);
78
79                 /* If the node is not reachable anymore but we remember it had an edge to us, clean it up */
80
81                 if(report && c->node && !c->node->status.reachable) {
82                         edge_t *e;
83                         e = lookup_edge(c->node, mesh->self);
84
85                         if(e) {
86                                 send_del_edge(mesh, mesh->everyone, e, 0);
87                                 edge_del(mesh, e);
88                         }
89                 }
90         }
91
92         outgoing_t *outgoing = c->outgoing;
93         connection_del(mesh, c);
94
95         /* Check if this was our outgoing connection */
96
97         if(outgoing) {
98                 do_outgoing_connection(mesh, outgoing);
99         }
100 }
101
102 /*
103   Check if the other end is active.
104   If we have sent packets, but didn't receive any,
105   then possibly the other end is dead. We send a
106   PING request over the meta connection. If the other
107   end does not reply in time, we consider them dead
108   and close the connection.
109 */
110 static void timeout_handler(event_loop_t *loop, void *data) {
111         assert(data);
112
113         meshlink_handle_t *mesh = loop->data;
114         logger(mesh, MESHLINK_DEBUG, "timeout_handler()");
115
116         for list_each(connection_t, c, mesh->connections) {
117                 int pingtimeout = c->node ? mesh->dev_class_traits[c->node->devclass].pingtimeout : default_timeout;
118                 int pinginterval = c->node ? mesh->dev_class_traits[c->node->devclass].pinginterval : default_interval;
119
120                 if(c->outgoing && c->outgoing->timeout < 5) {
121                         pingtimeout = 1;
122                 }
123
124                 // Also make sure that if outstanding key requests for the UDP counterpart of a connection has timed out, we restart it.
125                 if(c->node) {
126                         if(c->node->status.waitingforkey && c->node->last_req_key + pingtimeout <= mesh->loop.now.tv_sec) {
127                                 send_req_key(mesh, c->node);
128                         }
129                 }
130
131                 if(c->status.active && c->last_key_renewal + 3600 < mesh->loop.now.tv_sec) {
132                         devtool_sptps_renewal_probe((meshlink_node_t *)c->node);
133
134                         if(!sptps_force_kex(&c->sptps)) {
135                                 logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for connection with %s failed", c->name);
136                                 terminate_connection(mesh, c, true);
137                                 continue;
138                         } else {
139                                 c->last_key_renewal = mesh->loop.now.tv_sec;
140                         }
141                 }
142
143                 if(c->last_ping_time + pingtimeout <= mesh->loop.now.tv_sec) {
144                         if(c->status.active) {
145                                 if(c->status.pinged) {
146                                         logger(mesh, MESHLINK_INFO, "%s didn't respond to PING in %ld seconds", c->name, (long)mesh->loop.now.tv_sec - c->last_ping_time);
147                                 } else if(c->last_ping_time + pinginterval <= mesh->loop.now.tv_sec) {
148                                         send_ping(mesh, c);
149                                         continue;
150                                 } else {
151                                         continue;
152                                 }
153                         } else {
154                                 if(c->status.connecting) {
155                                         logger(mesh, MESHLINK_WARNING, "Timeout while connecting to %s", c->name);
156                                 } else {
157                                         logger(mesh, MESHLINK_WARNING, "Timeout from %s during authentication", c->name);
158                                 }
159                         }
160
161                         terminate_connection(mesh, c, c->status.active);
162                 }
163         }
164
165         timeout_set(&mesh->loop, data, &(struct timespec) {
166                 1, prng(mesh, TIMER_FUDGE)
167         });
168 }
169
170 // devclass asc, last_successfull_connection desc
171 static int node_compare_devclass_asc_lsc_desc(const void *a, const void *b) {
172         const node_t *na = a, *nb = b;
173
174         if(na->devclass < nb->devclass) {
175                 return -1;
176         }
177
178         if(na->devclass > nb->devclass) {
179                 return 1;
180         }
181
182         if(na->last_successfull_connection == nb->last_successfull_connection) {
183                 return 0;
184         }
185
186         if(na->last_successfull_connection == 0 || na->last_successfull_connection > nb->last_successfull_connection) {
187                 return -1;
188         }
189
190         if(nb->last_successfull_connection == 0 || na->last_successfull_connection < nb->last_successfull_connection) {
191                 return 1;
192         }
193
194         if(na < nb) {
195                 return -1;
196         }
197
198         if(na > nb) {
199                 return 1;
200         }
201
202         return 0;
203 }
204
205 // last_successfull_connection desc
206 static int node_compare_lsc_desc(const void *a, const void *b) {
207         const node_t *na = a, *nb = b;
208
209         if(na->last_successfull_connection == nb->last_successfull_connection) {
210                 return 0;
211         }
212
213         if(na->last_successfull_connection == 0 || na->last_successfull_connection > nb->last_successfull_connection) {
214                 return -1;
215         }
216
217         if(nb->last_successfull_connection == 0 || na->last_successfull_connection < nb->last_successfull_connection) {
218                 return 1;
219         }
220
221         if(na < nb) {
222                 return -1;
223         }
224
225         if(na > nb) {
226                 return 1;
227         }
228
229         return 0;
230 }
231
232 // devclass desc
233 static int node_compare_devclass_desc(const void *a, const void *b) {
234         const node_t *na = a, *nb = b;
235
236         if(na->devclass < nb->devclass) {
237                 return -1;
238         }
239
240         if(na->devclass > nb->devclass) {
241                 return 1;
242         }
243
244         if(na < nb) {
245                 return -1;
246         }
247
248         if(na > nb) {
249                 return 1;
250         }
251
252         return 0;
253 }
254
255
256 /*
257
258 autoconnect()
259 {
260         timeout = 5
261
262         // find the best one for initial connect
263
264         if cur < min
265                 newcon =
266                         first from nodes
267                                 where dclass <= my.dclass and !connection and (timestamp - last_retry) > retry_timeout
268                                 order by dclass asc, last_connection desc
269                 if newcon
270                         timeout = 0
271                         goto connect
272
273
274         // find better nodes to connect to: in case we have less than min connections within [BACKBONE, i] and there are nodes which we are not connected to within the range
275
276         if min <= cur < max
277                 j = 0
278                 for i = BACKBONE to my.dclass
279                         j += count(from connections where node.dclass = i)
280                         if j < min
281                                 newcon =
282                                         first from nodes
283                                                 where dclass = i and !connection and (timestamp - last_retry) > retry_timeout
284                                                 order by last_connection desc
285                                 if newcon
286                                         goto connect
287                         else
288                                 break
289
290
291         // heal partitions
292
293         if min <= cur < max
294                 newcon =
295                         first from nodes
296                                 where dclass <= my.dclass and !reachable and (timestamp - last_retry) > retry_timeout
297                                 order by dclass asc, last_connection desc
298                 if newcon
299                         goto connect
300
301
302         // connect
303
304 connect:
305         if newcon
306                 connect newcon
307
308
309         // disconnect outgoing connections in case we have more than min connections within [BACKBONE, i] and there are nodes which we are connected to within the range [i, PORTABLE]
310
311         if min < cur <= max
312                 j = 0
313                 for i = BACKBONE to my.dclass
314                         j += count(from connections where node.dclass = i)
315                         if min < j
316                                 delcon =
317                                         first from nodes
318                                                 where dclass >= i and outgoing_connection
319                                                 order by dclass desc
320                                 if disconnect
321                                         goto disconnect
322                                 else
323                                         break
324
325
326         // disconnect connections in case we have more than enough connections
327
328         if max < cur
329                 delcon =
330                         first from nodes
331                                 where outgoing_connection
332                                 order by dclass desc
333                 goto disconnect
334
335         // disconnect
336
337 disconnect
338         if delcon
339                 disconnect delcon
340
341
342         // next iteration
343         next (timeout, autoconnect)
344
345 }
346
347 */
348
349
350 static void periodic_handler(event_loop_t *loop, void *data) {
351         meshlink_handle_t *mesh = loop->data;
352
353         /* Check if there are too many contradicting ADD_EDGE and DEL_EDGE messages.
354            This usually only happens when another node has the same Name as this node.
355            If so, sleep for a short while to prevent a storm of contradicting messages.
356         */
357
358         if(mesh->contradicting_del_edge > 100 && mesh->contradicting_add_edge > 100) {
359                 logger(mesh, MESHLINK_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", mesh->sleeptime);
360                 struct timespec ts = {mesh->sleeptime, 0};
361                 nanosleep(&ts, NULL);
362                 mesh->sleeptime *= 2;
363
364                 if(mesh->sleeptime < 0) {
365                         mesh->sleeptime = 3600;
366                 }
367         } else {
368                 mesh->sleeptime /= 2;
369
370                 if(mesh->sleeptime < 10) {
371                         mesh->sleeptime = 10;
372                 }
373         }
374
375         mesh->contradicting_add_edge = 0;
376         mesh->contradicting_del_edge = 0;
377
378         int timeout = default_timeout;
379
380         /* Check if we need to make or break connections. */
381
382         if(mesh->nodes->count > 1) {
383
384                 logger(mesh, MESHLINK_DEBUG, "--- autoconnect begin ---");
385
386                 int retry_timeout = min(mesh->nodes->count * default_timeout, 60);
387
388                 logger(mesh, MESHLINK_DEBUG, "* devclass = %d", mesh->devclass);
389                 logger(mesh, MESHLINK_DEBUG, "* nodes = %d", mesh->nodes->count);
390                 logger(mesh, MESHLINK_DEBUG, "* retry_timeout = %d", retry_timeout);
391
392
393                 // connect disconnect nodes
394
395                 node_t *connect_to = NULL;
396                 node_t *disconnect_from = NULL;
397
398
399                 // get cur_connects
400
401                 unsigned int cur_connects = 0;
402
403                 for list_each(connection_t, c, mesh->connections) {
404                         if(c->status.active) {
405                                 cur_connects += 1;
406                         }
407                 }
408
409                 logger(mesh, MESHLINK_DEBUG, "* cur_connects = %d", cur_connects);
410                 logger(mesh, MESHLINK_DEBUG, "* outgoings = %d", mesh->outgoings->count);
411
412                 // get min_connects and max_connects
413
414                 unsigned int min_connects = mesh->dev_class_traits[mesh->devclass].min_connects;
415                 unsigned int max_connects = mesh->dev_class_traits[mesh->devclass].max_connects;
416
417                 logger(mesh, MESHLINK_DEBUG, "* min_connects = %d", min_connects);
418                 logger(mesh, MESHLINK_DEBUG, "* max_connects = %d", max_connects);
419
420                 // find the best one for initial connect
421
422                 if(cur_connects < min_connects) {
423                         splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_lsc_desc, NULL);
424
425                         for splay_each(node_t, n, mesh->nodes) {
426                                 logger(mesh, MESHLINK_DEBUG, "* %s->devclass = %d", n->name, n->devclass);
427
428                                 if(n != mesh->self && n->devclass <= mesh->devclass && !n->connection && !n->status.blacklisted && (n->last_connect_try == 0 || (mesh->loop.now.tv_sec - n->last_connect_try) > retry_timeout)) {
429                                         splay_insert(nodes, n);
430                                 }
431                         }
432
433                         if(nodes->head) {
434                                 //timeout = 0;
435                                 connect_to = (node_t *)nodes->head->data;
436
437                                 logger(mesh, MESHLINK_DEBUG, "* found best one for initial connect: %s", connect_to->name);
438                         } else {
439                                 logger(mesh, MESHLINK_DEBUG, "* could not find node for initial connect");
440                         }
441
442                         splay_delete_tree(nodes);
443                 }
444
445
446                 // find better nodes to connect to
447
448                 if(!connect_to && min_connects <= cur_connects && cur_connects < max_connects) {
449                         unsigned int connects = 0;
450
451                         for(dev_class_t devclass = 0; devclass <= mesh->devclass; ++devclass) {
452                                 for list_each(connection_t, c, mesh->connections) {
453                                         if(c->status.active && c->node && c->node->devclass == devclass) {
454                                                 connects += 1;
455                                         }
456                                 }
457
458                                 if(connects < min_connects) {
459                                         splay_tree_t *nodes = splay_alloc_tree(node_compare_lsc_desc, NULL);
460
461                                         for splay_each(node_t, n, mesh->nodes) {
462                                                 if(n != mesh->self && n->devclass == devclass && !n->connection && !n->status.blacklisted && (n->last_connect_try == 0 || (mesh->loop.now.tv_sec - n->last_connect_try) > retry_timeout)) {
463                                                         splay_insert(nodes, n);
464                                                 }
465                                         }
466
467                                         if(nodes->head) {
468                                                 logger(mesh, MESHLINK_DEBUG, "* found better node");
469                                                 connect_to = (node_t *)nodes->head->data;
470
471                                                 splay_delete_tree(nodes);
472                                                 break;
473                                         }
474
475                                         splay_delete_tree(nodes);
476                                 } else {
477                                         break;
478                                 }
479                         }
480
481                         if(!connect_to) {
482                                 logger(mesh, MESHLINK_DEBUG, "* could not find better nodes");
483                         }
484                 }
485
486
487                 // heal partitions
488
489                 if(!connect_to && min_connects <= cur_connects && cur_connects < max_connects) {
490                         splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_asc_lsc_desc, NULL);
491
492                         for splay_each(node_t, n, mesh->nodes) {
493                                 if(n != mesh->self && n->devclass <= mesh->devclass && !n->status.reachable && !n->status.blacklisted && (n->last_connect_try == 0 || (mesh->loop.now.tv_sec - n->last_connect_try) > retry_timeout)) {
494                                         splay_insert(nodes, n);
495                                 }
496                         }
497
498                         if(nodes->head) {
499                                 logger(mesh, MESHLINK_DEBUG, "* try to heal partition");
500                                 connect_to = (node_t *)nodes->head->data;
501                         } else {
502                                 logger(mesh, MESHLINK_DEBUG, "* could not find nodes for partition healing");
503                         }
504
505                         splay_delete_tree(nodes);
506                 }
507
508
509                 // perform connect
510
511                 if(connect_to && !connect_to->connection) {
512                         connect_to->last_connect_try = mesh->loop.now.tv_sec;
513                         logger(mesh, MESHLINK_DEBUG, "Autoconnect trying to connect to %s", connect_to->name);
514
515                         /* check if there is already a connection attempt to this node */
516                         bool skip = false;
517
518                         for list_each(outgoing_t, outgoing, mesh->outgoings) {
519                                 if(outgoing->node == connect_to) {
520                                         logger(mesh, MESHLINK_DEBUG, "* skip autoconnect since it is an outgoing connection already");
521                                         skip = true;
522                                         break;
523                                 }
524                         }
525
526                         if(!connect_to->status.reachable && !node_read_public_key(mesh, connect_to)) {
527                                 logger(mesh, MESHLINK_DEBUG, "* skip autoconnect since we don't know this node's public key");
528                                 skip = true;
529                         }
530
531                         if(!skip) {
532                                 logger(mesh, MESHLINK_DEBUG, "Autoconnecting to %s", connect_to->name);
533                                 outgoing_t *outgoing = xzalloc(sizeof(outgoing_t));
534                                 outgoing->node = connect_to;
535                                 list_insert_tail(mesh->outgoings, outgoing);
536                                 setup_outgoing_connection(mesh, outgoing);
537                         }
538                 }
539
540
541                 // disconnect suboptimal outgoing connections
542
543                 if(min_connects < cur_connects /*&& cur_connects <= max_connects*/) {
544                         unsigned int connects = 0;
545
546                         for(dev_class_t devclass = 0; devclass <= mesh->devclass; ++devclass) {
547                                 for list_each(connection_t, c, mesh->connections) {
548                                         if(c->status.active && c->node && c->node->devclass == devclass) {
549                                                 connects += 1;
550                                         }
551                                 }
552
553                                 if(min_connects < connects) {
554                                         splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_desc, NULL);
555
556                                         for list_each(connection_t, c, mesh->connections) {
557                                                 if(c->outgoing && c->node && c->node->devclass >= devclass) {
558                                                         splay_insert(nodes, c->node);
559                                                 }
560                                         }
561
562                                         if(nodes->head) {
563                                                 logger(mesh, MESHLINK_DEBUG, "* disconnect suboptimal outgoing connection");
564                                                 disconnect_from = (node_t *)nodes->head->data;
565                                         }
566
567                                         splay_delete_tree(nodes);
568                                         break;
569                                 }
570                         }
571
572                         if(!disconnect_from) {
573                                 logger(mesh, MESHLINK_DEBUG, "* no suboptimal outgoing connections");
574                         }
575                 }
576
577
578                 // disconnect connections (too many connections)
579
580                 if(!disconnect_from && max_connects < cur_connects) {
581                         splay_tree_t *nodes = splay_alloc_tree(node_compare_devclass_desc, NULL);
582
583                         for list_each(connection_t, c, mesh->connections) {
584                                 if(c->status.active && c->node) {
585                                         splay_insert(nodes, c->node);
586                                 }
587                         }
588
589                         if(nodes->head) {
590                                 logger(mesh, MESHLINK_DEBUG, "* disconnect connection (too many connections)");
591
592                                 //timeout = 0;
593                                 disconnect_from = (node_t *)nodes->head->data;
594                         } else {
595                                 logger(mesh, MESHLINK_DEBUG, "* no node we want to disconnect, even though we have too many connections");
596                         }
597
598                         splay_delete_tree(nodes);
599                 }
600
601
602                 // perform disconnect
603
604                 if(disconnect_from && disconnect_from->connection) {
605                         logger(mesh, MESHLINK_DEBUG, "Autodisconnecting from %s", disconnect_from->connection->name);
606                         list_delete(mesh->outgoings, disconnect_from->connection->outgoing);
607                         disconnect_from->connection->outgoing = NULL;
608                         terminate_connection(mesh, disconnect_from->connection, disconnect_from->connection->status.active);
609                 }
610
611                 // reduce timeout if we don't have enough connections + outgoings
612                 if(cur_connects + mesh->outgoings->count < 3) {
613                         timeout = 1;
614                 }
615
616                 // done!
617
618                 logger(mesh, MESHLINK_DEBUG, "--- autoconnect end ---");
619         }
620
621         for splay_each(node_t, n, mesh->nodes) {
622                 if(n->status.dirty) {
623                         if(!node_write_config(mesh, n)) {
624                                 logger(mesh, MESHLINK_DEBUG, "Could not update %s", n->name);
625                         }
626
627                         n->status.dirty = false;
628                 }
629
630                 if(n->status.validkey && n->last_req_key + 3600 < mesh->loop.now.tv_sec) {
631                         logger(mesh, MESHLINK_DEBUG, "SPTPS key renewal for node %s", n->name);
632                         devtool_sptps_renewal_probe((meshlink_node_t *)n);
633
634                         if(!sptps_force_kex(&n->sptps)) {
635                                 logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for node %s failed", n->name);
636                                 n->status.validkey = false;
637                                 sptps_stop(&n->sptps);
638                                 n->status.waitingforkey = false;
639                                 n->last_req_key = -3600;
640                         } else {
641                                 n->last_req_key = mesh->loop.now.tv_sec;
642                         }
643                 }
644         }
645
646         timeout_set(&mesh->loop, data, &(struct timespec) {
647                 timeout, prng(mesh, TIMER_FUDGE)
648         });
649 }
650
651 void handle_meta_connection_data(meshlink_handle_t *mesh, connection_t *c) {
652         if(!receive_meta(mesh, c)) {
653                 terminate_connection(mesh, c, c->status.active);
654                 return;
655         }
656 }
657
658 void retry(meshlink_handle_t *mesh) {
659         /* Reset the reconnection timers for all outgoing connections */
660         for list_each(outgoing_t, outgoing, mesh->outgoings) {
661                 outgoing->timeout = 0;
662
663                 if(outgoing->ev.cb) {
664                         timeout_set(&mesh->loop, &outgoing->ev, &(struct timespec) {
665                                 0, 0
666                         });
667                 }
668         }
669
670         /* For active connections, check if their addresses are still valid.
671          * If yes, reset their ping timers, otherwise terminate them. */
672         for list_each(connection_t, c, mesh->connections) {
673                 if(!c->status.active) {
674                         continue;
675                 }
676
677                 if(!c->status.pinged) {
678                         c->last_ping_time = -3600;
679                 }
680
681                 sockaddr_t sa;
682                 socklen_t salen = sizeof(sa);
683
684                 if(getsockname(c->socket, &sa.sa, &salen)) {
685                         continue;
686                 }
687
688                 switch(sa.sa.sa_family) {
689                 case AF_INET:
690                         sa.in.sin_port = 0;
691                         break;
692
693                 case AF_INET6:
694                         sa.in6.sin6_port = 0;
695                         break;
696
697                 default:
698                         continue;
699                 }
700
701                 int sock = socket(sa.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
702
703                 if(sock != -1) {
704                         continue;
705                 }
706
707                 if(bind(sock, &sa.sa, salen) && errno == EADDRNOTAVAIL) {
708                         logger(mesh, MESHLINK_DEBUG, "Local address for connection to %s no longer valid, terminating", c->name);
709                         terminate_connection(mesh, c, c->status.active);
710                 }
711
712                 closesocket(sock);
713         }
714
715         /* Kick the ping timeout handler */
716         timeout_set(&mesh->loop, &mesh->pingtimer, &(struct timespec) {
717                 0, 0
718         });
719 }
720
721 /*
722   this is where it all happens...
723 */
724 void main_loop(meshlink_handle_t *mesh) {
725         timeout_add(&mesh->loop, &mesh->pingtimer, timeout_handler, &mesh->pingtimer, &(struct timespec) {
726                 1, prng(mesh, TIMER_FUDGE)
727         });
728         timeout_add(&mesh->loop, &mesh->periodictimer, periodic_handler, &mesh->periodictimer, &(struct timespec) {
729                 0, 0
730         });
731
732         //Add signal handler
733         mesh->datafromapp.signum = 0;
734         signal_add(&mesh->loop, &mesh->datafromapp, meshlink_send_from_queue, mesh, mesh->datafromapp.signum);
735
736         if(!event_loop_run(&mesh->loop, &mesh->mutex)) {
737                 logger(mesh, MESHLINK_ERROR, "Error while waiting for input: %s", strerror(errno));
738                 call_error_cb(mesh, MESHLINK_ENETWORK);
739         }
740
741         signal_del(&mesh->loop, &mesh->datafromapp);
742         timeout_del(&mesh->loop, &mesh->periodictimer);
743         timeout_del(&mesh->loop, &mesh->pingtimer);
744 }