summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-messenger.c14
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger.c4
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger_member.c10
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger_message_store.c10
-rwxr-xr-x[-rw-r--r--]src/messenger/gnunet-service-messenger_operation_store.c4
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_contact_store.c9
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_message.c2
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_room.c16
-rwxr-xr-x[-rw-r--r--]src/messenger/messenger_api_room.h6
9 files changed, 47 insertions, 28 deletions
diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c
index 737bb83c8..094ae398d 100644..100755
--- a/src/messenger/gnunet-messenger.c
+++ b/src/messenger/gnunet-messenger.c
@@ -229,18 +229,12 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle)
if (room_key)
GNUNET_CRYPTO_hash (room_key, strlen (room_key), &key);
+ struct GNUNET_PeerIdentity door_peer;
struct GNUNET_PeerIdentity *door = NULL;
- if (door_id)
- {
- door = GNUNET_new(struct GNUNET_PeerIdentity);
-
- if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (door_id, strlen (door_id), &(door->public_key)))
- {
- GNUNET_free(door);
- door = NULL;
- }
- }
+ if ((door_id) &&
+ (GNUNET_OK == GNUNET_CRYPTO_eddsa_public_key_from_string (door_id, strlen (door_id), &(door_peer.public_key))))
+ door = &door_peer;
const char *name = GNUNET_MESSENGER_get_name (handle);
diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c
index 187b65ed5..76fb31d95 100644..100755
--- a/src/messenger/gnunet-service-messenger.c
+++ b/src/messenger/gnunet-service-messenger.c
@@ -191,7 +191,7 @@ check_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg)
const uint16_t length = full_length - sizeof(*msg);
const char *buffer = ((const char*) msg) + sizeof(*msg);
- uint16_t key_length = 0;
+ ssize_t key_length = 0;
if (!(flags & GNUNET_MESSENGER_FLAG_PRIVATE))
goto check_for_message;
@@ -231,7 +231,7 @@ handle_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg)
const char *buffer = ((const char*) msg) + sizeof(*msg);
const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
- uint16_t key_length = 0;
+ ssize_t key_length = 0;
struct GNUNET_IDENTITY_PublicKey public_key;
diff --git a/src/messenger/gnunet-service-messenger_member.c b/src/messenger/gnunet-service-messenger_member.c
index 6e39cec13..7f00e8438 100644..100755
--- a/src/messenger/gnunet-service-messenger_member.c
+++ b/src/messenger/gnunet-service-messenger_member.c
@@ -335,7 +335,11 @@ add_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSEN
struct GNUNET_HashCode hash;
GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
- GNUNET_CONTAINER_multihashmap_put(member->sessions, &hash, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
+ member->sessions, &hash, session,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding a member session failed: %s\n",
+ GNUNET_h2s(&hash));
}
void
@@ -348,7 +352,9 @@ remove_member_session (struct GNUNET_MESSENGER_Member *member, struct GNUNET_MES
struct GNUNET_HashCode hash;
GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash);
- GNUNET_CONTAINER_multihashmap_remove(member->sessions, &hash, session);
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(member->sessions, &hash, session))
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a member session failed: %s\n",
+ GNUNET_h2s(&hash));
}
struct GNUNET_MESSENGER_ClosureIterateSessions {
diff --git a/src/messenger/gnunet-service-messenger_message_store.c b/src/messenger/gnunet-service-messenger_message_store.c
index 1f3d262ac..b143c6c98 100644..100755
--- a/src/messenger/gnunet-service-messenger_message_store.c
+++ b/src/messenger/gnunet-service-messenger_message_store.c
@@ -158,6 +158,8 @@ load_message_store_links (struct GNUNET_MESSENGER_MessageStore *store, const cha
struct GNUNET_MESSENGER_MessageLinkStorage storage;
struct GNUNET_MESSENGER_MessageLink *link = NULL;
+ memset(&storage, 0, sizeof(storage));
+
do
{
if ((sizeof(storage.hash) != GNUNET_DISK_file_read (entries, &(storage.hash), sizeof(storage.hash))) ||
@@ -311,6 +313,8 @@ save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *dir
save.store = store;
save.storage = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, permission);
+ GNUNET_free(filename);
+
if (!save.storage)
goto save_entries;
@@ -324,7 +328,6 @@ close_links:
GNUNET_DISK_file_close (save.storage);
save_entries:
- GNUNET_free(filename);
GNUNET_asprintf (&filename, "%s%s", directory, "entries.store");
save.store = store;
@@ -417,7 +420,10 @@ get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNU
if ((GNUNET_YES != decoding) || (GNUNET_CRYPTO_hash_cmp (hash, &check) != 0))
{
- GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, entry);
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, entry))
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Corrupted entry could not be removed from store: %s\n",
+ GNUNET_h2s(hash));
+
store->rewrite_entries = GNUNET_YES;
goto free_message;
diff --git a/src/messenger/gnunet-service-messenger_operation_store.c b/src/messenger/gnunet-service-messenger_operation_store.c
index 05985ef84..a32fbad2c 100644..100755
--- a/src/messenger/gnunet-service-messenger_operation_store.c
+++ b/src/messenger/gnunet-service-messenger_operation_store.c
@@ -184,7 +184,9 @@ cancel_store_operation (struct GNUNET_MESSENGER_OperationStore *store,
stop_operation(op);
- GNUNET_CONTAINER_multihashmap_remove(store->operations, hash, op);
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(store->operations, hash, op))
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Canceled operation could not be removed: %s\n",
+ GNUNET_h2s(hash));
destroy_operation(op);
}
diff --git a/src/messenger/messenger_api_contact_store.c b/src/messenger/messenger_api_contact_store.c
index 5238b2c58..6a517c2e0 100644..100755
--- a/src/messenger/messenger_api_contact_store.c
+++ b/src/messenger/messenger_api_contact_store.c
@@ -155,8 +155,10 @@ update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET
store, next_context, &hash
);
- GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating a contact failed: %s\n",
+ GNUNET_h2s(&hash));
}
}
@@ -176,7 +178,8 @@ remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET
);
if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact))
- return;
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a contact failed: %s\n",
+ GNUNET_h2s(&hash));
destroy_contact (contact);
}
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c
index d88859186..0d885f9ee 100644..100755
--- a/src/messenger/messenger_api_message.c
+++ b/src/messenger/messenger_api_message.c
@@ -590,7 +590,7 @@ int
decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer,
int include_signature, uint16_t *padding)
{
- GNUNET_assert((message) && (buffer));
+ GNUNET_assert((message) && (buffer) && (length >= sizeof(message->header)));
uint16_t offset = 0;
diff --git a/src/messenger/messenger_api_room.c b/src/messenger/messenger_api_room.c
index df141ca12..5b7edee60 100644..100755
--- a/src/messenger/messenger_api_room.c
+++ b/src/messenger/messenger_api_room.c
@@ -106,7 +106,7 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_H
return (entry? entry->sender : NULL);
}
-static void
+static struct GNUNET_MESSENGER_Contact*
handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender,
const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
{
@@ -124,6 +124,8 @@ handle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER
(GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(room->members, &(message->header.sender_id), sender,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)))
increase_contact_rc(sender);
+
+ return sender;
}
static void
@@ -140,7 +142,7 @@ handle_leave_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGE
struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle);
if (GNUNET_YES == decrease_contact_rc(sender))
- remove_store_contact(store, sender, &context);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A contact does not share any room with you anymore!\n");
}
static void
@@ -216,17 +218,17 @@ handle_delete_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENG
}
}
-void
+struct GNUNET_MESSENGER_Contact*
handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender,
const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
{
if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash))
- return;
+ return sender;
switch (message->header.kind)
{
case GNUNET_MESSENGER_KIND_JOIN:
- handle_join_message (room, sender, message, hash);
+ sender = handle_join_message (room, sender, message, hash);
break;
case GNUNET_MESSENGER_KIND_LEAVE:
handle_leave_message (room, sender, message, hash);
@@ -253,7 +255,7 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER
struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_new(struct GNUNET_MESSENGER_RoomMessageEntry);
if (!entry)
- return;
+ return sender;
entry->sender = sender;
entry->message = copy_message (message);
@@ -264,6 +266,8 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER
destroy_message (entry->message);
GNUNET_free(entry);
}
+
+ return sender;
}
struct GNUNET_MESSENGER_MemberCall
diff --git a/src/messenger/messenger_api_room.h b/src/messenger/messenger_api_room.h
index 9455fd43b..eb41cf740 100644..100755
--- a/src/messenger/messenger_api_room.h
+++ b/src/messenger/messenger_api_room.h
@@ -100,12 +100,16 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_H
* Handles a <i>message</i> with a given <i>hash</i> in a <i>room</i> for the client API to update
* members and its information. The function also stores the message in map locally for access afterwards.
*
+ * The contact of the message's sender could be updated or even created. It may not be freed or destroyed though!
+ * (The contact may still be in use for old messages...)
+ *
* @param[in/out] room Room
* @param[in/out] sender Contact of sender
* @param[in] message Message
* @param[in] hash Hash of message
+ * @return Contact of sender
*/
-void
+struct GNUNET_MESSENGER_Contact*
handle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender,
const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);