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