fix memleak
[oweals/gnunet.git] / src / chat / gnunet-service-chat.c
index c41ec90953ad4900da2a8340f04c734817d48c0b..ec988e8fd1d427f7d0e0cec901e26b97bb36e747 100644 (file)
 #include "gnunet_signatures.h"
 #include "chat.h"
 
-#define DEBUG_CHAT_SERVICE GNUNET_NO
+#define DEBUG_CHAT_SERVICE GNUNET_EXTRA_LOGGING
 #define MAX_TRANSMIT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
 #define EXPECTED_NEIGHBOUR_COUNT 16
-#define QUEUE_SIZE 16
 #define MAX_ANONYMOUS_MSG_LIST_LENGTH 16
 
 
@@ -70,7 +69,7 @@ struct ChatClient
   /**
    * Hash of the public key (for convenience).
    */
-  GNUNET_HashCode id;
+  struct GNUNET_HashCode id;
 
   /**
    * Options which the client is willing to receive.
@@ -118,7 +117,7 @@ struct AnonymousMessage
   /**
    * Hash of the message.
    */
-  GNUNET_HashCode hash;
+  struct GNUNET_HashCode hash;
 
 };
 
@@ -136,7 +135,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
 /**
  * The identity of this host.
  */
-static const struct GNUNET_PeerIdentity *me;
+static struct GNUNET_PeerIdentity me;
 
 /**
  * Head of the list of current clients.
@@ -163,7 +162,7 @@ static void
 remember_anonymous_message (const struct P2PReceiveNotificationMessage
                             *p2p_rnmsg)
 {
-  static GNUNET_HashCode hash;
+  static struct GNUNET_HashCode hash;
   struct AnonymousMessage *anon_msg;
   struct AnonymousMessage *prev;
   int anon_list_len;
@@ -193,13 +192,13 @@ remember_anonymous_message (const struct P2PReceiveNotificationMessage
 static int
 lookup_anonymous_message (const struct P2PReceiveNotificationMessage *p2p_rnmsg)
 {
-  static GNUNET_HashCode hash;
+  static struct GNUNET_HashCode hash;
   struct AnonymousMessage *anon_msg;
 
   GNUNET_CRYPTO_hash (p2p_rnmsg, ntohs (p2p_rnmsg->header.size), &hash);
   anon_msg = anonymous_list_head;
   while ((NULL != anon_msg) &&
-         (0 != memcmp (&anon_msg->hash, &hash, sizeof (GNUNET_HashCode))))
+         (0 != memcmp (&anon_msg->hash, &hash, sizeof (struct GNUNET_HashCode))))
     anon_msg = anon_msg->next;
   return (NULL != anon_msg);
 }
@@ -245,7 +244,7 @@ transmit_message_notification_to_peer (void *cls, size_t size, void *buf)
  * Ask to send a message notification to the peer.
  */
 static int
