X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fchat%2Fgnunet-service-chat.c;h=ec988e8fd1d427f7d0e0cec901e26b97bb36e747;hb=d0b4927e6ab7e8b9874dd7807055e77fb4c5163f;hp=7afa18d6867de50db8f8ff1964bd05ea132e690c;hpb=502af2167f7c218366666ca4944bd7cc54b5b19a;p=oweals%2Fgnunet.git diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c index 7afa18d68..ec988e8fd 100644 --- a/src/chat/gnunet-service-chat.c +++ b/src/chat/gnunet-service-chat.c @@ -20,7 +20,7 @@ /** * @file chat/gnunet-service-chat.c - * @brief service providing chat functionality + * @brief service providing chat functionality * @author Christian Grothoff * @author Vitaly Minko */ @@ -33,10 +33,9 @@ #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; @@ -254,18 +253,15 @@ send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_PEER_resolve (cp->pid, &pid); #if DEBUG_CHAT_SERVICE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending message notification to `%s'\n", GNUNET_i2s (&pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message notification to `%s'\n", + GNUNET_i2s (&pid)); #endif my_msg = GNUNET_memdup (msg, ntohs (msg->header.size)); - if (NULL == GNUNET_CORE_notify_transmit_ready (core, - GNUNET_NO, - 1, - MAX_TRANSMIT_DELAY, - &pid, - ntohs (msg->header.size), - &transmit_message_notification_to_peer, - my_msg)) + if (NULL == + GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, MAX_TRANSMIT_DELAY, + &pid, ntohs (msg->header.size), + &transmit_message_notification_to_peer, + my_msg)) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to queue a message notification\n")); return GNUNET_YES; @@ -281,11 +277,10 @@ send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value) * @param message the actual message */ static void -handle_transmit_request (void *cls, - struct GNUNET_SERVER_Client *client, +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; @@ -316,12 +311,11 @@ handle_transmit_request (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n"); #endif GNUNET_CRYPTO_aes_create_session_key (&key); - msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1], - msg_len, - &key, - (const struct - GNUNET_CRYPTO_AesInitializationVector - *) INITVALUE, encrypted_msg); + msg_len = + GNUNET_CRYPTO_aes_encrypt (&trmsg[1], msg_len, &key, + (const struct + GNUNET_CRYPTO_AesInitializationVector *) + INITVALUE, encrypted_msg); if (-1 == msg_len) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -332,8 +326,8 @@ handle_transmit_request (void *cls, } } rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); - rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + - msg_len); + rnmsg->header.size = + htons (sizeof (struct ReceiveNotificationMessage) + msg_len); rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); rnmsg->msg_options = trmsg->msg_options; rnmsg->timestamp = trmsg->timestamp; @@ -355,7 +349,7 @@ handle_transmit_request (void *cls, 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 @@ -370,7 +364,7 @@ handle_transmit_request (void *cls, "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"); @@ -382,8 +376,8 @@ handle_transmit_request (void *cls, memcpy (&rnmsg[1], encrypted_msg, msg_len); target = client_list_head; while ((NULL != target) && - (0 != memcmp (&target->id, - &trmsg->target, sizeof (GNUNET_HashCode)))) + (0 != + memcmp (&target->id, &trmsg->target, sizeof (struct GNUNET_HashCode)))) target = target->next; if (NULL == target) { @@ -394,11 +388,10 @@ handle_transmit_request (void *cls, GNUNET_free (rnmsg); return; } - if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key, - sizeof (struct - GNUNET_CRYPTO_AesSessionKey), - &target->public_key, - &rnmsg->encrypted_key)) + if (GNUNET_SYSERR == + GNUNET_CRYPTO_rsa_encrypt (&key, + sizeof (struct GNUNET_CRYPTO_AesSessionKey), + &target->public_key, &rnmsg->encrypted_key)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not encrypt the session key\n"); @@ -419,17 +412,14 @@ handle_transmit_request (void *cls, #endif while (NULL != pos) { - if ((0 == strcmp (room, pos->room)) && - (NULL != pos->client) && (pos->client != client)) + if ((0 == strcmp (room, pos->room)) && (NULL != pos->client) && + (pos->client != client)) { if (((!is_priv) || - (0 == memcmp (&trmsg->target, - &pos->id, - sizeof (GNUNET_HashCode)))) && - (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options)))) + (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, + GNUNET_SERVER_notification_context_unicast (nc, pos->client, &rnmsg->header, GNUNET_NO); } } @@ -442,8 +432,9 @@ handle_transmit_request (void *cls, if (is_anon) { room_len = strlen (room); - p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + - msg_len + room_len); + p2p_rnmsg = + GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + msg_len + + room_len); p2p_rnmsg->header.size = htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len + room_len); @@ -453,15 +444,14 @@ handle_transmit_request (void *cls, } else { - p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + - msg_len); + p2p_rnmsg = + GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + msg_len); p2p_rnmsg->header.size = htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len); if (is_priv) { memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len); - memcpy (&p2p_rnmsg->encrypted_key, - &rnmsg->encrypted_key, + memcpy (&p2p_rnmsg->encrypted_key, &rnmsg->encrypted_key, sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); } else @@ -531,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; @@ -540,19 +530,17 @@ send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_PEER_resolve (cp->pid, &pid); #if DEBUG_CHAT_SERVICE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending join notification to `%s'\n", GNUNET_i2s (&pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending join notification to `%s'\n", + GNUNET_i2s (&pid)); #endif - msg_size = sizeof (struct P2PJoinNotificationMessage) + - strlen (entry->room) + entry->meta_len; - if (NULL == GNUNET_CORE_notify_transmit_ready (core, - GNUNET_NO, - 1, - MAX_TRANSMIT_DELAY, - &pid, - msg_size, - &transmit_join_notification_to_peer, - entry)) + msg_size = + sizeof (struct P2PJoinNotificationMessage) + strlen (entry->room) + + entry->meta_len; + if (NULL == + GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, MAX_TRANSMIT_DELAY, + &pid, msg_size, + &transmit_join_notification_to_peer, + entry)) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to queue a join notification\n")); return GNUNET_YES; @@ -568,8 +556,7 @@ send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value) * @param message the actual message */ static void -handle_join_request (void *cls, - struct GNUNET_SERVER_Client *client, +handle_join_request (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct JoinRequestMessage *jrmsg; @@ -644,8 +631,7 @@ handle_join_request (void *cls, if (0 == strcmp (room_name, entry->room)) { if (NULL != entry->client) - GNUNET_SERVER_notification_context_unicast (nc, - entry->client, + GNUNET_SERVER_notification_context_unicast (nc, entry->client, &jnmsg->header, GNUNET_NO); if (entry->client != client) { @@ -659,8 +645,7 @@ handle_join_request (void *cls, entry_jnmsg->msg_options = entry->msg_options; entry_jnmsg->public_key = entry->public_key; memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len); - GNUNET_SERVER_notification_context_unicast (nc, - client, + GNUNET_SERVER_notification_context_unicast (nc, client, &entry_jnmsg->header, GNUNET_NO); GNUNET_free (entry_jnmsg); @@ -718,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; @@ -728,20 +713,17 @@ send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_PEER_resolve (cp->pid, &pid); #if DEBUG_CHAT_SERVICE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending confirmation receipt to `%s'\n", GNUNET_i2s (&pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending confirmation receipt to `%s'\n", + GNUNET_i2s (&pid)); #endif msg_size = sizeof (struct P2PConfirmationReceiptMessage); - my_receipt = GNUNET_memdup (receipt, - sizeof (struct P2PConfirmationReceiptMessage)); - if (NULL == GNUNET_CORE_notify_transmit_ready (core, - GNUNET_YES, - 1, - MAX_TRANSMIT_DELAY, - &pid, - msg_size, - &transmit_confirmation_receipt_to_peer, - my_receipt)) + my_receipt = + GNUNET_memdup (receipt, sizeof (struct P2PConfirmationReceiptMessage)); + if (NULL == + GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, + MAX_TRANSMIT_DELAY, &pid, msg_size, + &transmit_confirmation_receipt_to_peer, + my_receipt)) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to queue a confirmation receipt\n")); return GNUNET_YES; @@ -758,8 +740,7 @@ send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value) * @param message the actual message */ static void -handle_acknowledge_request (void *cls, - struct GNUNET_SERVER_Client *client, +handle_acknowledge_request (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct ConfirmationReceiptMessage *receipt; @@ -772,8 +753,8 @@ handle_acknowledge_request (void *cls, receipt = (const struct ConfirmationReceiptMessage *) message; author = client_list_head; while ((NULL != author) && - (0 != memcmp (&receipt->author, - &author->id, sizeof (GNUNET_HashCode)))) + (0 != + memcmp (&receipt->author, &author->id, sizeof (struct GNUNET_HashCode)))) author = author->next; if (NULL == author) { @@ -785,8 +766,8 @@ handle_acknowledge_request (void *cls, } target = client_list_head; while ((NULL != target) && - (0 != memcmp (&receipt->target, - &target->id, sizeof (GNUNET_HashCode)))) + (0 != + memcmp (&receipt->target, &target->id, sizeof (struct GNUNET_HashCode)))) target = target->next; if (NULL == target) { @@ -831,8 +812,8 @@ handle_acknowledge_request (void *cls, #endif if (GNUNET_OK != GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, - &receipt->purpose, - &receipt->signature, &target->public_key)) + &receipt->purpose, &receipt->signature, + &target->public_key)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid signature of the receipt\n"); @@ -899,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; @@ -909,13 +890,13 @@ send_leave_noficiation (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_PEER_resolve (cp->pid, &pid); #if DEBUG_CHAT_SERVICE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending leave notification to `%s'\n", GNUNET_i2s (&pid)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending leave notification to `%s'\n", + GNUNET_i2s (&pid)); #endif msg_size = sizeof (struct P2PLeaveNotificationMessage); - public_key = GNUNET_memdup (&entry->public_key, - sizeof (struct - GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); + public_key = + GNUNET_memdup (&entry->public_key, + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); if (NULL == GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, MAX_TRANSMIT_DELAY, &pid, msg_size, @@ -975,8 +956,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) { if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client)) { - GNUNET_SERVER_notification_context_unicast (nc, - entry->client, + GNUNET_SERVER_notification_context_unicast (nc, entry->client, &lnmsg.header, GNUNET_NO); } entry = entry->next; @@ -1000,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) */ @@ -1007,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; @@ -1019,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)) @@ -1044,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, @@ -1093,8 +1074,7 @@ handle_p2p_join_notification (void *cls, { if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client)) { - GNUNET_SERVER_notification_context_unicast (nc, - entry->client, + GNUNET_SERVER_notification_context_unicast (nc, entry->client, &jnmsg->header, GNUNET_NO); } entry = entry->next; @@ -1117,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) */ @@ -1124,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; @@ -1143,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; @@ -1173,8 +1154,7 @@ handle_p2p_leave_notification (void *cls, { if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client)) { - GNUNET_SERVER_notification_context_unicast (nc, - entry->client, + GNUNET_SERVER_notification_context_unicast (nc, entry->client, &lnmsg.header, GNUNET_NO); } entry = entry->next; @@ -1199,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) */ @@ -1206,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; @@ -1230,7 +1211,8 @@ handle_p2p_message_notification (void *cls, return GNUNET_SYSERR; } p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message; - msg_len = ntohs (p2p_rnmsg->header.size) - + msg_len = + ntohs (p2p_rnmsg->header.size) - sizeof (struct P2PReceiveNotificationMessage); is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); @@ -1263,8 +1245,8 @@ handle_p2p_message_notification (void *cls, { sender = client_list_head; while ((NULL != sender) && - (0 != memcmp (&sender->id, - &p2p_rnmsg->sender, sizeof (GNUNET_HashCode)))) + (0 != + memcmp (&sender->id, &p2p_rnmsg->sender, sizeof (struct GNUNET_HashCode)))) sender = sender->next; if (NULL == sender) { @@ -1297,18 +1279,17 @@ handle_p2p_message_notification (void *cls, "Sending message to local room members\n"); #endif rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); - rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + - msg_len); + rnmsg->header.size = + htons (sizeof (struct ReceiveNotificationMessage) + msg_len); rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); rnmsg->msg_options = p2p_rnmsg->msg_options; rnmsg->sequence_number = p2p_rnmsg->sequence_number; rnmsg->reserved = htonl (0); rnmsg->timestamp = p2p_rnmsg->timestamp; - is_priv = (0 != memcmp (&all_zeros, - &p2p_rnmsg->target, sizeof (GNUNET_HashCode))); + is_priv = + (0 != memcmp (&all_zeros, &p2p_rnmsg->target, sizeof (struct GNUNET_HashCode))); if (is_priv) - memcpy (&rnmsg->encrypted_key, - &p2p_rnmsg->encrypted_key, + memcpy (&rnmsg->encrypted_key, &p2p_rnmsg->encrypted_key, sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); rnmsg->sender = p2p_rnmsg->sender; memcpy (&rnmsg[1], text, msg_len); @@ -1318,13 +1299,11 @@ handle_p2p_message_notification (void *cls, if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client)) { if (((!is_priv) || - (0 == memcmp (&p2p_rnmsg->target, - &pos->id, - sizeof (GNUNET_HashCode)))) && + (0 == + 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, + GNUNET_SERVER_notification_context_unicast (nc, pos->client, &rnmsg->header, GNUNET_NO); } } @@ -1352,14 +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, +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; @@ -1373,14 +1353,11 @@ handle_p2p_sync_request (void *cls, entry = client_list_head; while (NULL != entry) { - msg_size = sizeof (struct P2PJoinNotificationMessage) + - strlen (entry->room) + entry->meta_len; - th = GNUNET_CORE_notify_transmit_ready (core, - GNUNET_NO, - 1, - MAX_TRANSMIT_DELAY, - other, - msg_size, + msg_size = + sizeof (struct P2PJoinNotificationMessage) + strlen (entry->room) + + entry->meta_len; + th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, + MAX_TRANSMIT_DELAY, other, msg_size, &transmit_join_notification_to_peer, entry); GNUNET_assert (NULL != th); @@ -1397,6 +1374,7 @@ handle_p2p_sync_request (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) */ @@ -1404,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; @@ -1417,8 +1395,8 @@ handle_p2p_confirmation_receipt (void *cls, p2p_crmsg = (const struct P2PConfirmationReceiptMessage *) message; target = client_list_head; while ((NULL != target) && - (0 != memcmp (&target->id, - &p2p_crmsg->target, sizeof (GNUNET_HashCode)))) + (0 != + memcmp (&target->id, &p2p_crmsg->target, sizeof (struct GNUNET_HashCode)))) target = target->next; if (NULL == target) { @@ -1441,8 +1419,8 @@ handle_p2p_confirmation_receipt (void *cls, target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number); author = client_list_head; while ((NULL != author) && - (0 != memcmp (&author->id, - &p2p_crmsg->author, sizeof (GNUNET_HashCode)))) + (0 != + memcmp (&author->id, &p2p_crmsg->author, sizeof (struct GNUNET_HashCode)))) author = author->next; if (NULL == author) { @@ -1488,8 +1466,8 @@ handle_p2p_confirmation_receipt (void *cls, crmsg->content = p2p_crmsg->content; if (GNUNET_OK != GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, - &crmsg->purpose, - &crmsg->signature, &target->public_key)) + &crmsg->purpose, &crmsg->signature, + &target->public_key)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid signature of the receipt\n"); @@ -1501,8 +1479,7 @@ handle_p2p_confirmation_receipt (void *cls, "The author of the original message is a local client." " Sending receipt to the client\n"); #endif - GNUNET_SERVER_notification_context_unicast (nc, - author->client, + GNUNET_SERVER_notification_context_unicast (nc, author->client, &crmsg->header, GNUNET_NO); GNUNET_free (crmsg); } @@ -1543,24 +1520,22 @@ 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) +peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, + 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)); - th = GNUNET_CORE_notify_transmit_ready (core, - GNUNET_YES, - 1, - MAX_TRANSMIT_DELAY, - peer, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer connected: %s\n", + GNUNET_i2s (peer)); + th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, + MAX_TRANSMIT_DELAY, peer, sizeof (struct GNUNET_MessageHeader), &transmit_sync_request_to_peer, NULL); GNUNET_assert (NULL != th); @@ -1574,8 +1549,7 @@ peer_connect_handler (void *cls, cp->pid = GNUNET_PEER_intern (peer); GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (connected_peers, - &peer->hashPubKey, - cp, + &peer->hashPubKey, cp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); } @@ -1589,7 +1563,7 @@ peer_connect_handler (void *cls, * @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 = @@ -1617,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); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer disconnected: %s\n", + GNUNET_i2s (peer)); + clean_peer (NULL, (const struct GNUNET_HashCode *) peer, NULL); } @@ -1674,16 +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) +core_init (void *cls, struct GNUNET_CORE_Handle *server, + const struct GNUNET_PeerIdentity *my_identity) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Core initialized\n"); - me = my_identity; + me = *my_identity; } @@ -1695,8 +1666,7 @@ core_init (void *cls, * @param c configuration to use */ static void -run (void *cls, - struct GNUNET_SERVER_Handle *server, +run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { @@ -1736,19 +1706,15 @@ run (void *cls, 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, - &peer_connect_handler, - &peer_disconnect_handler, - NULL, - NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers); + core = + GNUNET_CORE_connect (cfg, NULL, &core_init, + &peer_connect_handler, &peer_disconnect_handler, + 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); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, + NULL); } @@ -1763,10 +1729,8 @@ int main (int argc, char *const *argv) { return (GNUNET_OK == - GNUNET_SERVICE_run (argc, - argv, - "chat", - GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; + GNUNET_SERVICE_run (argc, argv, "chat", GNUNET_SERVICE_OPTION_NONE, + &run, NULL)) ? 0 : 1; } /* end of gnunet-service-chat.c */