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