-send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
+send_message_noficiation (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct P2PReceiveNotificationMessage *msg = cls;
   struct ConnectedPeer *cp = value;
@@ -281,7 +280,7 @@ static void
 handle_transmit_request (void *cls, struct GNUNET_SERVER_Client *client,
                          const struct GNUNET_MessageHeader *message)
 {
-  static GNUNET_HashCode all_zeros;
+  static struct GNUNET_HashCode all_zeros;
   const struct TransmitRequestMessage *trmsg;
   struct ReceiveNotificationMessage *rnmsg;
   struct P2PReceiveNotificationMessage *p2p_rnmsg;
@@ -350,7 +349,7 @@ handle_transmit_request (void *cls, struct GNUNET_SERVER_Client *client,
   is_anon = (0 != (ntohl (trmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS));
   if (is_anon)
   {
-    memset (&rnmsg->sender, 0, sizeof (GNUNET_HashCode));
+    memset (&rnmsg->sender, 0, sizeof (struct GNUNET_HashCode));
     rnmsg->sequence_number = 0;
   }
   else
@@ -365,7 +364,7 @@ handle_transmit_request (void *cls, struct GNUNET_SERVER_Client *client,
                 "Encrypting the session key using the public key of '%s'\n",
                 GNUNET_h2s (&trmsg->target));
 #endif
-    if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (GNUNET_HashCode)))
+    if (0 == memcmp (&all_zeros, &trmsg->target, sizeof (struct GNUNET_HashCode)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Malformed message: private, but no target\n");
@@ -378,7 +377,7 @@ handle_transmit_request (void *cls, struct GNUNET_SERVER_Client *client,
     target = client_list_head;
     while ((NULL != target) &&
            (0 !=
-            memcmp (&target->id, &trmsg->target, sizeof (GNUNET_HashCode))))
+            memcmp (&target->id, &trmsg->target, sizeof (struct GNUNET_HashCode))))
       target = target->next;
     if (NULL == target)
     {
@@ -417,7 +416,7 @@ handle_transmit_request (void *cls, struct GNUNET_SERVER_Client *client,
         (pos->client != client))
     {
       if (((!is_priv) ||
-           (0 == memcmp (&trmsg->target, &pos->id, sizeof (GNUNET_HashCode))))
+           (0 == memcmp (&trmsg->target, &pos->id, sizeof (struct GNUNET_HashCode))))
           && (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options))))
       {
         GNUNET_SERVER_notification_context_unicast (nc, pos->client,
@@ -522,7 +521,7 @@ transmit_join_notification_to_peer (void *cls, size_t size, void *buf)
  * Ask to send a join notification to the peer.
  */
 static int
-send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
+send_join_noficiation (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct ChatClient *entry = cls;
   struct ConnectedPeer *cp = value;
@@ -704,7 +703,7 @@ transmit_confirmation_receipt_to_peer (void *cls, size_t size, void *buf)
  * Ask to send a confirmation receipt to the peer.
  */
 static int
-send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value)
+send_confirmation_receipt (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct P2PConfirmationReceiptMessage *receipt = cls;
   struct ConnectedPeer *cp = value;
@@ -755,7 +754,7 @@ handle_acknowledge_request (void *cls, struct GNUNET_SERVER_Client *client,
   author = client_list_head;
   while ((NULL != author) &&
          (0 !=
-          memcmp (&receipt->author, &author->id, sizeof (GNUNET_HashCode))))
+          memcmp (&receipt->author, &author->id, sizeof (struct GNUNET_HashCode))))
     author = author->next;
   if (NULL == author)
   {
@@ -768,7 +767,7 @@ handle_acknowledge_request (void *cls, struct GNUNET_SERVER_Client *client,
   target = client_list_head;
   while ((NULL != target) &&
          (0 !=
-          memcmp (&receipt->target, &target->id, sizeof (GNUNET_HashCode))))
+          memcmp (&receipt->target, &target->id, sizeof (struct GNUNET_HashCode))))
     target = target->next;
   if (NULL == target)
   {
@@ -881,7 +880,7 @@ transmit_leave_notification_to_peer (void *cls, size_t size, void *buf)
  * Ask to send a leave notification to the peer.
  */
 static int
-send_leave_noficiation (void *cls, const GNUNET_HashCode * key, void *value)
+send_leave_noficiation (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct ChatClient *entry = cls;
   struct ConnectedPeer *cp = value;
@@ -981,6 +980,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
  * @param other the other peer involved
  * @param message the actual message
  * @param atsi performance information
+ * @param atsi_count number of entries in atsi
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
@@ -988,8 +988,8 @@ static int
 handle_p2p_join_notification (void *cls,
                               const struct GNUNET_PeerIdentity *other,
                               const struct GNUNET_MessageHeader *message,
-                              const struct GNUNET_TRANSPORT_ATS_Information
-                              *atsi)
+                              const struct GNUNET_ATS_Information *atsi,
+                              unsigned int atsi_count)
 {
   const struct P2PJoinNotificationMessage *p2p_jnmsg;
   char *room_name;
@@ -1000,7 +1000,7 @@ handle_p2p_join_notification (void *cls,
   struct ChatClient *new_entry;
   struct ChatClient *entry;
   struct JoinNotificationMessage *jnmsg;
-  GNUNET_HashCode id;
+  struct GNUNET_HashCode id;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got P2P join notification\n");
   if (ntohs (message->size) <= sizeof (struct P2PJoinNotificationMessage))
@@ -1025,7 +1025,7 @@ handle_p2p_join_notification (void *cls,
   entry = client_list_head;
   while (NULL != entry)
   {
-    if (0 == memcmp (&entry->id, &id, sizeof (GNUNET_HashCode)))
+    if (0 == memcmp (&entry->id, &id, sizeof (struct GNUNET_HashCode)))
     {
 #if DEBUG_CHAT_SERVICE
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1097,6 +1097,7 @@ handle_p2p_join_notification (void *cls,
  * @param other the other peer involved
  * @param message the actual message
  * @param atsi performance information
+ * @param atsi_count number of entries in atsi
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
@@ -1104,11 +1105,11 @@ static int
 handle_p2p_leave_notification (void *cls,
                                const struct GNUNET_PeerIdentity *other,
                                const struct GNUNET_MessageHeader *message,
-                               const struct GNUNET_TRANSPORT_ATS_Information
-                               *atsi)
+                               const struct GNUNET_ATS_Information *atsi,
+                               unsigned int atsi_count)
 {
   const struct P2PLeaveNotificationMessage *p2p_lnmsg;
-  GNUNET_HashCode id;
+  struct GNUNET_HashCode id;
   struct ChatClient *pos;
   struct ChatClient *prev;
   struct ChatClient *entry;
@@ -1123,7 +1124,7 @@ handle_p2p_leave_notification (void *cls,
   prev = NULL;
   while (NULL != pos)
   {
-    if (0 == memcmp (&pos->id, &id, sizeof (GNUNET_HashCode)))
+    if (0 == memcmp (&pos->id, &id, sizeof (struct GNUNET_HashCode)))
       break;
     prev = pos;
     pos = pos->next;
@@ -1178,6 +1179,7 @@ handle_p2p_leave_notification (void *cls,
  * @param other the other peer involved
  * @param message the actual message
  * @param atsi performance information
+ * @param atsi_count number of entries in atsi
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
@@ -1185,15 +1187,15 @@ static int
 handle_p2p_message_notification (void *cls,
                                  const struct GNUNET_PeerIdentity *other,
                                  const struct GNUNET_MessageHeader *message,
-                                 const struct GNUNET_TRANSPORT_ATS_Information
-                                 *atsi)
+                                 const struct GNUNET_ATS_Information *atsi,
+                                 unsigned int atsi_count)
 {
   const struct P2PReceiveNotificationMessage *p2p_rnmsg;
   struct P2PReceiveNotificationMessage *my_p2p_rnmsg;
   struct ReceiveNotificationMessage *rnmsg;
   struct ChatClient *sender;
   struct ChatClient *pos;
-  static GNUNET_HashCode all_zeros;
+  static struct GNUNET_HashCode all_zeros;
   int is_priv;
   int is_anon;
   uint16_t msg_len;
@@ -1244,7 +1246,7 @@ handle_p2p_message_notification (void *cls,
     sender = client_list_head;
     while ((NULL != sender) &&
            (0 !=
-            memcmp (&sender->id, &p2p_rnmsg->sender, sizeof (GNUNET_HashCode))))
+            memcmp (&sender->id, &p2p_rnmsg->sender, sizeof (struct GNUNET_HashCode))))
       sender = sender->next;
     if (NULL == sender)
     {
@@ -1285,7 +1287,7 @@ handle_p2p_message_notification (void *cls,
   rnmsg->reserved = htonl (0);
   rnmsg->timestamp = p2p_rnmsg->timestamp;
   is_priv =
-      (0 != memcmp (&all_zeros, &p2p_rnmsg->target, sizeof (GNUNET_HashCode)));
+      (0 != memcmp (&all_zeros, &p2p_rnmsg->target, sizeof (struct GNUNET_HashCode)));
   if (is_priv)
     memcpy (&rnmsg->encrypted_key, &p2p_rnmsg->encrypted_key,
             sizeof (struct GNUNET_CRYPTO_RsaEncryptedData));
@@ -1298,7 +1300,7 @@ handle_p2p_message_notification (void *cls,
     {
       if (((!is_priv) ||
            (0 ==
-            memcmp (&p2p_rnmsg->target, &pos->id, sizeof (GNUNET_HashCode)))) &&
+            memcmp (&p2p_rnmsg->target, &pos->id, sizeof (struct GNUNET_HashCode)))) &&
           (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options))))
       {
         GNUNET_SERVER_notification_context_unicast (nc, pos->client,
@@ -1329,13 +1331,15 @@ handle_p2p_message_notification (void *cls,
  * @param other the other peer involved
  * @param message the actual message
  * @param atsi performance information
+ * @param atsi_count number of entries in atsi
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other,
                          const struct GNUNET_MessageHeader *message,
-                         const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                         const struct GNUNET_ATS_Information *atsi,
+                         unsigned int atsi_count)
 {
   struct ChatClient *entry;
   struct GNUNET_CORE_TransmitHandle *th;
@@ -1370,6 +1374,7 @@ handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other,
  * @param other the other peer involved
  * @param message the actual message
  * @param atsi performance information
+ * @param atsi_count number of entries in atsi
  * @return GNUNET_OK to keep the connection open,
  *         GNUNET_SYSERR to close it (signal serious error)
  */
@@ -1377,8 +1382,8 @@ static int
 handle_p2p_confirmation_receipt (void *cls,
                                  const struct GNUNET_PeerIdentity *other,
                                  const struct GNUNET_MessageHeader *message,
-                                 const struct GNUNET_TRANSPORT_ATS_Information
-                                 *atsi)
+                                 const struct GNUNET_ATS_Information *atsi,
+                                 unsigned int atsi_count)
 {
   const struct P2PConfirmationReceiptMessage *p2p_crmsg;
   struct P2PConfirmationReceiptMessage *my_p2p_crmsg;
@@ -1391,7 +1396,7 @@ handle_p2p_confirmation_receipt (void *cls,
   target = client_list_head;
   while ((NULL != target) &&
          (0 !=
-          memcmp (&target->id, &p2p_crmsg->target, sizeof (GNUNET_HashCode))))
+          memcmp (&target->id, &p2p_crmsg->target, sizeof (struct GNUNET_HashCode))))
     target = target->next;
   if (NULL == target)
   {
@@ -1415,7 +1420,7 @@ handle_p2p_confirmation_receipt (void *cls,
   author = client_list_head;
   while ((NULL != author) &&
          (0 !=
-          memcmp (&author->id, &p2p_crmsg->author, sizeof (GNUNET_HashCode))))
+          memcmp (&author->id, &p2p_crmsg->author, sizeof (struct GNUNET_HashCode))))
     author = author->next;
   if (NULL == author)
   {
@@ -1515,15 +1520,17 @@ transmit_sync_request_to_peer (void *cls, size_t size, void *buf)
  * @param cls closure
  * @param peer peer identity this notification is about
  * @param atsi performance data
+ * @param atsi_count number of entries in atsi
  */
 static void
 peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
-                      const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+                      const struct GNUNET_ATS_Information *atsi,
+                      unsigned int atsi_count)
 {
   struct ConnectedPeer *cp;
   struct GNUNET_CORE_TransmitHandle *th;
 
-  if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
+  if (0 == memcmp (peer, &me, sizeof (struct GNUNET_PeerIdentity)))
     return;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer connected: %s\n",
               GNUNET_i2s (peer));
@@ -1556,7 +1563,7 @@ peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @return GNUNET_YES (we should continue to iterate)
  */
 static int
-clean_peer (void *cls, const GNUNET_HashCode * key, void *value)
+clean_peer (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct ConnectedPeer *cp;
   const struct GNUNET_PeerIdentity *peer =
@@ -1584,11 +1591,11 @@ static void
 peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
 
-  if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity)))
+  if (0 == memcmp (peer, &me, sizeof (struct GNUNET_PeerIdentity)))
     return;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer disconnected: %s\n",
               GNUNET_i2s (peer));
-  clean_peer (NULL, (const GNUNET_HashCode *) peer, NULL);
+  clean_peer (NULL, (const struct GNUNET_HashCode *) peer, NULL);
 }
 
 
@@ -1641,15 +1648,13 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param cls closure, NULL
  * @param server handle to the server for this service
  * @param my_identity the public identity of this peer
- * @param publicKey the public key of this peer
  */
 static void
 core_init (void *cls, struct GNUNET_CORE_Handle *server,
-           const struct GNUNET_PeerIdentity *my_identity,
-           const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+           const struct GNUNET_PeerIdentity *my_identity)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Core initialized\n");
-  me = my_identity;
+  me = *my_identity;
 }
 
 
@@ -1701,13 +1706,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   cfg = c;
   nc = GNUNET_SERVER_notification_context_create (server, 16);
   connected_peers =
-      GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT);
+    GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT, GNUNET_NO);
   GNUNET_SERVER_add_handlers (server, handlers);
   core =
-      GNUNET_CORE_connect (cfg, QUEUE_SIZE, NULL, &core_init,
+      GNUNET_CORE_connect (cfg, NULL, &core_init,
                            &peer_connect_handler, &peer_disconnect_handler,
-                           NULL, NULL, GNUNET_NO, NULL, GNUNET_NO,
-                           p2p_handlers);
+                           NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers);
   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
                                 NULL);