aboutsummaryrefslogtreecommitdiff
path: root/src/chat
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-03-04 08:09:33 +0000
committerChristian Grothoff <christian@grothoff.org>2011-03-04 08:09:33 +0000
commite3445ef22cc8478bb6cdca2b35f20f7f3325c697 (patch)
tree30117bb239a8b5bc03366e18a4901f46a3945147 /src/chat
parentef147778f4ada88486a3d0584b34ba8889742249 (diff)
downloadgnunet-e3445ef22cc8478bb6cdca2b35f20f7f3325c697.tar.gz
gnunet-e3445ef22cc8478bb6cdca2b35f20f7f3325c697.zip
chat update -- Mantis 1665
Diffstat (limited to 'src/chat')
-rw-r--r--src/chat/chat.c16
-rw-r--r--src/chat/gnunet-service-chat.c305
2 files changed, 199 insertions, 122 deletions
diff --git a/src/chat/chat.c b/src/chat/chat.c
index f3e3470a0..5f4e121dc 100644
--- a/src/chat/chat.c
+++ b/src/chat/chat.c
@@ -149,7 +149,7 @@ struct GNUNET_CHAT_SendReceiptContext
149 * Ask client to send a join request. 149 * Ask client to send a join request.
150 */ 150 */
151static int 151static int
152GNUNET_CHAT_rejoin_room (struct GNUNET_CHAT_Room *chat_room); 152rejoin_room (struct GNUNET_CHAT_Room *chat_room);
153 153
154 154
155/** 155/**
@@ -448,7 +448,7 @@ receive_results (void *cls,
448 if (NULL == msg) 448 if (NULL == msg)
449 { 449 {
450 GNUNET_break (0); 450 GNUNET_break (0);
451 GNUNET_CHAT_rejoin_room (chat_room); 451 rejoin_room (chat_room);
452 return; 452 return;
453 } 453 }
454 process_result (chat_room, msg); 454 process_result (chat_room, msg);
@@ -468,8 +468,8 @@ receive_results (void *cls,
468 * Returns the private key on success, NULL on error. 468 * Returns the private key on success, NULL on error.
469 */ 469 */
470static struct GNUNET_CRYPTO_RsaPrivateKey * 470static struct GNUNET_CRYPTO_RsaPrivateKey *
471GNUNET_CHAT_initPrivateKey (const struct GNUNET_CONFIGURATION_Handle *cfg, 471init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg,
472 const char *nick_name) 472 const char *nick_name)
473{ 473{
474 char *home; 474 char *home;
475 char *keyfile; 475 char *keyfile;
@@ -548,7 +548,7 @@ transmit_join_request (void *cls,
548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
549 "Could not transmit join request, retrying...\n"); 549 "Could not transmit join request, retrying...\n");
550#endif 550#endif
551 GNUNET_CHAT_rejoin_room (chat_room); 551 rejoin_room (chat_room);
552 return 0; 552 return 0;
553 } 553 }
554#if DEBUG_CHAT 554#if DEBUG_CHAT
@@ -591,7 +591,7 @@ transmit_join_request (void *cls,
591 * Ask to send a join request. 591 * Ask to send a join request.
592 */ 592 */
593static int 593static int
594GNUNET_CHAT_rejoin_room (struct GNUNET_CHAT_Room *chat_room) 594rejoin_room (struct GNUNET_CHAT_Room *chat_room)
595{ 595{
596 size_t size_of_join; 596 size_t size_of_join;
597 597
@@ -682,7 +682,7 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
682#if DEBUG_CHAT 682#if DEBUG_CHAT
683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Joining the room '%s'\n", room_name); 683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Joining the room '%s'\n", room_name);
684#endif 684#endif
685 priv_key = GNUNET_CHAT_initPrivateKey (cfg, nick_name); 685 priv_key = init_private_key (cfg, nick_name);
686 if (NULL == priv_key) 686 if (NULL == priv_key)
687 return NULL; 687 return NULL;
688 GNUNET_CRYPTO_rsa_key_get_public (priv_key, &pub_key); 688 GNUNET_CRYPTO_rsa_key_get_public (priv_key, &pub_key);
@@ -732,7 +732,7 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg,
732 chat_room->cfg = cfg; 732 chat_room->cfg = cfg;
733 chat_room->client = client; 733 chat_room->client = client;
734 chat_room->members = NULL; 734 chat_room->members = NULL;
735 if (GNUNET_SYSERR == GNUNET_CHAT_rejoin_room (chat_room)) 735 if (GNUNET_SYSERR == rejoin_room (chat_room))
736 { 736 {
737 GNUNET_CHAT_leave_room (chat_room); 737 GNUNET_CHAT_leave_room (chat_room);
738 return NULL; 738 return NULL;
diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c
index 69318e4e8..6a5c5790a 100644
--- a/src/chat/gnunet-service-chat.c
+++ b/src/chat/gnunet-service-chat.c
@@ -35,6 +35,7 @@
35 35
36#define DEBUG_CHAT_SERVICE GNUNET_NO 36#define DEBUG_CHAT_SERVICE GNUNET_NO
37#define MAX_TRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 37#define MAX_TRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
38#define EXPECTED_NEIGHBOUR_COUNT 16
38#define QUEUE_SIZE 16 39#define QUEUE_SIZE 16
39#define MAX_ANONYMOUS_MSG_LIST_LENGTH 16 40#define MAX_ANONYMOUS_MSG_LIST_LENGTH 16
40 41
@@ -95,6 +96,19 @@ struct ChatClient
95}; 96};
96 97
97/** 98/**
99 * Information about a peer that we are connected to.
100 * We track data that is useful for determining which
101 * peers should receive our requests.
102 */
103struct ConnectedPeer
104{
105 /**
106 * The peer's identity.
107 */
108 GNUNET_PEER_Id pid;
109};
110
111/**
98 * Linked list of recent anonymous messages. 112 * Linked list of recent anonymous messages.
99 */ 113 */
100struct AnonymousMessage 114struct AnonymousMessage
@@ -138,6 +152,11 @@ struct GNUNET_SERVER_NotificationContext *nc = NULL;
138 * Head of the list of recent anonymous messages. 152 * Head of the list of recent anonymous messages.
139 */ 153 */
140static struct AnonymousMessage *anonymous_list_head = NULL; 154static struct AnonymousMessage *anonymous_list_head = NULL;
155
156/**
157 * Map of peer identifiers to "struct ConnectedPeer" (for that peer).
158 */
159static struct GNUNET_CONTAINER_MultiHashMap *connected_peers;
141 160
142 161
143static void 162static void
@@ -226,33 +245,32 @@ transmit_message_notification_to_peer (void *cls,
226/** 245/**
227 * Ask to send a message notification to the peer. 246 * Ask to send a message notification to the peer.
228 */ 247 */
229static void 248static int
230send_message_noficiation (void *cls, 249send_message_noficiation (void *cls,
231 const struct GNUNET_PeerIdentity *peer, 250 const GNUNET_HashCode *key,
232 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 251 void *value)
233{ 252{
234 struct P2PReceiveNotificationMessage *msg = cls; 253 struct P2PReceiveNotificationMessage *msg = cls;
254 struct ConnectedPeer *cp = value;
255 struct GNUNET_PeerIdentity pid;
235 struct P2PReceiveNotificationMessage *my_msg; 256 struct P2PReceiveNotificationMessage *my_msg;
236 struct GNUNET_CORE_TransmitHandle *th;
237 257
238 if (NULL == peer) 258 GNUNET_PEER_resolve (cp->pid, &pid);
239 GNUNET_free (msg);
240 else
241 {
242#if DEBUG_CHAT_SERVICE 259#if DEBUG_CHAT_SERVICE
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "Sending message notification to `%s'\n", GNUNET_i2s (peer)); 261 "Sending message notification to `%s'\n", GNUNET_i2s (&pid));
245#endif 262#endif
246 my_msg = GNUNET_memdup (msg, ntohs (msg->header.size)); 263 my_msg = GNUNET_memdup (msg, ntohs (msg->header.size));
247 th = GNUNET_CORE_notify_transmit_ready (core, 264 if (NULL == GNUNET_CORE_notify_transmit_ready (core,
248 1, 265 1,
249 MAX_TRANSMIT_DELAY, 266 MAX_TRANSMIT_DELAY,
250 peer, 267 &pid,
251 ntohs (msg->header.size), 268 ntohs (msg->header.size),
252 &transmit_message_notification_to_peer, 269 &transmit_message_notification_to_peer,
253 my_msg); 270 my_msg))
254 GNUNET_assert (NULL != th); 271 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
255 } 272 _("Failed to queue a message notification\n"));
273 return GNUNET_YES;
256} 274}
257 275
258 276
@@ -460,9 +478,10 @@ handle_transmit_request (void *cls,
460 p2p_rnmsg->target = trmsg->target; 478 p2p_rnmsg->target = trmsg->target;
461 if (is_anon) 479 if (is_anon)
462 remember_anonymous_message (p2p_rnmsg); 480 remember_anonymous_message (p2p_rnmsg);
463 GNUNET_CORE_iterate_peers (cfg, 481 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
464 &send_message_noficiation, 482 &send_message_noficiation,
465 p2p_rnmsg); 483 p2p_rnmsg);
484 GNUNET_free (p2p_rnmsg);
466 GNUNET_SERVER_receive_done (client, GNUNET_OK); 485 GNUNET_SERVER_receive_done (client, GNUNET_OK);
467 GNUNET_free (rnmsg); 486 GNUNET_free (rnmsg);
468} 487}
@@ -515,33 +534,34 @@ transmit_join_notification_to_peer (void *cls,
515/** 534/**
516 * Ask to send a join notification to the peer. 535 * Ask to send a join notification to the peer.
517 */ 536 */
518static void 537static int
519send_join_noficiation (void *cls, 538send_join_noficiation (void *cls,
520 const struct GNUNET_PeerIdentity *peer, 539 const GNUNET_HashCode *key,
521 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 540 void *value)
522{ 541{
523 struct ChatClient *entry = cls; 542 struct ChatClient *entry = cls;
524 struct GNUNET_CORE_TransmitHandle *th; 543 struct ConnectedPeer *cp = value;
544 struct GNUNET_PeerIdentity pid;
525 size_t msg_size; 545 size_t msg_size;
526 546
527 if (NULL != peer) 547 GNUNET_PEER_resolve (cp->pid, &pid);
528 {
529#if DEBUG_CHAT_SERVICE 548#if DEBUG_CHAT_SERVICE
530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
531 "Sending join notification to `%s'\n", GNUNET_i2s (peer)); 550 "Sending join notification to `%s'\n", GNUNET_i2s (&pid));
532#endif 551#endif
533 msg_size = sizeof (struct P2PJoinNotificationMessage) + 552 msg_size = sizeof (struct P2PJoinNotificationMessage) +
534 strlen (entry->room) + 553 strlen (entry->room) +
535 entry->meta_len; 554 entry->meta_len;
536 th = GNUNET_CORE_notify_transmit_ready (core, 555 if (NULL == GNUNET_CORE_notify_transmit_ready (core,
537 1, 556 1,
538 MAX_TRANSMIT_DELAY, 557 MAX_TRANSMIT_DELAY,
539 peer, 558 &pid,
540 msg_size, 559 msg_size,
541 &transmit_join_notification_to_peer, 560 &transmit_join_notification_to_peer,
542 entry); 561 entry))
543 GNUNET_assert (NULL != th); 562 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
544 } 563 _("Failed to queue a join notification\n"));
564 return GNUNET_YES;
545} 565}
546 566
547 567
@@ -662,9 +682,9 @@ handle_join_request (void *cls,
662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
663 "Broadcasting join notification to neighbour peers\n"); 683 "Broadcasting join notification to neighbour peers\n");
664#endif 684#endif
665 GNUNET_CORE_iterate_peers (cfg, 685 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
666 &send_join_noficiation, 686 &send_join_noficiation,
667 new_entry); 687 new_entry);
668 GNUNET_SERVER_receive_done (client, GNUNET_OK); 688 GNUNET_SERVER_receive_done (client, GNUNET_OK);
669 GNUNET_free (jnmsg); 689 GNUNET_free (jnmsg);
670} 690}
@@ -710,36 +730,35 @@ transmit_confirmation_receipt_to_peer (void *cls,
710/** 730/**
711 * Ask to send a confirmation receipt to the peer. 731 * Ask to send a confirmation receipt to the peer.
712 */ 732 */
713static void 733static int
714send_confirmation_receipt (void *cls, 734send_confirmation_receipt (void *cls,
715 const struct GNUNET_PeerIdentity *peer, 735 const GNUNET_HashCode *key,
716 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 736 void *value)
717{ 737{
718 struct P2PConfirmationReceiptMessage *receipt = cls; 738 struct P2PConfirmationReceiptMessage *receipt = cls;
739 struct ConnectedPeer *cp = value;
740 struct GNUNET_PeerIdentity pid;
719 struct P2PConfirmationReceiptMessage *my_receipt; 741 struct P2PConfirmationReceiptMessage *my_receipt;
720 struct GNUNET_CORE_TransmitHandle *th;
721 size_t msg_size; 742 size_t msg_size;
722 743
723 if (NULL == peer) 744 GNUNET_PEER_resolve (cp->pid, &pid);
724 GNUNET_free (receipt);
725 else
726 {
727#if DEBUG_CHAT_SERVICE 745#if DEBUG_CHAT_SERVICE
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
729 "Sending confirmation receipt to `%s'\n", GNUNET_i2s (peer)); 747 "Sending confirmation receipt to `%s'\n", GNUNET_i2s (&pid));
730#endif 748#endif
731 msg_size = sizeof (struct P2PConfirmationReceiptMessage); 749 msg_size = sizeof (struct P2PConfirmationReceiptMessage);
732 my_receipt = GNUNET_memdup (receipt, 750 my_receipt = GNUNET_memdup (receipt,
733 sizeof (struct P2PConfirmationReceiptMessage)); 751 sizeof (struct P2PConfirmationReceiptMessage));
734 th = GNUNET_CORE_notify_transmit_ready (core, 752 if (NULL == GNUNET_CORE_notify_transmit_ready (core,
735 1, 753 1,
736 MAX_TRANSMIT_DELAY, 754 MAX_TRANSMIT_DELAY,
737 peer, 755 &pid,
738 msg_size, 756 msg_size,
739 &transmit_confirmation_receipt_to_peer, 757 &transmit_confirmation_receipt_to_peer,
740 my_receipt); 758 my_receipt))
741 GNUNET_assert (NULL != th); 759 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
742 } 760 _("Failed to queue a confirmation receipt\n"));
761 return GNUNET_YES;
743} 762}
744 763
745 764
@@ -812,9 +831,10 @@ handle_acknowledge_request (void *cls,
812 p2p_crmsg->author = receipt->author; 831 p2p_crmsg->author = receipt->author;
813 p2p_crmsg->content = receipt->content; 832 p2p_crmsg->content = receipt->content;
814 p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number); 833 p2p_crmsg->sequence_number = htonl (target->rcpt_sequence_number);
815 GNUNET_CORE_iterate_peers (cfg, 834 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
816 &send_confirmation_receipt, 835 &send_confirmation_receipt,
817 p2p_crmsg); 836 p2p_crmsg);
837 GNUNET_free (p2p_crmsg);
818 } 838 }
819 else 839 else
820 { 840 {
@@ -896,40 +916,35 @@ transmit_leave_notification_to_peer (void *cls,
896/** 916/**
897 * Ask to send a leave notification to the peer. 917 * Ask to send a leave notification to the peer.
898 */ 918 */
899static void 919static int
900send_leave_noficiation (void *cls, 920send_leave_noficiation (void *cls,
901 const struct GNUNET_PeerIdentity *peer, 921 const GNUNET_HashCode *key,
902 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 922 void *value)
903{ 923{
904 struct ChatClient *entry = cls; 924 struct ChatClient *entry = cls;
925 struct ConnectedPeer *cp = value;
926 struct GNUNET_PeerIdentity pid;
905 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key; 927 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key;
906 size_t msg_size; 928 size_t msg_size;
907 929
908 if (NULL == peer) 930 GNUNET_PEER_resolve (cp->pid, &pid);
909 {
910 GNUNET_free (entry->room);
911 GNUNET_free_non_null (entry->member_info);
912 GNUNET_free (entry);
913 }
914 else
915 {
916#if DEBUG_CHAT_SERVICE 931#if DEBUG_CHAT_SERVICE
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
918 "Sending leave notification to `%s'\n", GNUNET_i2s (peer)); 933 "Sending leave notification to `%s'\n", GNUNET_i2s (&pid));
919#endif 934#endif
920 msg_size = sizeof (struct P2PLeaveNotificationMessage); 935 msg_size = sizeof (struct P2PLeaveNotificationMessage);
921 public_key = GNUNET_memdup (&entry->public_key, 936 public_key = GNUNET_memdup (&entry->public_key,
922 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 937 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
923 if (NULL == GNUNET_CORE_notify_transmit_ready (core, 938 if (NULL == GNUNET_CORE_notify_transmit_ready (core,
924 1, 939 1,
925 MAX_TRANSMIT_DELAY, 940 MAX_TRANSMIT_DELAY,
926 peer, 941 &pid,
927 msg_size, 942 msg_size,
928 &transmit_leave_notification_to_peer, 943 &transmit_leave_notification_to_peer,
929 public_key)) 944 public_key))
930 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 945 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
931 _("Failed to queue a leave notification\n")); 946 _("Failed to queue a leave notification\n"));
932 } 947 return GNUNET_YES;
933} 948}
934 949
935 950
@@ -994,9 +1009,12 @@ handle_client_disconnect (void *cls,
994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
995 "Broadcasting leave notification to neighbour peers\n"); 1010 "Broadcasting leave notification to neighbour peers\n");
996#endif 1011#endif
997 GNUNET_CORE_iterate_peers (cfg, 1012 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
998 &send_leave_noficiation, 1013 &send_leave_noficiation,
999 pos); 1014 pos);
1015 GNUNET_free (pos->room);
1016 GNUNET_free_non_null (pos->member_info);
1017 GNUNET_free (pos);
1000} 1018}
1001 1019
1002 1020
@@ -1112,9 +1130,9 @@ handle_p2p_join_notification (void *cls,
1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1113 "Broadcasting join notification to neighbour peers\n"); 1131 "Broadcasting join notification to neighbour peers\n");
1114#endif 1132#endif
1115 GNUNET_CORE_iterate_peers (cfg, 1133 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
1116 &send_join_noficiation, 1134 &send_join_noficiation,
1117 new_entry); 1135 new_entry);
1118 GNUNET_free (jnmsg); 1136 GNUNET_free (jnmsg);
1119 return GNUNET_OK; 1137 return GNUNET_OK;
1120} 1138}
@@ -1194,9 +1212,12 @@ handle_p2p_leave_notification (void *cls,
1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1195 "Broadcasting leave notification to neighbour peers\n"); 1213 "Broadcasting leave notification to neighbour peers\n");
1196#endif 1214#endif
1197 GNUNET_CORE_iterate_peers (cfg, 1215 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
1198 &send_leave_noficiation, 1216 &send_leave_noficiation,
1199 pos); 1217 pos);
1218 GNUNET_free (pos->room);
1219 GNUNET_free_non_null (pos->member_info);
1220 GNUNET_free (pos);
1200 return GNUNET_OK; 1221 return GNUNET_OK;
1201} 1222}
1202 1223
@@ -1347,9 +1368,9 @@ handle_p2p_message_notification (void *cls,
1347 "Broadcasting message notification to neighbour peers\n"); 1368 "Broadcasting message notification to neighbour peers\n");
1348#endif 1369#endif
1349 my_p2p_rnmsg = GNUNET_memdup (p2p_rnmsg, ntohs (p2p_rnmsg->header.size)); 1370 my_p2p_rnmsg = GNUNET_memdup (p2p_rnmsg, ntohs (p2p_rnmsg->header.size));
1350 GNUNET_CORE_iterate_peers (cfg, 1371 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
1351 &send_message_noficiation, 1372 &send_message_noficiation,
1352 my_p2p_rnmsg); 1373 my_p2p_rnmsg);
1353 GNUNET_free (rnmsg); 1374 GNUNET_free (rnmsg);
1354 return GNUNET_OK; 1375 return GNUNET_OK;
1355} 1376}
@@ -1470,9 +1491,10 @@ handle_p2p_confirmation_receipt (void *cls,
1470 " Broadcasting receipt to neighbour peers\n"); 1491 " Broadcasting receipt to neighbour peers\n");
1471#endif 1492#endif
1472 my_p2p_crmsg = GNUNET_memdup (p2p_crmsg, sizeof (struct P2PConfirmationReceiptMessage)); 1493 my_p2p_crmsg = GNUNET_memdup (p2p_crmsg, sizeof (struct P2PConfirmationReceiptMessage));
1473 GNUNET_CORE_iterate_peers (cfg, 1494 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
1474 &send_confirmation_receipt, 1495 &send_confirmation_receipt,
1475 my_p2p_crmsg); 1496 my_p2p_crmsg);
1497 GNUNET_free (my_p2p_crmsg);
1476 } 1498 }
1477 else 1499 else
1478 { 1500 {
@@ -1559,12 +1581,13 @@ peer_connect_handler (void *cls,
1559 const struct GNUNET_PeerIdentity *peer, 1581 const struct GNUNET_PeerIdentity *peer,
1560 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1582 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1561{ 1583{
1584 struct ConnectedPeer *cp;
1562 struct GNUNET_CORE_TransmitHandle *th; 1585 struct GNUNET_CORE_TransmitHandle *th;
1563 1586
1564 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1565 "Peer connected: %s\n", GNUNET_i2s (peer));
1566 if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) 1587 if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
1567 return; 1588 return;
1589 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1590 "Peer connected: %s\n", GNUNET_i2s (peer));
1568 th = GNUNET_CORE_notify_transmit_ready (core, 1591 th = GNUNET_CORE_notify_transmit_ready (core,
1569 1, 1592 1,
1570 MAX_TRANSMIT_DELAY, 1593 MAX_TRANSMIT_DELAY,
@@ -1573,6 +1596,50 @@ peer_connect_handler (void *cls,
1573 &transmit_sync_request_to_peer, 1596 &transmit_sync_request_to_peer,
1574 NULL); 1597 NULL);
1575 GNUNET_assert (NULL != th); 1598 GNUNET_assert (NULL != th);
1599 cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
1600 &peer->hashPubKey);
1601 if (NULL != cp)
1602 {
1603 GNUNET_break (0);
1604 return;
1605 }
1606 cp = GNUNET_malloc (sizeof (struct ConnectedPeer));
1607 cp->pid = GNUNET_PEER_intern (peer);
1608 GNUNET_break (GNUNET_OK ==
1609 GNUNET_CONTAINER_multihashmap_put (connected_peers,
1610 &peer->hashPubKey,
1611 cp,
1612 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1613}
1614
1615
1616/**
1617 * Iterator to free peer entries.
1618 *
1619 * @param cls closure, unused
1620 * @param key current key code
1621 * @param value value in the hash map (peer entry)
1622 * @return GNUNET_YES (we should continue to iterate)
1623 */
1624static int
1625clean_peer (void *cls,
1626 const GNUNET_HashCode * key,
1627 void *value)
1628{
1629 struct ConnectedPeer *cp;
1630 const struct GNUNET_PeerIdentity *peer = (const struct GNUNET_PeerIdentity *) key;
1631
1632 cp = GNUNET_CONTAINER_multihashmap_get (connected_peers,
1633 &peer->hashPubKey);
1634 if (cp == NULL)
1635 return GNUNET_YES;
1636 GNUNET_break (GNUNET_YES ==
1637 GNUNET_CONTAINER_multihashmap_remove (connected_peers,
1638 &peer->hashPubKey,
1639 cp));
1640 GNUNET_PEER_change_rc (cp->pid, -1);
1641 GNUNET_free (cp);
1642 return GNUNET_YES;
1576} 1643}
1577 1644
1578 1645
@@ -1586,8 +1653,12 @@ static void
1586peer_disconnect_handler (void *cls, 1653peer_disconnect_handler (void *cls,
1587 const struct GNUNET_PeerIdentity *peer) 1654 const struct GNUNET_PeerIdentity *peer)
1588{ 1655{
1656
1657 if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
1658 return;
1589 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1659 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1590 "Peer disconnected: %s\n", GNUNET_i2s (peer)); 1660 "Peer disconnected: %s\n", GNUNET_i2s (peer));
1661 clean_peer (NULL, (const GNUNET_HashCode *) peer, NULL);
1591} 1662}
1592 1663
1593 1664
@@ -1629,6 +1700,11 @@ cleanup_task (void *cls,
1629 GNUNET_free (anonymous_list_head); 1700 GNUNET_free (anonymous_list_head);
1630 anonymous_list_head = next_msg; 1701 anonymous_list_head = next_msg;
1631 } 1702 }
1703 GNUNET_CONTAINER_multihashmap_iterate (connected_peers,
1704 &clean_peer,
1705 NULL);
1706 GNUNET_CONTAINER_multihashmap_destroy (connected_peers);
1707 connected_peers = NULL;
1632} 1708}
1633 1709
1634 1710
@@ -1701,6 +1777,7 @@ run (void *cls,
1701 NULL); 1777 NULL);
1702 cfg = c; 1778 cfg = c;
1703 nc = GNUNET_SERVER_notification_context_create (server, 16); 1779 nc = GNUNET_SERVER_notification_context_create (server, 16);
1780 connected_peers = GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT);
1704 GNUNET_SERVER_add_handlers (server, handlers); 1781 GNUNET_SERVER_add_handlers (server, handlers);
1705 core = GNUNET_CORE_connect (cfg, 1782 core = GNUNET_CORE_connect (cfg,
1706 QUEUE_SIZE, 1783 QUEUE_SIZE,