2 This file is part of GNUnet.
3 (C) 2001-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file mesh/gnunet-service-mesh_connection.c
23 * @brief GNUnet MESH service connection handling
24 * @author Bartlomiej Polot
28 #include "gnunet_util_lib.h"
30 #include "gnunet_statistics_service.h"
32 #include "mesh_path.h"
33 #include "mesh_protocol_enc.h"
35 #include "gnunet-service-mesh_connection.h"
36 #include "gnunet-service-mesh_peer.h"
37 #include "gnunet-service-mesh_tunnel.h"
40 #define LOG(level, ...) GNUNET_log_from (level,"mesh-con",__VA_ARGS__)
42 #define MESH_MAX_POLL_TIME GNUNET_TIME_relative_multiply (\
43 GNUNET_TIME_UNIT_MINUTES,\
48 /******************************************************************************/
49 /******************************** STRUCTS **********************************/
50 /******************************************************************************/
53 * Struct to encapsulate all the Flow Control information to a peer to which
54 * we are directly connected (on a core level).
56 struct MeshFlowControl
59 * Connection this controls.
61 struct MeshConnection *c;
64 * How many messages are in the queue on this connection.
69 * How many messages do we accept in the queue.
71 unsigned int queue_max;
79 * ID of the last packet sent towards the peer.
81 uint32_t last_pid_sent;
84 * ID of the last packet received from the peer.
86 uint32_t last_pid_recv;
89 * Last ACK sent to the peer (peer can't send more than this PID).
91 uint32_t last_ack_sent;
94 * Last ACK sent towards the origin (for traffic towards leaf node).
96 uint32_t last_ack_recv;
99 * Task to poll the peer in case of a lost ACK causes stall.
101 GNUNET_SCHEDULER_TaskIdentifier poll_task;
104 * How frequently to poll for ACKs.
106 struct GNUNET_TIME_Relative poll_time;
109 * Queued poll message, to cancel if not necessary anymore (got ACK).
111 struct MeshConnectionQueue *poll_msg;
114 * Queued poll message, to cancel if not necessary anymore (got ACK).
116 struct MeshConnectionQueue *ack_msg;
120 * Keep a record of the last messages sent on this connection.
122 struct MeshConnectionPerformance
125 * Circular buffer for storing measurements.
127 double usecsperbyte[AVG_MSGS];
130 * Running average of @c usecsperbyte.
135 * How many values of @c usecsperbyte are valid.
140 * Index of the next "free" position in @c usecsperbyte.
147 * Struct containing all information regarding a connection to a peer.
149 struct MeshConnection
152 * Tunnel this connection is part of.
154 struct MeshTunnel3 *t;
157 * Flow control information for traffic fwd.
159 struct MeshFlowControl fwd_fc;
162 * Flow control information for traffic bck.
164 struct MeshFlowControl bck_fc;
167 * Measure connection performance on the endpoint.
169 struct MeshConnectionPerformance *perf;
172 * ID of the connection.
174 struct GNUNET_HashCode id;
177 * State of the connection.
179 enum MeshConnectionState state;
182 * Path being used for the tunnel.
184 struct MeshPeerPath *path;
187 * Position of the local peer in the path.
189 unsigned int own_pos;
192 * Task to keep the used paths alive at the owner,
193 * time tunnel out on all the other peers.
195 GNUNET_SCHEDULER_TaskIdentifier fwd_maintenance_task;
198 * Task to keep the used paths alive at the destination,
199 * time tunnel out on all the other peers.
201 GNUNET_SCHEDULER_TaskIdentifier bck_maintenance_task;
204 * Pending message count.
206 int pending_messages;
209 * Destroy flag: if true, destroy on last message.
215 * Handle for messages queued but not yet sent.
217 struct MeshConnectionQueue
219 struct MeshPeerQueue *q;
224 /******************************************************************************/
225 /******************************* GLOBALS ***********************************/
226 /******************************************************************************/
229 * Global handle to the statistics service.
231 extern struct GNUNET_STATISTICS_Handle *stats;
234 * Local peer own ID (memory efficient handle).
236 extern GNUNET_PEER_Id myid;
239 * Local peer own ID (full value).
241 extern struct GNUNET_PeerIdentity my_full_id;
244 * Connections known, indexed by cid (MeshConnection).
246 static struct GNUNET_CONTAINER_MultiHashMap *connections;
249 * How many connections are we willing to maintain.
250 * Local connections are always allowed, even if there are more connections than max.
252 static unsigned long long max_connections;
255 * How many messages *in total* are we willing to queue, divide by number of
256 * connections to get connection queue size.
258 static unsigned long long max_msgs_queue;
261 * How often to send path keepalives. Paths timeout after 4 missed.
263 static struct GNUNET_TIME_Relative refresh_connection_time;
266 /******************************************************************************/
267 /******************************** STATIC ***********************************/
268 /******************************************************************************/
270 #if 0 // avoid compiler warning for unused static function
272 fc_debug (struct MeshFlowControl *fc)
274 LOG (GNUNET_ERROR_TYPE_DEBUG, " IN: %u/%u\n",
275 fc->last_pid_recv, fc->last_ack_sent);
276 LOG (GNUNET_ERROR_TYPE_DEBUG, " OUT: %u/%u\n",
277 fc->last_pid_sent, fc->last_ack_recv);
278 LOG (GNUNET_ERROR_TYPE_DEBUG, " QUEUE: %u/%u\n",
279 fc->queue_n, fc->queue_max);
283 connection_debug (struct MeshConnection *c)
287 LOG (GNUNET_ERROR_TYPE_DEBUG, "*** DEBUG NULL CONNECTION ***\n");
290 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connection %s:%X\n",
291 peer2s (c->t->peer), GMC_2s (c));
292 LOG (GNUNET_ERROR_TYPE_DEBUG, " state: %u, pending msgs: %u\n",
293 c->state, c->pending_messages);
294 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD FC\n");
295 fc_debug (&c->fwd_fc);
296 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK FC\n");
297 fc_debug (&c->bck_fc);
302 * Get string description for tunnel state.
304 * @param s Tunnel state.
306 * @return String representation.
309 GMC_state2s (enum MeshConnectionState s)
313 case MESH_CONNECTION_NEW:
314 return "MESH_CONNECTION_NEW";
315 case MESH_CONNECTION_SENT:
316 return "MESH_CONNECTION_SENT";
317 case MESH_CONNECTION_ACK:
318 return "MESH_CONNECTION_ACK";
319 case MESH_CONNECTION_READY:
320 return "MESH_CONNECTION_READY";
322 return "MESH_CONNECTION_STATE_ERROR";
328 * Initialize a Flow Control structure to the initial state.
330 * @param fc Flow Control structure to initialize.
333 fc_init (struct MeshFlowControl *fc)
336 fc->last_pid_sent = (uint32_t) -1; /* Next (expected) = 0 */
337 fc->last_pid_recv = (uint32_t) -1;
338 fc->last_ack_sent = (uint32_t) 0;
339 fc->last_ack_recv = (uint32_t) 0;
340 fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
341 fc->poll_time = GNUNET_TIME_UNIT_SECONDS;
343 fc->queue_max = (max_msgs_queue / max_connections) + 1;
350 * @param cid Connection ID.
352 static struct MeshConnection *
353 connection_get (const struct GNUNET_HashCode *cid)
355 return GNUNET_CONTAINER_multihashmap_get (connections, cid);
360 connection_change_state (struct MeshConnection* c,
361 enum MeshConnectionState state)
363 LOG (GNUNET_ERROR_TYPE_DEBUG,
364 "Connection %s state was %s\n",
365 GMC_2s (c), GMC_state2s (c->state));
366 LOG (GNUNET_ERROR_TYPE_DEBUG,
367 "Connection %s state is now %s\n",
368 GMC_2s (c), GMC_state2s (state));
374 * Callback called when a queued ACK message is sent.
376 * @param cls Closure (FC).
377 * @param c Connection this message was on.
378 * @param type Type of message sent.
379 * @param fwd Was this a FWD going message?
380 * @param size Size of the message.
384 struct MeshConnection *c,
385 struct MeshConnectionQueue *q,
386 uint16_t type, int fwd, size_t size)
388 struct MeshFlowControl *fc = cls;
395 * Send an ACK on the connection, informing the predecessor about
396 * the available buffer space. Should not be called in case the peer
397 * is origin (no predecessor) in the @c fwd direction.
399 * Note that for fwd ack, the FWD mean forward *traffic* (root->dest),
400 * the ACK itself goes "back" (dest->root).
402 * @param c Connection on which to send the ACK.
403 * @param buffer How much space free to advertise?
404 * @param fwd Is this FWD ACK? (Going dest -> root)
405 * @param force Don't optimize out.
408 send_ack (struct MeshConnection *c, unsigned int buffer, int fwd, int force)
410 struct MeshFlowControl *next_fc;
411 struct MeshFlowControl *prev_fc;
412 struct GNUNET_MESH_ACK msg;
416 /* If origin, there is no connection to send ACKs. Wrong function! */
417 if (GMC_is_origin (c, fwd))
423 next_fc = fwd ? &c->fwd_fc : &c->bck_fc;
424 prev_fc = fwd ? &c->bck_fc : &c->fwd_fc;
426 LOG (GNUNET_ERROR_TYPE_DEBUG,
427 "connection send %s ack on %s\n",
428 fwd ? "FWD" : "BCK", GMC_2s (c));
430 /* Check if we need to transmit the ACK. */
431 delta = prev_fc->last_ack_sent - prev_fc->last_pid_recv;
432 if (3 < delta && buffer < delta && GNUNET_NO == force)
434 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer > 3\n");
435 LOG (GNUNET_ERROR_TYPE_DEBUG,
436 " last pid recv: %u, last ack sent: %u\n",
437 prev_fc->last_pid_recv, prev_fc->last_ack_sent);
441 /* Ok, ACK might be necessary, what PID to ACK? */
442 ack = prev_fc->last_pid_recv + buffer;
443 LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack);
444 LOG (GNUNET_ERROR_TYPE_DEBUG,
445 " last pid %u, last ack %u, qmax %u, q %u\n",
446 prev_fc->last_pid_recv, prev_fc->last_ack_sent,
447 next_fc->queue_max, next_fc->queue_n);
448 if (ack == prev_fc->last_ack_sent && GNUNET_NO == force)
450 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n");
454 /* Check if message is already in queue */
455 if (NULL != prev_fc->ack_msg)
457 if (GMC_is_pid_bigger (ack, prev_fc->last_ack_sent))
459 LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n");
460 GMC_cancel (prev_fc->ack_msg);
461 /* GMC_cancel triggers ack_sent(), which clears fc->ack_msg */
465 LOG (GNUNET_ERROR_TYPE_DEBUG, " same ACK already in queue\n");
470 prev_fc->last_ack_sent = ack;
472 /* Build ACK message and send on connection */
473 msg.header.size = htons (sizeof (msg));
474 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK);
475 msg.ack = htonl (ack);
478 prev_fc->ack_msg = GMC_send_prebuilt_message (&msg.header, c, !fwd,
484 * Callback called when a queued message is sent.
486 * Calculates the average time and connection packet tracking.
488 * @param cls Closure (ConnectionQueue Handle).
489 * @param c Connection this message was on.
490 * @param type Type of message sent.
491 * @param fwd Was this a FWD going message?
492 * @param size Size of the message.
493 * @param wait Time spent waiting for core (only the time for THIS message)
496 message_sent (void *cls,
497 struct MeshConnection *c, uint16_t type,
498 int fwd, size_t size,
499 struct GNUNET_TIME_Relative wait)
501 struct MeshConnectionPerformance *p;
502 struct MeshFlowControl *fc;
503 struct MeshConnectionQueue *q = cls;
506 fc = fwd ? &c->fwd_fc : &c->bck_fc;
507 LOG (GNUNET_ERROR_TYPE_DEBUG, "! sent %s\n", GNUNET_MESH_DEBUG_M2S (type));
508 LOG (GNUNET_ERROR_TYPE_DEBUG, "! C_P- %p %u\n", c, c->pending_messages);
513 LOG (GNUNET_ERROR_TYPE_DEBUG, "! calling cont\n");
514 q->cont (q->cont_cls, c, q, type, fwd, size);
518 c->pending_messages--;
519 if (GNUNET_YES == c->destroy && 0 == c->pending_messages)
521 LOG (GNUNET_ERROR_TYPE_DEBUG, "! destroying connection!\n");
525 /* Send ACK if needed, after accounting for sent ID in fc->queue_n */
528 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
530 LOG (GNUNET_ERROR_TYPE_DEBUG, "! Q_N- %p %u\n", fc, fc->queue_n);
532 LOG (GNUNET_ERROR_TYPE_DEBUG,
533 "! accounting pid %u\n",
535 GMC_send_ack (c, fwd, GNUNET_NO);
538 case GNUNET_MESSAGE_TYPE_MESH_POLL:
542 case GNUNET_MESSAGE_TYPE_MESH_ACK:
549 LOG (GNUNET_ERROR_TYPE_DEBUG, "! message sent!\n");
552 return; /* Only endpoints are interested in timing. */
555 usecsperbyte = ((double) wait.rel_value_us) / size;
556 if (p->size == AVG_MSGS)
558 /* Array is full. Substract oldest value, add new one and store. */
559 p->avg -= (p->usecsperbyte[p->idx] / AVG_MSGS);
560 p->usecsperbyte[p->idx] = usecsperbyte;
561 p->avg += (p->usecsperbyte[p->idx] / AVG_MSGS);
565 /* Array not yet full. Add current value to avg and store. */
566 p->usecsperbyte[p->idx] = usecsperbyte;
568 p->avg += p->usecsperbyte[p->idx];
572 p->idx = (p->idx + 1) % AVG_MSGS;
577 * Get the previous hop in a connection
579 * @param c Connection.
581 * @return Previous peer in the connection.
583 static struct MeshPeer *
584 get_prev_hop (const struct MeshConnection *c)
588 LOG (GNUNET_ERROR_TYPE_DEBUG, "Get prev hop, own pos %u\n", c->own_pos);
589 if (0 == c->own_pos || c->path->length < 2)
590 id = c->path->peers[0];
592 id = c->path->peers[c->own_pos - 1];
594 return GMP_get_short (id);
599 * Get the next hop in a connection
601 * @param c Connection.
603 * @return Next peer in the connection.
605 static struct MeshPeer *
606 get_next_hop (const struct MeshConnection *c)
610 if ((c->path->length - 1) == c->own_pos || c->path->length < 2)
611 id = c->path->peers[c->path->length - 1];
613 id = c->path->peers[c->own_pos + 1];
615 return GMP_get_short (id);
620 * Get the hop in a connection.
622 * @param c Connection.
623 * @param fwd Next hop?
625 * @return Next peer in the connection.
627 static struct MeshPeer *
628 get_hop (struct MeshConnection *c, int fwd)
631 return get_next_hop (c);
632 return get_prev_hop (c);
637 * Is traffic coming from this sender 'FWD' traffic?
639 * @param c Connection to check.
640 * @param sender Peer identity of neighbor.
642 * @return #GNUNET_YES in case the sender is the 'prev' hop and therefore
643 * the traffic is 'FWD'.
644 * #GNUNET_NO for BCK.
645 * #GNUNET_SYSERR for errors.
648 is_fwd (const struct MeshConnection *c,
649 const struct GNUNET_PeerIdentity *sender)
653 id = GNUNET_PEER_search (sender);
654 if (GMP_get_short_id (get_prev_hop (c)) == id)
657 if (GMP_get_short_id (get_next_hop (c)) == id)
661 return GNUNET_SYSERR;
666 * Sends a CONNECTION ACK message in reponse to a received CONNECTION_CREATE
667 * or a first CONNECTION_ACK directed to us.
669 * @param connection Connection to confirm.
670 * @param fwd Should we send it FWD? (root->dest)
671 * (First (~SYNACK) goes BCK, second (~ACK) goes FWD)
674 send_connection_ack (struct MeshConnection *connection, int fwd)
676 struct MeshTunnel3 *t;
679 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection %s ACK\n",
680 !fwd ? "FWD" : "BCK");
681 GMP_queue_add (get_hop (connection, fwd), NULL,
682 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
683 sizeof (struct GNUNET_MESH_ConnectionACK),
684 connection, fwd, &message_sent, NULL);
685 connection->pending_messages++;
686 if (MESH_TUNNEL3_NEW == GMT_get_state (t))
687 GMT_change_state (t, MESH_TUNNEL3_WAITING);
688 if (MESH_CONNECTION_READY != connection->state)
689 connection_change_state (connection, MESH_CONNECTION_SENT);
694 * Send a notification that a connection is broken.
696 * @param c Connection that is broken.
697 * @param id1 Peer that has disconnected.
698 * @param id2 Peer that has disconnected.
699 * @param fwd Direction towards which to send it.
702 send_broken (struct MeshConnection *c,
703 const struct GNUNET_PeerIdentity *id1,
704 const struct GNUNET_PeerIdentity *id2,
707 struct GNUNET_MESH_ConnectionBroken msg;
709 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
710 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN);
714 GMC_send_prebuilt_message (&msg.header, c, fwd, NULL, NULL);
720 * Send keepalive packets for a connection.
722 * @param c Connection to keep alive..
723 * @param fwd Is this a FWD keepalive? (owner -> dest).
726 connection_keepalive (struct MeshConnection *c, int fwd)
728 struct GNUNET_MESH_ConnectionKeepAlive *msg;
729 size_t size = sizeof (struct GNUNET_MESH_ConnectionKeepAlive);
733 type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE :
734 GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE;
736 LOG (GNUNET_ERROR_TYPE_DEBUG,
737 "sending %s keepalive for connection %s]\n",
738 fwd ? "FWD" : "BCK", GMC_2s (c));
740 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf;
741 msg->header.size = htons (size);
742 msg->header.type = htons (type);
745 GMC_send_prebuilt_message (&msg->header, c, fwd, NULL, NULL);
750 * Send CONNECTION_{CREATE/ACK} packets for a connection.
752 * @param c Connection for which to send the message.
753 * @param fwd If #GNUNET_YES, send CREATE, otherwise send ACK.
756 connection_recreate (struct MeshConnection *c, int fwd)
758 LOG (GNUNET_ERROR_TYPE_DEBUG, "sending connection recreate\n");
762 send_connection_ack (c, GNUNET_NO);
767 * Generic connection timer management.
768 * Depending on the role of the peer in the connection will send the
769 * appropriate message (build or keepalive)
771 * @param c Conncetion to maintain.
775 connection_maintain (struct MeshConnection *c, int fwd)
777 if (MESH_TUNNEL3_SEARCHING == GMT_get_state (c->t))
779 /* TODO DHT GET with RO_BART */
784 case MESH_CONNECTION_NEW:
786 case MESH_CONNECTION_SENT:
787 connection_recreate (c, fwd);
789 case MESH_CONNECTION_READY:
790 connection_keepalive (c, fwd);
799 connection_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
801 struct MeshConnection *c = cls;
803 c->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
804 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
807 connection_maintain (c, GNUNET_YES);
808 c->fwd_maintenance_task = GNUNET_SCHEDULER_add_delayed (refresh_connection_time,
809 &connection_fwd_keepalive,
815 connection_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
817 struct MeshConnection *c = cls;
819 c->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
820 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
823 connection_maintain (c, GNUNET_NO);
824 c->bck_maintenance_task = GNUNET_SCHEDULER_add_delayed (refresh_connection_time,
825 &connection_bck_keepalive,
831 * @brief Re-initiate traffic on this connection if necessary.
833 * Check if there is traffic queued towards this peer
834 * and the core transmit handle is NULL (traffic was stalled).
835 * If so, call core tmt rdy.
837 * @param c Connection on which initiate traffic.
838 * @param fwd Is this about fwd traffic?
841 connection_unlock_queue (struct MeshConnection *c, int fwd)
843 struct MeshPeer *peer;
845 LOG (GNUNET_ERROR_TYPE_DEBUG,
846 "connection_unlock_queue %s on %s\n",
847 fwd ? "FWD" : "BCK", GMC_2s (c));
849 if (GMC_is_terminal (c, fwd))
851 LOG (GNUNET_ERROR_TYPE_DEBUG, " is terminal!\n");
855 peer = get_hop (c, fwd);
856 GMP_queue_unlock (peer, c);
861 * Cancel all transmissions that belong to a certain connection.
863 * If the connection is scheduled for destruction and no more messages are left,
864 * the connection will be destroyed by the continuation call.
866 * @param c Connection which to cancel. Might be destroyed during this call.
867 * @param fwd Cancel fwd traffic?
870 connection_cancel_queues (struct MeshConnection *c, int fwd)
872 struct MeshFlowControl *fc;
873 struct MeshPeer *peer;
881 fc = fwd ? &c->fwd_fc : &c->bck_fc;
882 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task)
884 GNUNET_SCHEDULER_cancel (fc->poll_task);
885 fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
887 peer = get_hop (c, fwd);
888 GMP_queue_cancel (peer, c);
893 * Function called if a connection has been stalled for a while,
894 * possibly due to a missed ACK. Poll the neighbor about its ACK status.
896 * @param cls Closure (poll ctx).
897 * @param tc TaskContext.
900 connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
904 * Callback called when a queued POLL message is sent.
906 * @param cls Closure (FC).
907 * @param c Connection this message was on.
908 * @param type Type of message sent.
909 * @param fwd Was this a FWD going message?
910 * @param size Size of the message.
913 poll_sent (void *cls,
914 struct MeshConnection *c,
915 struct MeshConnectionQueue *q,
916 uint16_t type, int fwd, size_t size)
918 struct MeshFlowControl *fc = cls;
920 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL sent, scheduling new one!\n");
922 fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time);
923 fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
924 &connection_poll, fc);
928 * Function called if a connection has been stalled for a while,
929 * possibly due to a missed ACK. Poll the neighbor about its ACK status.
931 * @param cls Closure (poll ctx).
932 * @param tc TaskContext.
935 connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
937 struct MeshFlowControl *fc = cls;
938 struct GNUNET_MESH_Poll msg;
939 struct MeshConnection *c;
941 fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
942 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
948 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** Polling!\n");
949 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** connection [%s]\n", GMC_2s (c));
950 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** %s\n",
951 fc == &c->fwd_fc ? "FWD" : "BCK");
953 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL);
954 msg.header.size = htons (sizeof (msg));
955 msg.pid = htonl (fc->last_pid_sent);
956 LOG (GNUNET_ERROR_TYPE_DEBUG, " *** last pid sent: %u!\n", fc->last_pid_sent);
957 fc->poll_msg = GMC_send_prebuilt_message (&msg.header, c, fc == &c->fwd_fc,
963 * Timeout function due to lack of keepalive/traffic from the owner.
964 * Destroys connection if called.
966 * @param cls Closure (connection to destroy).
967 * @param tc TaskContext.
970 connection_fwd_timeout (void *cls,
971 const struct GNUNET_SCHEDULER_TaskContext *tc)
973 struct MeshConnection *c = cls;
975 c->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
976 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
978 LOG (GNUNET_ERROR_TYPE_DEBUG,
979 "Connection %s[%X] FWD timed out. Destroying.\n",
983 if (GMC_is_origin (c, GNUNET_YES)) /* If local, leave. */
991 * Timeout function due to lack of keepalive/traffic from the destination.
992 * Destroys connection if called.
994 * @param cls Closure (connection to destroy).
995 * @param tc TaskContext
998 connection_bck_timeout (void *cls,
999 const struct GNUNET_SCHEDULER_TaskContext *tc)
1001 struct MeshConnection *c = cls;
1003 c->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
1004 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1007 LOG (GNUNET_ERROR_TYPE_DEBUG,
1008 "Connection %s[%X] FWD timed out. Destroying.\n",
1009 GMT_2s (c->t), c->id);
1011 if (GMC_is_origin (c, GNUNET_NO)) /* If local, leave. */
1019 * Resets the connection timeout task, some other message has done the
1021 * - For the first peer on the direction this means to send
1022 * a keepalive or a path confirmation message (either create or ACK).
1023 * - For all other peers, this means to destroy the connection,
1024 * due to lack of activity.
1025 * Starts the tiemout if no timeout was running (connection just created).
1027 * @param c Connection whose timeout to reset.
1028 * @param fwd Is this forward?
1030 * TODO use heap to improve efficiency of scheduler.
1033 connection_reset_timeout (struct MeshConnection *c, int fwd)
1035 GNUNET_SCHEDULER_TaskIdentifier *ti;
1036 GNUNET_SCHEDULER_Task f;
1038 ti = fwd ? &c->fwd_maintenance_task : &c->bck_maintenance_task;
1040 if (GNUNET_SCHEDULER_NO_TASK != *ti)
1041 GNUNET_SCHEDULER_cancel (*ti);
1043 if (GMC_is_origin (c, fwd)) /* Endpoint */
1045 f = fwd ? &connection_fwd_keepalive : &connection_bck_keepalive;
1046 *ti = GNUNET_SCHEDULER_add_delayed (refresh_connection_time, f, c);
1050 struct GNUNET_TIME_Relative delay;
1052 delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 4);
1053 f = fwd ? &connection_fwd_timeout : &connection_bck_timeout;
1054 *ti = GNUNET_SCHEDULER_add_delayed (delay, f, c);
1060 * Add the connection to the list of both neighbors.
1062 * @param c Connection.
1065 register_neighbors (struct MeshConnection *c)
1067 struct MeshPeer *peer;
1069 peer = get_next_hop (c);
1070 if (GNUNET_NO == GMP_is_neighbor (peer))
1075 GMP_add_connection (peer, c);
1076 peer = get_prev_hop (c);
1077 if (GNUNET_NO == GMP_is_neighbor (peer))
1082 GMP_add_connection (peer, c);
1087 * Remove the connection from the list of both neighbors.
1089 * @param c Connection.
1092 unregister_neighbors (struct MeshConnection *c)
1094 struct MeshPeer *peer;
1096 peer = get_next_hop (c);
1097 GMP_remove_connection (peer, c);
1099 peer = get_prev_hop (c);
1100 GMP_remove_connection (peer, c);
1106 * Bind the connection to the peer and the tunnel to that peer.
1108 * If the peer has no tunnel, create one. Update tunnel and connection
1109 * data structres to reflect new status.
1111 * @param c Connection.
1115 add_to_peer (struct MeshConnection *c, struct MeshPeer *peer)
1117 GMP_add_tunnel (peer);
1118 c->t = GMP_get_tunnel (peer);
1119 GMT_add_connection (c->t, c);
1122 /******************************************************************************/
1123 /******************************** API ***********************************/
1124 /******************************************************************************/
1127 * Core handler for connection creation.
1129 * @param cls Closure (unused).
1130 * @param peer Sender (neighbor).
1131 * @param message Message.
1133 * @return GNUNET_OK to keep the connection open,
1134 * GNUNET_SYSERR to close it (signal serious error)
1137 GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1138 const struct GNUNET_MessageHeader *message)
1140 struct GNUNET_MESH_ConnectionCreate *msg;
1141 struct GNUNET_PeerIdentity *id;
1142 struct GNUNET_HashCode *cid;
1143 struct MeshPeerPath *path;
1144 struct MeshPeer *dest_peer;
1145 struct MeshPeer *orig_peer;
1146 struct MeshConnection *c;
1147 unsigned int own_pos;
1151 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1152 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a connection create msg\n");
1155 size = ntohs (message->size);
1156 if (size < sizeof (struct GNUNET_MESH_ConnectionCreate))
1158 GNUNET_break_op (0);
1162 /* Calculate hops */
1163 size -= sizeof (struct GNUNET_MESH_ConnectionCreate);
1164 if (size % sizeof (struct GNUNET_PeerIdentity))
1166 GNUNET_break_op (0);
1169 size /= sizeof (struct GNUNET_PeerIdentity);
1172 GNUNET_break_op (0);
1175 LOG (GNUNET_ERROR_TYPE_DEBUG, " path has %u hops.\n", size);
1177 /* Get parameters */
1178 msg = (struct GNUNET_MESH_ConnectionCreate *) message;
1180 id = (struct GNUNET_PeerIdentity *) &msg[1];
1181 LOG (GNUNET_ERROR_TYPE_DEBUG,
1182 " connection %s (%s).\n",
1183 GNUNET_h2s (cid), GNUNET_i2s (id));
1185 /* Create connection */
1186 c = connection_get (cid);
1190 LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n");
1191 path = path_new (size);
1193 for (i = 0; i < size; i++)
1195 LOG (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n",
1196 GNUNET_i2s (&id[i]));
1197 path->peers[i] = GNUNET_PEER_intern (&id[i]);
1198 if (path->peers[i] == myid)
1201 if (own_pos == 0 && path->peers[own_pos] != myid)
1203 /* create path: self not found in path through self */
1204 GNUNET_break_op (0);
1205 path_destroy (path);
1208 LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos);
1209 GMP_add_path_to_all (path, GNUNET_NO);
1210 LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n");
1211 c = GMC_new (cid, NULL, path_duplicate (path), own_pos);
1214 connection_reset_timeout (c, GNUNET_YES);
1220 if (MESH_CONNECTION_NEW == c->state)
1221 connection_change_state (c, MESH_CONNECTION_SENT);
1223 /* Remember peers */
1224 dest_peer = GMP_get (&id[size - 1]);
1225 orig_peer = GMP_get (&id[0]);
1227 /* Is it a connection to us? */
1228 if (c->own_pos == size - 1)
1230 LOG (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
1231 GMP_add_path_to_origin (orig_peer, path, GNUNET_YES);
1233 add_to_peer (c, orig_peer);
1234 if (MESH_TUNNEL3_NEW == GMT_get_state (c->t))
1235 GMT_change_state (c->t, MESH_TUNNEL3_WAITING);
1237 send_connection_ack (c, GNUNET_NO);
1238 if (MESH_CONNECTION_SENT == c->state)
1239 connection_change_state (c, MESH_CONNECTION_ACK);
1241 /* Keep tunnel alive in direction dest->owner*/
1242 connection_reset_timeout (c, GNUNET_NO);
1246 /* It's for somebody else! Retransmit. */
1247 LOG (GNUNET_ERROR_TYPE_DEBUG, " Retransmitting.\n");
1248 GMP_add_path (dest_peer, path_duplicate (path), GNUNET_NO);
1249 GMP_add_path_to_origin (orig_peer, path, GNUNET_NO);
1250 GMC_send_prebuilt_message (message, c, GNUNET_YES, NULL, NULL);
1257 * Core handler for path confirmations.
1259 * @param cls closure
1260 * @param message message
1261 * @param peer peer identity this notification is about
1263 * @return GNUNET_OK to keep the connection open,
1264 * GNUNET_SYSERR to close it (signal serious error)
1267 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1268 const struct GNUNET_MessageHeader *message)
1270 struct GNUNET_MESH_ConnectionACK *msg;
1271 struct MeshConnection *c;
1272 struct MeshPeerPath *p;
1273 struct MeshPeer *pi;
1276 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1277 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a connection ACK msg\n");
1278 msg = (struct GNUNET_MESH_ConnectionACK *) message;
1279 LOG (GNUNET_ERROR_TYPE_DEBUG, " on connection %s\n",
1280 GNUNET_h2s (&msg->cid));
1281 c = connection_get (&msg->cid);
1284 GNUNET_STATISTICS_update (stats, "# control on unknown connection",
1286 LOG (GNUNET_ERROR_TYPE_DEBUG, " don't know the connection!\n");
1291 LOG (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n",
1293 pi = GMP_get (peer);
1294 if (get_next_hop (c) == pi)
1296 LOG (GNUNET_ERROR_TYPE_DEBUG, " SYNACK\n");
1298 if (MESH_CONNECTION_SENT == c->state)
1299 connection_change_state (c, MESH_CONNECTION_ACK);
1301 else if (get_prev_hop (c) == pi)
1303 LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK\n");
1305 connection_change_state (c, MESH_CONNECTION_READY);
1309 GNUNET_break_op (0);
1312 connection_reset_timeout (c, fwd);
1314 /* Add path to peers? */
1318 GMP_add_path_to_all (p, GNUNET_YES);
1325 /* Message for us as creator? */
1326 if (GMC_is_origin (c, GNUNET_YES))
1328 LOG (GNUNET_ERROR_TYPE_DEBUG, " Connection (SYN)ACK for us!\n");
1329 connection_change_state (c, MESH_CONNECTION_READY);
1330 if (MESH_TUNNEL3_WAITING == GMT_get_state (c->t))
1331 GMT_change_state (c->t, MESH_TUNNEL3_READY);
1332 send_connection_ack (c, GNUNET_YES);
1336 /* Message for us as destination? */
1337 if (GMC_is_terminal (c, GNUNET_YES))
1339 LOG (GNUNET_ERROR_TYPE_DEBUG, " Connection ACK for us!\n");
1340 connection_change_state (c, MESH_CONNECTION_READY);
1341 if (MESH_TUNNEL3_WAITING == GMT_get_state (c->t))
1342 GMT_change_state (c->t, MESH_TUNNEL3_READY);
1346 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
1347 GMC_send_prebuilt_message (message, c, fwd, NULL, NULL);
1353 * Core handler for notifications of broken paths
1355 * @param cls Closure (unused).
1356 * @param id Peer identity of sending neighbor.
1357 * @param message Message.
1359 * @return GNUNET_OK to keep the connection open,
1360 * GNUNET_SYSERR to close it (signal serious error)
1363 GMC_handle_broken (void* cls,
1364 const struct GNUNET_PeerIdentity* id,
1365 const struct GNUNET_MessageHeader* message)
1367 struct GNUNET_MESH_ConnectionBroken *msg;
1368 struct MeshConnection *c;
1371 LOG (GNUNET_ERROR_TYPE_DEBUG,
1372 "Received a CONNECTION BROKEN msg from %s\n", GNUNET_i2s (id));
1373 msg = (struct GNUNET_MESH_ConnectionBroken *) message;
1374 LOG (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n",
1375 GNUNET_i2s (&msg->peer1));
1376 LOG (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n",
1377 GNUNET_i2s (&msg->peer2));
1378 c = connection_get (&msg->cid);
1381 GNUNET_break_op (0);
1385 fwd = is_fwd (c, id);
1386 connection_cancel_queues (c, !fwd);
1387 if (GMC_is_terminal (c, fwd))
1389 if (0 < c->pending_messages)
1390 c->destroy = GNUNET_YES;
1396 GMC_send_prebuilt_message (message, c, fwd, NULL, NULL);
1397 c->destroy = GNUNET_YES;
1406 * Core handler for tunnel destruction
1408 * @param cls Closure (unused).
1409 * @param peer Peer identity of sending neighbor.
1410 * @param message Message.
1412 * @return GNUNET_OK to keep the connection open,
1413 * GNUNET_SYSERR to close it (signal serious error)
1416 GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
1417 const struct GNUNET_MessageHeader *message)
1419 struct GNUNET_MESH_ConnectionDestroy *msg;
1420 struct MeshConnection *c;
1423 msg = (struct GNUNET_MESH_ConnectionDestroy *) message;
1424 LOG (GNUNET_ERROR_TYPE_DEBUG,
1425 "Got a CONNECTION DESTROY message from %s\n",
1427 LOG (GNUNET_ERROR_TYPE_DEBUG,
1428 " for connection %s\n",
1429 GNUNET_h2s (&msg->cid));
1430 c = connection_get (&msg->cid);
1433 /* Probably already got the message from another path,
1434 * destroyed the tunnel and retransmitted to children.
1437 GNUNET_STATISTICS_update (stats, "# control on unknown tunnel",
1441 fwd = is_fwd (c, peer);
1442 if (GNUNET_SYSERR == fwd)
1444 GNUNET_break_op (0);
1447 GMC_send_prebuilt_message (message, c, fwd, NULL, NULL);
1448 c->destroy = GNUNET_YES;
1454 * Generic handler for mesh network encrypted traffic.
1456 * @param peer Peer identity this notification is about.
1457 * @param msg Encrypted message.
1459 * @return GNUNET_OK to keep the connection open,
1460 * GNUNET_SYSERR to close it (signal serious error)
1463 handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1464 const struct GNUNET_MESH_Encrypted *msg)
1466 struct MeshConnection *c;
1467 struct MeshPeer *neighbor;
1468 struct MeshFlowControl *fc;
1469 GNUNET_PEER_Id peer_id;
1477 size = ntohs (msg->header.size);
1479 sizeof (struct GNUNET_MESH_Encrypted) +
1480 sizeof (struct GNUNET_MessageHeader))
1482 GNUNET_break_op (0);
1485 type = ntohs (msg->header.type);
1486 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1487 LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n",
1488 GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer));
1490 /* Check connection */
1491 c = connection_get (&msg->cid);
1494 GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
1495 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING connection unknown\n");
1499 /* Check if origin is as expected */
1500 neighbor = get_prev_hop (c);
1501 peer_id = GNUNET_PEER_search (peer);
1502 if (peer_id == GMP_get_short_id (neighbor))
1508 neighbor = get_next_hop (c);
1509 if (peer_id == GMP_get_short_id (neighbor))
1515 /* Unexpected peer sending traffic on a connection. */
1516 GNUNET_break_op (0);
1522 fc = fwd ? &c->bck_fc : &c->fwd_fc;
1523 pid = ntohl (msg->pid);
1524 if (GMC_is_pid_bigger (pid, fc->last_ack_sent))
1526 GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO);
1527 LOG (GNUNET_ERROR_TYPE_DEBUG,
1528 "WARNING Received PID %u, (prev %u), ACK %u\n",
1529 pid, fc->last_pid_recv, fc->last_ack_sent);
1532 if (GNUNET_NO == GMC_is_pid_bigger (pid, fc->last_pid_recv))
1534 GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO);
1535 LOG (GNUNET_ERROR_TYPE_DEBUG,
1536 " Pid %u not expected (%u+), dropping!\n",
1537 pid, fc->last_pid_recv + 1);
1540 if (MESH_CONNECTION_SENT == c->state || MESH_CONNECTION_ACK == c->state)
1541 connection_change_state (c, MESH_CONNECTION_READY);
1542 connection_reset_timeout (c, fwd);
1543 fc->last_pid_recv = pid;
1545 /* Is this message for us? */
1546 if (GMC_is_terminal (c, fwd))
1548 /* TODO signature verification */
1549 LOG (GNUNET_ERROR_TYPE_DEBUG, " message for us!\n");
1550 GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO);
1557 fc->last_pid_recv = pid;
1558 GMT_handle_encrypted (c->t, msg);
1559 GMC_send_ack (c, fwd, GNUNET_NO);
1563 /* Message not for us: forward to next hop */
1564 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
1565 ttl = ntohl (msg->ttl);
1566 LOG (GNUNET_ERROR_TYPE_DEBUG, " ttl: %u\n", ttl);
1569 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
1570 LOG (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
1571 GMC_send_ack (c, fwd, GNUNET_NO);
1575 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
1576 GMC_send_prebuilt_message (&msg->header, c, fwd, NULL, NULL);
1582 * Generic handler for mesh network encrypted traffic.
1584 * @param peer Peer identity this notification is about.
1585 * @param msg Encrypted message.
1587 * @return GNUNET_OK to keep the connection open,
1588 * GNUNET_SYSERR to close it (signal serious error)
1591 handle_mesh_kx (const struct GNUNET_PeerIdentity *peer,
1592 const struct GNUNET_MESH_KX *msg)
1594 struct MeshConnection *c;
1595 struct MeshPeer *neighbor;
1596 GNUNET_PEER_Id peer_id;
1602 size = ntohs (msg->header.size);
1604 sizeof (struct GNUNET_MESH_Encrypted) +
1605 sizeof (struct GNUNET_MessageHeader))
1607 GNUNET_break_op (0);
1610 type = ntohs (msg->header.type);
1611 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1612 LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n",
1613 GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer));
1615 /* Check connection */
1616 c = connection_get (&msg->cid);
1619 GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
1620 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING connection unknown\n");
1624 /* Check if origin is as expected */
1625 neighbor = get_prev_hop (c);
1626 peer_id = GNUNET_PEER_search (peer);
1627 if (peer_id == GMP_get_short_id (neighbor))
1633 neighbor = get_next_hop (c);
1634 if (peer_id == GMP_get_short_id (neighbor))
1640 /* Unexpected peer sending traffic on a connection. */
1641 GNUNET_break_op (0);
1646 /* Count as connection confirmation. */
1647 if (MESH_CONNECTION_SENT == c->state || MESH_CONNECTION_ACK == c->state)
1648 connection_change_state (c, MESH_CONNECTION_READY);
1649 connection_reset_timeout (c, fwd);
1652 if (MESH_TUNNEL3_WAITING == GMT_get_state (c->t))
1653 GMT_change_state (c->t, MESH_TUNNEL3_READY);
1656 /* Is this message for us? */
1657 if (GMC_is_terminal (c, fwd))
1659 LOG (GNUNET_ERROR_TYPE_DEBUG, " message for us!\n");
1660 GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO);
1666 GMT_handle_kx (c->t, &msg[1].header);
1670 /* Message not for us: forward to next hop */
1671 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
1672 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
1673 GMC_send_prebuilt_message (&msg->header, c, fwd, NULL, NULL);
1680 * Core handler for encrypted mesh network traffic (channel mgmt, data).
1682 * @param cls Closure (unused).
1683 * @param message Message received.
1684 * @param peer Peer who sent the message.
1686 * @return GNUNET_OK to keep the connection open,
1687 * GNUNET_SYSERR to close it (signal serious error)
1690 GMC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
1691 const struct GNUNET_MessageHeader *message)
1693 return handle_mesh_encrypted (peer,
1694 (struct GNUNET_MESH_Encrypted *)message);
1699 * Core handler for key exchange traffic (ephemeral key, ping, pong).
1701 * @param cls Closure (unused).
1702 * @param message Message received.
1703 * @param peer Peer who sent the message.
1705 * @return GNUNET_OK to keep the connection open,
1706 * GNUNET_SYSERR to close it (signal serious error)
1709 GMC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
1710 const struct GNUNET_MessageHeader *message)
1712 return handle_mesh_kx (peer,
1713 (struct GNUNET_MESH_KX *) message);
1718 * Core handler for mesh network traffic point-to-point acks.
1720 * @param cls closure
1721 * @param message message
1722 * @param peer peer identity this notification is about
1724 * @return GNUNET_OK to keep the connection open,
1725 * GNUNET_SYSERR to close it (signal serious error)
1728 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
1729 const struct GNUNET_MessageHeader *message)
1731 struct GNUNET_MESH_ACK *msg;
1732 struct MeshConnection *c;
1733 struct MeshFlowControl *fc;
1738 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1739 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n",
1741 msg = (struct GNUNET_MESH_ACK *) message;
1743 c = connection_get (&msg->cid);
1747 GNUNET_STATISTICS_update (stats, "# ack on unknown connection", 1,
1752 /* Is this a forward or backward ACK? */
1753 id = GNUNET_PEER_search (peer);
1754 if (GMP_get_short_id (get_next_hop (c)) == id)
1756 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
1760 else if (GMP_get_short_id (get_prev_hop (c)) == id)
1762 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
1768 GNUNET_break_op (0);
1772 ack = ntohl (msg->ack);
1773 LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u (was %u)\n",
1774 ack, fc->last_ack_recv);
1775 if (GMC_is_pid_bigger (ack, fc->last_ack_recv))
1776 fc->last_ack_recv = ack;
1778 /* Cancel polling if the ACK is big enough. */
1779 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task &&
1780 GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent))
1782 LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n");
1783 GNUNET_SCHEDULER_cancel (fc->poll_task);
1784 fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
1785 fc->poll_time = GNUNET_TIME_UNIT_SECONDS;
1788 connection_unlock_queue (c, fwd);
1795 * Core handler for mesh network traffic point-to-point ack polls.
1797 * @param cls closure
1798 * @param message message
1799 * @param peer peer identity this notification is about
1801 * @return GNUNET_OK to keep the connection open,
1802 * GNUNET_SYSERR to close it (signal serious error)
1805 GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
1806 const struct GNUNET_MessageHeader *message)
1808 struct GNUNET_MESH_Poll *msg;
1809 struct MeshConnection *c;
1810 struct MeshFlowControl *fc;
1815 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
1816 LOG (GNUNET_ERROR_TYPE_DEBUG,
1817 "Got a POLL packet from %s!\n",
1820 msg = (struct GNUNET_MESH_Poll *) message;
1822 c = connection_get (&msg->cid);
1826 GNUNET_STATISTICS_update (stats, "# poll on unknown connection", 1,
1828 GNUNET_break_op (0);
1832 /* Is this a forward or backward ACK?
1833 * Note: a poll should never be needed in a loopback case,
1834 * since there is no possiblility of packet loss there, so
1835 * this way of discerining FWD/BCK should not be a problem.
1837 id = GNUNET_PEER_search (peer);
1838 if (GMP_get_short_id (get_next_hop (c)) == id)
1840 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD FC\n");
1843 else if (GMP_get_short_id (get_prev_hop (c)) == id)
1845 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK FC\n");
1850 GNUNET_break_op (0);
1854 pid = ntohl (msg->pid);
1855 LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u, OLD %u\n", pid, fc->last_pid_recv);
1856 fc->last_pid_recv = pid;
1857 fwd = fc == &c->bck_fc;
1858 GMC_send_ack (c, fwd, GNUNET_YES);
1865 * Core handler for mesh keepalives.
1867 * @param cls closure
1868 * @param message message
1869 * @param peer peer identity this notification is about
1870 * @return GNUNET_OK to keep the connection open,
1871 * GNUNET_SYSERR to close it (signal serious error)
1873 * TODO: Check who we got this from, to validate route.
1876 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1877 const struct GNUNET_MessageHeader *message)
1879 struct GNUNET_MESH_ConnectionKeepAlive *msg;
1880 struct MeshConnection *c;
1881 struct MeshPeer *neighbor;
1884 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) message;
1885 LOG (GNUNET_ERROR_TYPE_DEBUG, "got a keepalive packet from %s\n",
1888 c = connection_get (&msg->cid);
1891 GNUNET_STATISTICS_update (stats, "# keepalive on unknown connection", 1,
1896 fwd = GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE == ntohs (message->type) ?
1897 GNUNET_YES : GNUNET_NO;
1899 /* Check if origin is as expected */
1900 neighbor = get_hop (c, fwd);
1901 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
1903 GNUNET_break_op (0);
1907 connection_change_state (c, MESH_CONNECTION_READY);
1908 connection_reset_timeout (c, fwd);
1910 if (GMC_is_terminal (c, fwd))
1913 GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO);
1914 GMC_send_prebuilt_message (message, c, fwd, NULL, NULL);
1921 * Send an ACK on the appropriate connection/channel, depending on
1922 * the direction and the position of the peer.
1924 * @param c Which connection to send the hop-by-hop ACK.
1925 * @param fwd Is this a fwd ACK? (will go dest->root).
1926 * @param force Send the ACK even if suboptimal (e.g. requested by POLL).
1929 GMC_send_ack (struct MeshConnection *c, int fwd, int force)
1931 unsigned int buffer;
1933 LOG (GNUNET_ERROR_TYPE_DEBUG,
1934 "GMC send %s ACK on %s\n",
1935 fwd ? "FWD" : "BCK", GMC_2s (c));
1943 /* Get available buffer space */
1944 if (GMC_is_terminal (c, fwd))
1946 LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all channels\n");
1947 buffer = GMT_get_channels_buffer (c->t);
1951 LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from one connection\n");
1952 buffer = GMC_get_buffer (c, fwd);
1954 LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer);
1955 if (0 == buffer && GNUNET_NO == force)
1958 /* Send available buffer space */
1959 if (GMC_is_origin (c, fwd))
1961 GNUNET_assert (NULL != c->t);
1962 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channels...\n");
1963 GMT_unchoke_channels (c->t);
1967 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on connection\n");
1968 send_ack (c, buffer, fwd, force);
1974 * Initialize the connections subsystem
1976 * @param c Configuration handle.
1979 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c)
1981 LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
1983 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_MSGS_QUEUE",
1986 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
1987 "MESH", "MAX_MSGS_QUEUE", "MISSING");
1988 GNUNET_SCHEDULER_shutdown ();
1993 GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_CONNECTIONS",
1996 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
1997 "MESH", "MAX_CONNECTIONS", "MISSING");
1998 GNUNET_SCHEDULER_shutdown ();
2003 GNUNET_CONFIGURATION_get_value_time (c, "MESH", "REFRESH_CONNECTION_TIME",
2004 &refresh_connection_time))
2006 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
2007 "MESH", "REFRESH_CONNECTION_TIME", "MISSING");
2008 GNUNET_SCHEDULER_shutdown ();
2011 connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
2015 * Shut down the connections subsystem.
2020 GNUNET_CONTAINER_multihashmap_destroy (connections);
2024 struct MeshConnection *
2025 GMC_new (const struct GNUNET_HashCode *cid,
2026 struct MeshTunnel3 *t,
2027 struct MeshPeerPath *p,
2028 unsigned int own_pos)
2030 struct MeshConnection *c;
2032 c = GNUNET_new (struct MeshConnection);
2034 GNUNET_CONTAINER_multihashmap_put (connections, &c->id, c,
2035 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
2036 fc_init (&c->fwd_fc);
2037 fc_init (&c->bck_fc);
2042 if (own_pos > p->length - 1)
2048 c->own_pos = own_pos;
2053 c->fwd_maintenance_task =
2054 GNUNET_SCHEDULER_add_delayed (refresh_connection_time,
2055 &connection_fwd_keepalive, c);
2057 register_neighbors (c);
2063 GMC_destroy (struct MeshConnection *c)
2068 if (2 == c->destroy) /* cancel queues -> GMP_queue_cancel -> q_destroy -> */
2069 return; /* -> message_sent -> GMC_destroy. Don't loop. */
2072 LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying connection %s\n", GMC_2s (c));
2074 /* Cancel all traffic */
2075 connection_cancel_queues (c, GNUNET_YES);
2076 connection_cancel_queues (c, GNUNET_NO);
2078 /* Cancel maintainance task (keepalive/timeout) */
2079 if (GNUNET_SCHEDULER_NO_TASK != c->fwd_maintenance_task)
2080 GNUNET_SCHEDULER_cancel (c->fwd_maintenance_task);
2081 if (GNUNET_SCHEDULER_NO_TASK != c->bck_maintenance_task)
2082 GNUNET_SCHEDULER_cancel (c->bck_maintenance_task);
2084 /* Unregister from neighbors */
2085 unregister_neighbors (c);
2088 GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO);
2090 GMT_remove_connection (c->t, c);
2092 if (GNUNET_NO == GMC_is_origin (c, GNUNET_YES))
2093 path_destroy (c->path);
2099 * Get the connection ID.
2101 * @param c Connection to get the ID from.
2103 * @return ID of the connection.
2105 const struct GNUNET_HashCode *
2106 GMC_get_id (const struct MeshConnection *c)
2113 * Get the connection path.
2115 * @param c Connection to get the path from.
2117 * @return path used by the connection.
2119 const struct MeshPeerPath *
2120 GMC_get_path (const struct MeshConnection *c)
2127 * Get the connection state.
2129 * @param c Connection to get the state from.
2131 * @return state of the connection.
2133 enum MeshConnectionState
2134 GMC_get_state (const struct MeshConnection *c)
2140 * Get the connection tunnel.
2142 * @param c Connection to get the tunnel from.
2144 * @return tunnel of the connection.
2146 struct MeshTunnel3 *
2147 GMC_get_tunnel (const struct MeshConnection *c)
2154 * Get free buffer space in a connection.
2156 * @param c Connection.
2157 * @param fwd Is query about FWD traffic?
2159 * @return Free buffer space [0 - max_msgs_queue/max_connections]
2162 GMC_get_buffer (struct MeshConnection *c, int fwd)
2164 struct MeshFlowControl *fc;
2166 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2168 return (fc->queue_max - fc->queue_n);
2172 * Get how many messages have we allowed to send to us from a direction.
2174 * @param c Connection.
2175 * @param fwd Are we asking about traffic from FWD (BCK messages)?
2177 * @return last_ack_sent - last_pid_recv
2180 GMC_get_allowed (struct MeshConnection *c, int fwd)
2182 struct MeshFlowControl *fc;
2184 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2185 if (GMC_is_pid_bigger(fc->last_pid_recv, fc->last_ack_sent))
2189 return (fc->last_ack_sent - fc->last_pid_recv);
2193 * Get messages queued in a connection.
2195 * @param c Connection.
2196 * @param fwd Is query about FWD traffic?
2198 * @return Number of messages queued.
2201 GMC_get_qn (struct MeshConnection *c, int fwd)
2203 struct MeshFlowControl *fc;
2205 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2212 * Allow the connection to advertise a buffer of the given size.
2214 * The connection will send an @c fwd ACK message (so: in direction !fwd)
2215 * allowing up to last_pid_recv + buffer.
2217 * @param c Connection.
2218 * @param buffer How many more messages the connection can accept.
2219 * @param fwd Is this about FWD traffic? (The ack will go dest->root).
2222 GMC_allow (struct MeshConnection *c, unsigned int buffer, int fwd)
2224 send_ack (c, buffer, fwd, GNUNET_NO);
2229 * Notify other peers on a connection of a broken link. Mark connections
2230 * to destroy after all traffic has been sent.
2232 * @param c Connection on which there has been a disconnection.
2233 * @param peer Peer that disconnected.
2236 GMC_notify_broken (struct MeshConnection *c,
2237 struct MeshPeer *peer)
2241 fwd = peer == get_prev_hop (c);
2243 if (GNUNET_YES == GMC_is_terminal (c, fwd))
2245 /* Local shutdown, no one to notify about this. */
2249 if (GNUNET_NO == c->destroy)
2250 send_broken (c, &my_full_id, GMP_get_id (peer), fwd);
2252 /* Connection will have at least one pending message
2253 * (the one we just scheduled), so no point in checking whether to
2254 * destroy immediately. */
2255 c->destroy = GNUNET_YES;
2258 * Cancel all queues, if no message is left, connection will be destroyed.
2260 connection_cancel_queues (c, !fwd);
2267 * Is this peer the first one on the connection?
2269 * @param c Connection.
2270 * @param fwd Is this about fwd traffic?
2272 * @return #GNUNET_YES if origin, #GNUNET_NO if relay/terminal.
2275 GMC_is_origin (struct MeshConnection *c, int fwd)
2277 if (!fwd && c->path->length - 1 == c->own_pos )
2279 if (fwd && 0 == c->own_pos)
2286 * Is this peer the last one on the connection?
2288 * @param c Connection.
2289 * @param fwd Is this about fwd traffic?
2290 * Note that the ROOT is the terminal for BCK traffic!
2292 * @return #GNUNET_YES if terminal, #GNUNET_NO if relay/origin.
2295 GMC_is_terminal (struct MeshConnection *c, int fwd)
2297 return GMC_is_origin (c, !fwd);
2302 * See if we are allowed to send by the next hop in the given direction.
2304 * @param c Connection.
2305 * @param fwd Is this about fwd traffic?
2307 * @return #GNUNET_YES in case it's OK to send.
2310 GMC_is_sendable (struct MeshConnection *c, int fwd)
2312 struct MeshFlowControl *fc;
2314 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2315 if (GMC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent))
2321 * Sends an already built message on a connection, properly registering
2322 * all used resources.
2324 * @param message Message to send. Function makes a copy of it.
2325 * If message is not hop-by-hop, decrements TTL of copy.
2326 * @param c Connection on which this message is transmitted.
2327 * @param fwd Is this a fwd message?
2328 * @param cont Continuation called once message is sent. Can be NULL.
2329 * @param cont_cls Closure for @c cont.
2331 * @return Handle to cancel the message before it's sent. NULL on error.
2332 * Invalid on @c cont call.
2334 struct MeshConnectionQueue *
2335 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2336 struct MeshConnection *c, int fwd,
2337 GMC_sent cont, void *cont_cls)
2339 struct MeshFlowControl *fc;
2340 struct MeshConnectionQueue *q;
2346 size = ntohs (message->size);
2347 data = GNUNET_malloc (size);
2348 memcpy (data, message, size);
2349 type = ntohs (message->type);
2350 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send %s (%u bytes) on connection %s\n",
2351 GNUNET_MESH_DEBUG_M2S (type), size, GMC_2s (c));
2353 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2354 droppable = GNUNET_YES;
2357 struct GNUNET_MESH_Encrypted *emsg;
2358 struct GNUNET_MESH_KX *kmsg;
2359 struct GNUNET_MESH_ACK *amsg;
2360 struct GNUNET_MESH_Poll *pmsg;
2361 struct GNUNET_MESH_ConnectionDestroy *dmsg;
2362 struct GNUNET_MESH_ConnectionBroken *bmsg;
2365 case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
2366 emsg = (struct GNUNET_MESH_Encrypted *) data;
2367 ttl = ntohl (emsg->ttl);
2370 GNUNET_break_op (0);
2374 emsg->ttl = htonl (ttl - 1);
2375 emsg->pid = htonl (fwd ? c->fwd_fc.next_pid++ : c->bck_fc.next_pid++);
2376 LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n);
2378 LOG (GNUNET_ERROR_TYPE_DEBUG, "pid %u\n", ntohl (emsg->pid));
2379 LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent);
2380 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv);
2381 if (GMC_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv))
2383 GMC_start_poll (c, fwd);
2387 case GNUNET_MESSAGE_TYPE_MESH_KX:
2388 kmsg = (struct GNUNET_MESH_KX *) data;
2392 case GNUNET_MESSAGE_TYPE_MESH_ACK:
2393 amsg = (struct GNUNET_MESH_ACK *) data;
2395 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", ntohl (amsg->ack));
2396 droppable = GNUNET_NO;
2399 case GNUNET_MESSAGE_TYPE_MESH_POLL:
2400 pmsg = (struct GNUNET_MESH_Poll *) data;
2402 LOG (GNUNET_ERROR_TYPE_DEBUG, " poll %u\n", ntohl (pmsg->pid));
2403 droppable = GNUNET_NO;
2406 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
2407 dmsg = (struct GNUNET_MESH_ConnectionDestroy *) data;
2412 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
2413 bmsg = (struct GNUNET_MESH_ConnectionBroken *) data;
2418 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
2419 case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
2426 if (fc->queue_n > fc->queue_max && droppable)
2428 GNUNET_STATISTICS_update (stats, "# messages dropped (buffer full)",
2431 LOG (GNUNET_ERROR_TYPE_DEBUG,
2432 "queue full: %u/%u\n",
2433 fc->queue_n, fc->queue_max);
2434 if (GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED == type)
2436 return NULL; /* Drop this message */
2439 LOG (GNUNET_ERROR_TYPE_DEBUG, " C_P+ %p %u\n", c, c->pending_messages);
2440 c->pending_messages++;
2442 q = GNUNET_new (struct MeshConnectionQueue);
2443 q->q = GMP_queue_add (get_hop (c, fwd), data, type, size, c, fwd,
2452 q->cont_cls = cont_cls;
2458 * Cancel a previously sent message while it's in the queue.
2460 * ONLY can be called before the continuation given to the send function
2461 * is called. Once the continuation is called, the message is no longer in the
2464 * If the send function was given no continuation, GMC_cancel should
2465 * NOT be called, since it's not possible to determine if the message has
2466 * already been sent.
2468 * @param q Handle to the queue.
2471 GMC_cancel (struct MeshConnectionQueue *q)
2473 LOG (GNUNET_ERROR_TYPE_DEBUG, "! GMC cancel message\n");
2475 /* queue destroy calls message_sent, which calls q->cont and frees q */
2476 GMP_queue_destroy (q->q, GNUNET_YES);
2481 * Sends a CREATE CONNECTION message for a path to a peer.
2482 * Changes the connection and tunnel states if necessary.
2484 * @param connection Connection to create.
2487 GMC_send_create (struct MeshConnection *connection)
2489 enum MeshTunnel3State state;
2492 size = sizeof (struct GNUNET_MESH_ConnectionCreate);
2493 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
2494 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
2495 GMP_queue_add (get_next_hop (connection), NULL,
2496 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
2497 size, connection, GNUNET_YES, &message_sent, NULL);
2498 LOG (GNUNET_ERROR_TYPE_DEBUG, " C_P+ %p %u (create)\n",
2499 connection, connection->pending_messages);
2500 connection->pending_messages++;
2501 state = GMT_get_state (connection->t);
2502 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state)
2503 GMT_change_state (connection->t, MESH_TUNNEL3_WAITING);
2504 if (MESH_CONNECTION_NEW == connection->state)
2505 connection_change_state (connection, MESH_CONNECTION_SENT);
2510 * Send a message to all peers in this connection that the connection
2511 * is no longer valid.
2513 * If some peer should not receive the message, it should be zero'ed out
2514 * before calling this function.
2516 * @param c The connection whose peers to notify.
2519 GMC_send_destroy (struct MeshConnection *c)
2521 struct GNUNET_MESH_ConnectionDestroy msg;
2523 if (GNUNET_YES == c->destroy)
2526 msg.header.size = htons (sizeof (msg));
2527 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY);;
2529 LOG (GNUNET_ERROR_TYPE_DEBUG,
2530 " sending connection destroy for connection %s\n",
2533 if (GNUNET_NO == GMC_is_terminal (c, GNUNET_YES))
2534 GMC_send_prebuilt_message (&msg.header, c, GNUNET_YES, NULL, NULL);
2535 if (GNUNET_NO == GMC_is_terminal (c, GNUNET_NO))
2536 GMC_send_prebuilt_message (&msg.header, c, GNUNET_NO, NULL, NULL);
2537 c->destroy = GNUNET_YES;
2542 * @brief Start a polling timer for the connection.
2544 * When a neighbor does not accept more traffic on the connection it could be
2545 * caused by a simple congestion or by a lost ACK. Polling enables to check
2546 * for the lastest ACK status for a connection.
2548 * @param c Connection.
2549 * @param fwd Should we poll in the FWD direction?
2552 GMC_start_poll (struct MeshConnection *c, int fwd)
2554 struct MeshFlowControl *fc;
2556 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2557 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task && NULL != fc->poll_msg)
2561 fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
2568 * @brief Stop polling a connection for ACKs.
2570 * Once we have enough ACKs for future traffic, polls are no longer necessary.
2572 * @param c Connection.
2573 * @param fwd Should we stop the poll in the FWD direction?
2576 GMC_stop_poll (struct MeshConnection *c, int fwd)
2578 struct MeshFlowControl *fc;
2580 fc = fwd ? &c->fwd_fc : &c->bck_fc;
2581 if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task)
2583 GNUNET_SCHEDULER_cancel (fc->poll_task);
2584 fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
2589 * Get a (static) string for a connection.
2591 * @param c Connection.
2594 GMC_2s (struct MeshConnection *c)
2598 static char buf[128];
2600 sprintf (buf, "%s (->%s)", GNUNET_h2s (&c->id), GMT_2s (c->t));
2603 return GNUNET_h2s (&c->id);