diff options
-rw-r--r-- | src/revocation/gnunet-service-revocation.c | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index 8445f3264..d4194d952 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -146,6 +146,60 @@ static unsigned long long revocation_work_required; | |||
146 | static struct GNUNET_HashCode revocation_set_union_app_id; | 146 | static struct GNUNET_HashCode revocation_set_union_app_id; |
147 | 147 | ||
148 | 148 | ||
149 | /** | ||
150 | * Create a new PeerEntry and add it to the peers multipeermap. | ||
151 | * | ||
152 | * @param peer the peer identity | ||
153 | * @return a pointer to the new PeerEntry | ||
154 | */ | ||
155 | static struct PeerEntry * | ||
156 | new_peer_entry(const struct GNUNET_PeerIdentity *peer) | ||
157 | { | ||
158 | struct PeerEntry *peer_entry; | ||
159 | |||
160 | peer_entry = GNUNET_new (struct PeerEntry); | ||
161 | peer_entry->id = *peer; | ||
162 | GNUNET_assert (GNUNET_OK == | ||
163 | GNUNET_CONTAINER_multipeermap_put (peers, | ||
164 | &peer_entry->id, | ||
165 | peer_entry, | ||
166 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
167 | peer_entry->mq = GNUNET_CORE_mq_create (core_api, peer); | ||
168 | return peer_entry; | ||
169 | } | ||
170 | |||
171 | |||
172 | /** | ||
173 | * Delete a PeerEntry for the given peer | ||
174 | * | ||
175 | * @param peer the identity of the peer to delete | ||
176 | */ | ||
177 | static void | ||
178 | delete_peer_entry(const struct GNUNET_PeerIdentity *peer) | ||
179 | { | ||
180 | struct PeerEntry *peer_entry; | ||
181 | |||
182 | peer_entry = GNUNET_CONTAINER_multipeermap_get (peers, | ||
183 | peer); | ||
184 | GNUNET_assert (NULL != peer_entry); | ||
185 | GNUNET_assert (GNUNET_YES == | ||
186 | GNUNET_CONTAINER_multipeermap_remove (peers, | ||
187 | peer, | ||
188 | peer_entry)); | ||
189 | GNUNET_MQ_destroy (peer_entry->mq); | ||
190 | if (NULL != peer_entry->transmit_task) | ||
191 | { | ||
192 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | ||
193 | peer_entry->transmit_task = NULL; | ||
194 | } | ||
195 | if (NULL != peer_entry->so) | ||
196 | { | ||
197 | GNUNET_SET_operation_cancel (peer_entry->so); | ||
198 | peer_entry->so = NULL; | ||
199 | } | ||
200 | GNUNET_free (peer_entry); | ||
201 | } | ||
202 | |||
149 | 203 | ||
150 | /** | 204 | /** |
151 | * An revoke message has been received, check that it is well-formed. | 205 | * An revoke message has been received, check that it is well-formed. |
@@ -536,14 +590,7 @@ handle_core_connect (void *cls, | |||
536 | with. This should be rare, but isn't impossible. */ | 590 | with. This should be rare, but isn't impossible. */ |
537 | return; | 591 | return; |
538 | } | 592 | } |
539 | peer_entry = GNUNET_new (struct PeerEntry); | 593 | peer_entry = new_peer_entry(peer); |
540 | peer_entry->id = *peer; | ||
541 | GNUNET_assert (GNUNET_OK == | ||
542 | GNUNET_CONTAINER_multipeermap_put (peers, | ||
543 | &peer_entry->id, | ||
544 | peer_entry, | ||
545 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
546 | peer_entry->mq = GNUNET_CORE_mq_create (core_api, peer); | ||
547 | GNUNET_CRYPTO_hash (&my_identity, | 594 | GNUNET_CRYPTO_hash (&my_identity, |
548 | sizeof (my_identity), | 595 | sizeof (my_identity), |
549 | &my_hash); | 596 | &my_hash); |
@@ -575,8 +622,6 @@ static void | |||
575 | handle_core_disconnect (void *cls, | 622 | handle_core_disconnect (void *cls, |
576 | const struct GNUNET_PeerIdentity *peer) | 623 | const struct GNUNET_PeerIdentity *peer) |
577 | { | 624 | { |
578 | struct PeerEntry *pos; | ||
579 | |||
580 | if (0 == memcmp (peer, | 625 | if (0 == memcmp (peer, |
581 | &my_identity, | 626 | &my_identity, |
582 | sizeof (my_identity))) | 627 | sizeof (my_identity))) |
@@ -587,25 +632,7 @@ handle_core_disconnect (void *cls, | |||
587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 632 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
588 | "Peer `%s' disconnected from us\n", | 633 | "Peer `%s' disconnected from us\n", |
589 | GNUNET_i2s (peer)); | 634 | GNUNET_i2s (peer)); |
590 | pos = GNUNET_CONTAINER_multipeermap_get (peers, | 635 | delete_peer_entry(peer); |
591 | peer); | ||
592 | GNUNET_assert (NULL != pos); | ||
593 | GNUNET_assert (GNUNET_YES == | ||
594 | GNUNET_CONTAINER_multipeermap_remove (peers, | ||
595 | peer, | ||
596 | pos)); | ||
597 | GNUNET_MQ_destroy (pos->mq); | ||
598 | if (NULL != pos->transmit_task) | ||
599 | { | ||
600 | GNUNET_SCHEDULER_cancel (pos->transmit_task); | ||
601 | pos->transmit_task = NULL; | ||
602 | } | ||
603 | if (NULL != pos->so) | ||
604 | { | ||
605 | GNUNET_SET_operation_cancel (pos->so); | ||
606 | pos->so = NULL; | ||
607 | } | ||
608 | GNUNET_free (pos); | ||
609 | GNUNET_STATISTICS_update (stats, | 636 | GNUNET_STATISTICS_update (stats, |
610 | "# peers connected", | 637 | "# peers connected", |
611 | -1, | 638 | -1, |
@@ -739,13 +766,7 @@ handle_revocation_union_request (void *cls, | |||
739 | other_peer); | 766 | other_peer); |
740 | if (NULL == peer_entry) | 767 | if (NULL == peer_entry) |
741 | { | 768 | { |
742 | peer_entry = GNUNET_new (struct PeerEntry); | 769 | peer_entry = new_peer_entry(other_peer); |
743 | peer_entry->id = *other_peer; | ||
744 | GNUNET_assert (GNUNET_OK == | ||
745 | GNUNET_CONTAINER_multipeermap_put (peers, | ||
746 | other_peer, | ||
747 | peer_entry, | ||
748 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
749 | } | 770 | } |
750 | peer_entry->so = GNUNET_SET_accept (request, | 771 | peer_entry->so = GNUNET_SET_accept (request, |
751 | GNUNET_SET_RESULT_ADDED, | 772 | GNUNET_SET_RESULT_ADDED, |