aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-07 14:29:39 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-07 14:29:39 +0000
commitf0161e3832d1a99c559f647e27c8ff073b88b13c (patch)
tree519f7efa6c13647ed86429051fc746b14ef4d962 /src/transport/gnunet-service-transport_neighbours.c
parentcf599235b5ff4f06dc7e78aeca8c0d9794560c90 (diff)
downloadgnunet-f0161e3832d1a99c559f647e27c8ff073b88b13c.tar.gz
gnunet-f0161e3832d1a99c559f647e27c8ff073b88b13c.zip
stuff
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index db2a40a70..a8302bc56 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -321,8 +321,12 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
321{ 321{
322 struct MessageQueue *mq; 322 struct MessageQueue *mq;
323 323
324 disconnect_notify_cb (callback_cls, 324 if (n->is_connected)
325 &n->id); 325 {
326 disconnect_notify_cb (callback_cls,
327 &n->id);
328 n->is_connected = GNUNET_NO;
329 }
326 GNUNET_assert (GNUNET_YES == 330 GNUNET_assert (GNUNET_YES ==
327 GNUNET_CONTAINER_multihashmap_remove (neighbours, 331 GNUNET_CONTAINER_multihashmap_remove (neighbours,
328 &n->id.hashPubKey, 332 &n->id.hashPubKey,
@@ -667,6 +671,23 @@ GST_neighbours_iterate (GST_NeighbourIterator cb,
667 671
668 672
669/** 673/**
674 * Peer has been idle for too long. Disconnect.
675 *
676 * @param cls the 'struct NeighbourMapEntry' of the neighbour that went idle
677 * @param tc scheduler context
678 */
679static void
680neighbour_idle_timeout_task (void *cls,
681 const struct GNUNET_SCHEDULER_TaskContext *tc)
682{
683 struct NeighbourMapEntry *n = cls;
684
685 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
686 disconnect_neighbour (n);
687}
688
689
690/**
670 * We have received a CONNECT. Set the peer to connected. 691 * We have received a CONNECT. Set the peer to connected.
671 * 692 *
672 * @param sender peer sending the PONG 693 * @param sender peer sending the PONG
@@ -697,7 +718,7 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
697 { 718 {
698 GNUNET_break (0); 719 GNUNET_break (0);
699 return GNUNET_SYSERR; 720 return GNUNET_SYSERR;
700 } 721 }
701 n = lookup_neighbour (sender); 722 n = lookup_neighbour (sender);
702 if ( (NULL != n) || 723 if ( (NULL != n) ||
703 (n->is_connected == GNUNET_YES) ) 724 (n->is_connected == GNUNET_YES) )
@@ -745,7 +766,13 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
745 // FIXME: ATS: switch session!? 766 // FIXME: ATS: switch session!?
746 // n->session = session; 767 // n->session = session;
747 } 768 }
748 n->is_connected = GNUNET_YES; 769 n->peer_timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
770 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
771 GNUNET_SCHEDULER_cancel (n->timeout_task);
772 n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
773 &neighbour_idle_timeout_task,
774 n);
775 n->is_connected = GNUNET_YES;
749 connect_notify_cb (callback_cls, 776 connect_notify_cb (callback_cls,
750 sender, 777 sender,
751 n->ats, 778 n->ats,