aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-06-17 14:27:55 +0000
committerBart Polot <bart@net.in.tum.de>2015-06-17 14:27:55 +0000
commit55c9453ec9062748648dc32d11be5a32c113403d (patch)
tree5aa279e7f903788e00b1955c418ebaa6f3c6adc8 /src
parent6aa011dfa7b5dfe1d9390f5295deec173401b476 (diff)
downloadgnunet-55c9453ec9062748648dc32d11be5a32c113403d.tar.gz
gnunet-55c9453ec9062748648dc32d11be5a32c113403d.zip
- destroy peers on shutdown
Diffstat (limited to 'src')
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c99
1 files changed, 49 insertions, 50 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 8034a553a..bb6677dd8 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -451,8 +451,7 @@ core_disconnect (void *cls,
451 char own_id[16]; 451 char own_id[16];
452 452
453 strncpy (own_id, GNUNET_i2s (&my_full_id), 15); 453 strncpy (own_id, GNUNET_i2s (&my_full_id), 15);
454 p = GNUNET_CONTAINER_multipeermap_get (peers, 454 p = GNUNET_CONTAINER_multipeermap_get (peers, peer);
455 peer);
456 if (NULL == p) 455 if (NULL == p)
457 { 456 {
458 GNUNET_break (0); 457 GNUNET_break (0);
@@ -696,7 +695,48 @@ get_priority (struct CadetPeerQueue *q)
696 695
697 696
698/** 697/**
699 * Iterator over tunnel hash map entries to destroy the tunnel during shutdown. 698 * Destroy the peer_info and free any allocated resources linked to it
699 *
700 * @param peer The peer_info to destroy.
701 * @return #GNUNET_OK on success
702 */
703static int
704peer_destroy (struct CadetPeer *peer)
705{
706 struct GNUNET_PeerIdentity id;
707 struct CadetPeerPath *p;
708 struct CadetPeerPath *nextp;
709
710 GNUNET_PEER_resolve (peer->id, &id);
711 GNUNET_PEER_change_rc (peer->id, -1);
712
713 LOG (GNUNET_ERROR_TYPE_INFO,
714 "destroying peer %s\n",
715 GNUNET_i2s (&id));
716
717 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
718 {
719 GNUNET_break (0);
720 LOG (GNUNET_ERROR_TYPE_WARNING, " peer not in peermap!!\n");
721 }
722 GCP_stop_search (peer);
723 p = peer->path_head;
724 while (NULL != p)
725 {
726 nextp = p->next;
727 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p);
728 path_destroy (p);
729 p = nextp;
730 }
731 if (NULL != peer->tunnel)
732 GCT_destroy_empty (peer->tunnel);
733 GNUNET_free (peer);
734 return GNUNET_OK;
735}
736
737
738/**
739 * Iterator over peer hash map entries to destroy the peer during shutdown.
700 * 740 *
701 * @param cls closure 741 * @param cls closure
702 * @param key current key code 742 * @param key current key code
@@ -705,15 +745,17 @@ get_priority (struct CadetPeerQueue *q)
705 * #GNUNET_NO if not. 745 * #GNUNET_NO if not.
706 */ 746 */
707static int 747static int
708shutdown_tunnel (void *cls, 748shutdown_peer (void *cls,
709 const struct GNUNET_PeerIdentity *key, 749 const struct GNUNET_PeerIdentity *key,
710 void *value) 750 void *value)
711{ 751{
712 struct CadetPeer *p = value; 752 struct CadetPeer *p = value;
713 struct CadetTunnel *t = p->tunnel; 753 struct CadetTunnel *t = p->tunnel;
714 754
715 if (NULL != t) 755 if (NULL != t)
716 GCT_destroy (t); 756 GCT_destroy (t);
757 p->tunnel = NULL;
758 peer_destroy (p);
717 return GNUNET_YES; 759 return GNUNET_YES;
718} 760}
719 761
@@ -755,49 +797,6 @@ delayed_search (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
755 797
756 798
757/** 799/**
758 * Destroy the peer_info and free any allocated resources linked to it
759 *
760 * @param peer The peer_info to destroy.
761 * @return #GNUNET_OK on success
762 */
763static int
764peer_destroy (struct CadetPeer *peer)
765{
766 struct GNUNET_PeerIdentity id;
767 struct CadetPeerPath *p;
768 struct CadetPeerPath *nextp;
769
770 GNUNET_PEER_resolve (peer->id, &id);
771 GNUNET_PEER_change_rc (peer->id, -1);
772
773 LOG (GNUNET_ERROR_TYPE_WARNING,
774 "destroying peer %s\n",
775 GNUNET_i2s (&id));
776
777 if (GNUNET_YES !=
778 GNUNET_CONTAINER_multipeermap_remove (peers,
779 &id,
780 peer))
781 {
782 GNUNET_break (0);
783 LOG (GNUNET_ERROR_TYPE_WARNING, " not in peermap!!\n");
784 }
785 GCP_stop_search (peer);
786 p = peer->path_head;
787 while (NULL != p)
788 {
789 nextp = p->next;
790 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p);
791 path_destroy (p);
792 p = nextp;
793 }
794 GCT_destroy_empty (peer->tunnel);
795 GNUNET_free (peer);
796 return GNUNET_OK;
797}
798
799
800/**
801 * Returns if peer is used (has a tunnel or is neighbor). 800 * Returns if peer is used (has a tunnel or is neighbor).
802 * 801 *
803 * @param peer Peer to check. 802 * @param peer Peer to check.
@@ -1720,7 +1719,7 @@ void
1720GCP_shutdown (void) 1719GCP_shutdown (void)
1721{ 1720{
1722 GNUNET_CONTAINER_multipeermap_iterate (peers, 1721 GNUNET_CONTAINER_multipeermap_iterate (peers,
1723 &shutdown_tunnel, 1722 &shutdown_peer,
1724 NULL); 1723 NULL);
1725 if (NULL != core_handle) 1724 if (NULL != core_handle)
1726 { 1725 {