summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-01-24 22:23:39 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-01-24 22:23:39 +0100
commitaca1785bd9501dc163f7dcc82034119bfbe3cb81 (patch)
tree9003e26547c2e8f732e6c0e5b30b0f67611a8225
parent7243f100ae30482c771d3ac008157f9164fc32ac (diff)
-changed info messages and added protocol version exchangejacki/messenger
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/include/gnunet_messenger_service.h12
-rw-r--r--src/messenger/gnunet-service-messenger_member_session.c34
-rw-r--r--src/messenger/gnunet-service-messenger_member_session.h12
-rw-r--r--src/messenger/gnunet-service-messenger_message_handle.c5
-rw-r--r--src/messenger/gnunet-service-messenger_message_kind.c12
-rw-r--r--src/messenger/gnunet-service-messenger_message_kind.h2
-rw-r--r--src/messenger/gnunet-service-messenger_message_recv.c114
-rw-r--r--src/messenger/gnunet-service-messenger_message_recv.h13
-rw-r--r--src/messenger/gnunet-service-messenger_message_send.c3
-rw-r--r--src/messenger/gnunet-service-messenger_message_store.c8
-rw-r--r--src/messenger/gnunet-service-messenger_room.c55
-rw-r--r--src/messenger/gnunet-service-messenger_room.h11
-rw-r--r--src/messenger/gnunet-service-messenger_tunnel.c60
-rw-r--r--src/messenger/gnunet-service-messenger_tunnel.h42
-rw-r--r--src/messenger/messenger_api_message.c6
15 files changed, 222 insertions, 167 deletions
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h
index 29b3aed64..6af739873 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -48,6 +48,14 @@ extern "C" {
#include "gnunet_scheduler_lib.h"
#include "gnunet_time_lib.h"
+/**
+ * Version number of GNUnet Messenger API.
+ */
+#define GNUNET_MESSENGER_VERSION 0x00000001
+
+/**
+ * Identifier of GNUnet MESSENGER Service.
+ */
#define GNUNET_MESSENGER_SERVICE_NAME "messenger"
/**
@@ -204,9 +212,9 @@ struct GNUNET_MESSENGER_MessageInfo
struct GNUNET_IDENTITY_PublicKey host_key;
/**
- * The new unique id for the receiver in a room.
+ * The version of GNUnet Messenger API.
*/
- struct GNUNET_ShortHashCode unique_id;
+ uint32_t messenger_version;
};
/**
diff --git a/src/messenger/gnunet-service-messenger_member_session.c b/src/messenger/gnunet-service-messenger_member_session.c
index 119c112fb..0dea60cb3 100644
--- a/src/messenger/gnunet-service-messenger_member_session.c
+++ b/src/messenger/gnunet-service-messenger_member_session.c
@@ -90,11 +90,7 @@ switch_member_session (struct GNUNET_MESSENGER_MemberSession *session,
return NULL;
GNUNET_assert((GNUNET_MESSENGER_KIND_ID == message->header.kind) ||
- (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
- (GNUNET_MESSENGER_KIND_JOIN == message->header.kind));
-
- if (!session->messages.head)
- return session;
+ (GNUNET_MESSENGER_KIND_KEY == message->header.kind));
struct GNUNET_MESSENGER_MemberSession *next = GNUNET_new(struct GNUNET_MESSENGER_MemberSession);
@@ -114,13 +110,12 @@ switch_member_session (struct GNUNET_MESSENGER_MemberSession *session,
&(next->context)
);
- if (GNUNET_MESSENGER_KIND_JOIN != message->header.kind)
- update_store_contact(
- get_member_contact_store(next->member->store),
- get_member_session_contact(session),
- get_member_session_context(next),
- get_member_session_public_key(next)
- );
+ update_store_contact(
+ get_member_contact_store(next->member->store),
+ get_member_session_contact(session),
+ get_member_session_context(next),
+ get_member_session_public_key(next)
+ );
next->contact = get_member_session_contact(session);
@@ -139,11 +134,7 @@ switch_member_session (struct GNUNET_MESSENGER_MemberSession *session,
GNUNET_CONTAINER_multihashmap_iterate(session->history, iterate_copy_history, next);
init_list_messages(&(next->messages));
-
- if (GNUNET_MESSENGER_KIND_JOIN != message->header.kind)
- copy_list_messages(&(next->messages), &(session->messages));
- else
- add_to_list_messages(&(next->messages), hash);
+ copy_list_messages(&(next->messages), &(session->messages));
session->next = next;
next->next = NULL;
@@ -172,6 +163,15 @@ destroy_member_session(struct GNUNET_MESSENGER_MemberSession* session)
GNUNET_free(session);
}
+int
+is_member_session_active (const struct GNUNET_MESSENGER_MemberSession* session)
+{
+ if ((!session->messages.head) || (session->next))
+ return GNUNET_NO;
+ else
+ return GNUNET_YES;
+}
+
const struct GNUNET_HashCode*
get_member_session_key (const struct GNUNET_MESSENGER_MemberSession* session)
{
diff --git a/src/messenger/gnunet-service-messenger_member_session.h b/src/messenger/gnunet-service-messenger_member_session.h
index 5e5099339..acddc067c 100644
--- a/src/messenger/gnunet-service-messenger_member_session.h
+++ b/src/messenger/gnunet-service-messenger_member_session.h
@@ -70,9 +70,6 @@ create_member_session (struct GNUNET_MESSENGER_Member *member,
* <i>message</i> to switch session. The new session will be linked to the old
* one.
*
- * If the old session was fully empty (or unused) it will be returned instead
- * of a new one.
- *
* @param[in/out] session Old member session
* @param[in] message Message
* @param[in] hash Hash of message
@@ -92,6 +89,15 @@ void
destroy_member_session(struct GNUNET_MESSENGER_MemberSession* session);
/**
+ * Returns if the given member <i>session</i> is active and can be used.
+ *
+ * @param[in] session Member session
+ * @return #GNUNET_YES or #GNUNET_NO
+ */
+int
+is_member_session_active (const struct GNUNET_MESSENGER_MemberSession* session);
+
+/**
* Returns the key of the room a given member <i>session</i> belongs to.
*
* @param[in] session Member session
diff --git a/src/messenger/gnunet-service-messenger_message_handle.c b/src/messenger/gnunet-service-messenger_message_handle.c
index 31edd88aa..26e5e547b 100644
--- a/src/messenger/gnunet-service-messenger_message_handle.c
+++ b/src/messenger/gnunet-service-messenger_message_handle.c
@@ -46,7 +46,8 @@ void
handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session,
const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
{
- handle_session_switch (session, message, hash); // TODO: should not switch if session is still open!
+ clear_list_messages(&(session->messages));
+ add_to_list_messages(&(session->messages), hash);
GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member (%s) joins room (%s).\n",
GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s(get_room_key(room)));
@@ -56,7 +57,7 @@ void
handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session,
const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
{
- // TODO: close session!
+ clear_list_messages(&(session->messages));
GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member (%s) leaves room (%s).\n",
GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s(get_room_key(room)));
diff --git a/src/messenger/gnunet-service-messenger_message_kind.c b/src/messenger/gnunet-service-messenger_message_kind.c
index ebf58858f..c33ccf2ad 100644
--- a/src/messenger/gnunet-service-messenger_message_kind.c
+++ b/src/messenger/gnunet-service-messenger_message_kind.c
@@ -27,7 +27,7 @@
#include "gnunet-service-messenger_util.h"
struct GNUNET_MESSENGER_Message*
-create_message_info (const struct GNUNET_MESSENGER_Ego *ego, const struct GNUNET_CONTAINER_MultiShortmap *members)
+create_message_info (const struct GNUNET_MESSENGER_Ego *ego)
{
if (!ego)
return NULL;
@@ -39,13 +39,9 @@ create_message_info (const struct GNUNET_MESSENGER_Ego *ego, const struct GNUNET
GNUNET_memcpy(&(message->body.info.host_key), &(ego->pub), sizeof(ego->pub));
- if (GNUNET_YES == generate_free_member_id (&(message->body.info.unique_id), members))
- return message;
- else
- {
- destroy_message (message);
- return NULL;
- }
+ message->body.info.messenger_version = GNUNET_MESSENGER_VERSION;
+
+ return message;
}
struct GNUNET_MESSENGER_Message*
diff --git a/src/messenger/gnunet-service-messenger_message_kind.h b/src/messenger/gnunet-service-messenger_message_kind.h
index a6522258f..c098868c0 100644
--- a/src/messenger/gnunet-service-messenger_message_kind.h
+++ b/src/messenger/gnunet-service-messenger_message_kind.h
@@ -45,7 +45,7 @@
* @return New message
*/
struct GNUNET_MESSENGER_Message*
-create_message_info (const struct GNUNET_MESSENGER_Ego *ego, const struct GNUNET_CONTAINER_MultiShortmap *members);
+create_message_info (const struct GNUNET_MESSENGER_Ego *ego);
/**
* Creates and allocates a new join message containing the clients EGO public key.
diff --git a/src/messenger/gnunet-service-messenger_message_recv.c b/src/messenger/gnunet-service-messenger_message_recv.c
index b49ac3f76..3da97fa48 100644
--- a/src/messenger/gnunet-service-messenger_message_recv.c
+++ b/src/messenger/gnunet-service-messenger_message_recv.c
@@ -25,110 +25,54 @@
#include "gnunet-service-messenger_message_recv.h"
-int
-recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
- const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
+static int
+iterate_forward_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key,
+ struct GNUNET_MESSENGER_MemberSession *session)
{
- /*struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
-
- int conflict = get_store_member(member_store, &(message->body.info.unique_id))? GNUNET_YES : GNUNET_NO;
+ struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
+ struct GNUNET_MESSENGER_SrvRoom *room = tunnel->room;
- if (GNUNET_NO == conflict)
- {
- struct GNUNET_MESSENGER_Message *sync_message = create_message_id (&(message->body.info.unique_id));
- struct GNUNET_HashCode sync_hash;
+ struct GNUNET_MESSENGER_ListMessage *element;
- send_room_message_ext (room, room->host, sync_message, &sync_hash, tunnel);
- destroy_message (sync_message);
+ for (element = session->messages.head; element; element = element->next)
+ forward_tunnel_message(tunnel, get_room_message(room, NULL, &(element->hash), GNUNET_NO), &(element->hash));
- // update_store_member(member_store, get_room_host_id (room), &(message->body.info.unique_id));
-
- change_room_host_id (room, &(message->body.info.unique_id));
- }
+ return GNUNET_YES;
+}
- struct GNUNET_ShortHashCode original_id;
+int
+recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
+ const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
+{
+ const uint32_t version = get_tunnel_messenger_version(tunnel);
- if (GNUNET_YES == conflict)
+ if (GNUNET_OK != update_tunnel_messenger_version(tunnel, message->body.info.messenger_version))
{
- GNUNET_memcpy(&original_id, get_room_host_id (room), sizeof(struct GNUNET_ShortHashCode));
-
- change_room_host_id (room, &(message->body.info.unique_id));
+ disconnect_tunnel(tunnel);
+ return GNUNET_NO;
}
+ if ((version != get_tunnel_messenger_version(tunnel)) && (room->host))
{
- struct GNUNET_MESSENGER_Message *join_message = create_message_join (room->host->ego);
- struct GNUNET_HashCode join_hash;
+ const struct GNUNET_MESSENGER_Ego *ego = get_handle_ego(room->host);
- send_tunnel_message (tunnel, room->host, join_message, &join_hash);
- destroy_message (join_message);
+ send_tunnel_message (tunnel, room->host, create_message_info(ego));
}
- if ((GNUNET_YES == conflict) && (0 != GNUNET_memcmp(&original_id, get_room_host_id (room))))
- {
- struct GNUNET_MESSENGER_Message *sync_message = create_message_id (&original_id);
- struct GNUNET_HashCode sync_hash;
-
- send_tunnel_message (tunnel, room->host, sync_message, &sync_hash);
- destroy_message (sync_message);
- }*/
-
- return GNUNET_NO;
-}
-
-/*struct GNUNET_MESSENGER_MemberSpread
-{
- struct GNUNET_MESSENGER_SrvRoom *room;
- struct GNUNET_MESSENGER_SrvTunnel *tunnel;
-};
-
-static int
-iterate_spread_members (void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key,
- struct GNUNET_MESSENGER_MemberSession *session)
-{
- struct GNUNET_MESSENGER_MemberSpread *spread = cls;
-
- struct GNUNET_MESSENGER_ListMessage *element = session->messages.head;
+ struct GNUNET_PeerIdentity peer;
+ get_tunnel_peer_identity(tunnel, &peer);
- while (element)
+ if (GNUNET_YES != contains_list_tunnels(&(room->basement), &peer))
{
- const struct GNUNET_MESSENGER_Message *message = get_room_message (spread->room, spread->room->host,
- &(element->hash), GNUNET_NO);
-
- if (message)
- forward_tunnel_message (spread->tunnel, message, &(element->hash));
+ struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
- element = element->next;
+ iterate_store_members(member_store, iterate_forward_members, tunnel);
}
- return GNUNET_YES;
-}*/
+ if (version != get_tunnel_messenger_version(tunnel))
+ check_room_peer_status(room, tunnel);
-int
-recv_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
- const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
-{
- /*const struct GNUNET_MESSENGER_Message *info_msg = get_room_message (room, room->host, &(message->header.previous),
- GNUNET_NO);
-
- if ((info_msg) && (GNUNET_MESSENGER_KIND_INFO == info_msg->header.kind) &&
- (0 == GNUNET_memcmp(&(message->header.sender_id), &(info_msg->body.info.unique_id))))
- {
- struct GNUNET_MESSENGER_MemberSpread spread;
-
- spread.room = room;
- spread.tunnel = tunnel;
-
- if (spread.tunnel)
- {
- struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
-
- iterate_store_members(member_store, iterate_spread_members, &spread);
- }
- }*/
-
- // TODO: seems to work without it.. lol?
-
- return GNUNET_YES;
+ return GNUNET_NO;
}
int
diff --git a/src/messenger/gnunet-service-messenger_message_recv.h b/src/messenger/gnunet-service-messenger_message_recv.h
index 873094d60..9cb36c466 100644
--- a/src/messenger/gnunet-service-messenger_message_recv.h
+++ b/src/messenger/gnunet-service-messenger_message_recv.h
@@ -50,19 +50,6 @@ recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE
const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);
/**
- * Handles a received join message to forward all member information to the new member if the message was
- * the direct reaction to a previous info message from this peer.
- *
- * @param[in/out] room Room of the message
- * @param[in/out] tunnel Receiving connection
- * @param[in] message JOIN-Message
- * @param[in] hash Hash of the message
- * @return #GNUNET_YES to forward the message
- */
-int
-recv_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
- const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);
-/**
* Handles a received peer message to link it to its origin tunnel if the peer identity matches.
* (the peer message and the member id can potentially be linked to the tunnel)
*
diff --git a/src/messenger/gnunet-service-messenger_message_send.c b/src/messenger/gnunet-service-messenger_message_send.c
index 9876180ec..025df93ab 100644
--- a/src/messenger/gnunet-service-messenger_message_send.c
+++ b/src/messenger/gnunet-service-messenger_message_send.c
@@ -41,8 +41,7 @@ send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGE
if (!session)
add_member_session(member, create_member_session(member, &(message->body.join.key)));
- if (room->peer_message)
- send_room_message (room, handle, create_message_peer (room->service));
+ check_room_peer_status(room, NULL);
}
void
diff --git a/src/messenger/gnunet-service-messenger_message_store.c b/src/messenger/gnunet-service-messenger_message_store.c
index 4c90c4cb2..1602ed84d 100644
--- a/src/messenger/gnunet-service-messenger_message_store.c
+++ b/src/messenger/gnunet-service-messenger_message_store.c
@@ -151,7 +151,7 @@ free_filename:
GNUNET_free(filename);
}
-struct GNUNET_MESSENGER_MessageSave
+struct GNUNET_MESSENGER_ClosureMessageSave
{
struct GNUNET_MESSENGER_MessageStore *store;
@@ -161,7 +161,7 @@ struct GNUNET_MESSENGER_MessageSave
static int
iterate_save_entries (void *cls, const struct GNUNET_HashCode *key, void *value)
{
- struct GNUNET_MESSENGER_MessageSave *save = cls;
+ struct GNUNET_MESSENGER_ClosureMessageSave *save = cls;
struct GNUNET_MESSENGER_MessageEntry *entry = value;
struct GNUNET_MESSENGER_MessageEntryStorage storage;
@@ -179,7 +179,7 @@ iterate_save_entries (void *cls, const struct GNUNET_HashCode *key, void *value)
static int
iterate_save_messages (void *cls, const struct GNUNET_HashCode *key, void *value)
{
- struct GNUNET_MESSENGER_MessageSave *save = cls;
+ struct GNUNET_MESSENGER_ClosureMessageSave *save = cls;
if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (save->store->entries, key))
return GNUNET_YES;
@@ -212,7 +212,7 @@ save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *dir
{
GNUNET_assert((store) && (directory));
- struct GNUNET_MESSENGER_MessageSave save;
+ struct GNUNET_MESSENGER_ClosureMessageSave save;
enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
diff --git a/src/messenger/gnunet-service-messenger_room.c b/src/messenger/gnunet-service-messenger_room.c
index a135b6dba..01260d8a2 100644
--- a/src/messenger/gnunet-service-messenger_room.c
+++ b/src/messenger/gnunet-service-messenger_room.c
@@ -198,19 +198,7 @@ send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_S
if (!is_tunnel_connected (tunnel))
return GNUNET_NO;
- struct GNUNET_MESSENGER_Message *message = create_message_info (
- get_handle_ego (handle), room->member_store.members
- );
-
- if (!message)
- return GNUNET_NO;
-
- struct GNUNET_HashCode hash;
-
- send_tunnel_message (tunnel, handle, message, &hash);
- destroy_message (message);
-
- return GNUNET_YES;
+ return send_tunnel_message (tunnel, handle, create_message_info (get_handle_ego (handle)));
}
static void*
@@ -570,6 +558,11 @@ void
forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel,
struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
{
+ GNUNET_assert((room) && (tunnel));
+
+ if (!message)
+ return;
+
struct GNUNET_MESSENGER_ClosureSendRoom closure;
struct GNUNET_HashCode message_hash;
@@ -586,6 +579,42 @@ forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSE
}
void
+check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
+{
+ if (!room->peer_message)
+ return;
+
+ const struct GNUNET_MESSENGER_Message *message = get_room_message(room, NULL, room->peer_message, GNUNET_NO);
+
+ if (!message)
+ {
+ GNUNET_free(room->peer_message);
+ room->peer_message = NULL;
+ return;
+ }
+
+ struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
+ struct GNUNET_MESSENGER_Member *member = get_store_member(member_store, &(message->header.sender_id));
+
+ if (!member)
+ goto resend_peer_message;
+
+ struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, room->peer_message);
+
+ if (GNUNET_YES != is_member_session_active(session))
+ goto resend_peer_message;
+
+ if (tunnel)
+ forward_tunnel_message(tunnel, message, room->peer_message);
+
+ return;
+
+resend_peer_message:
+ if (room->host)
+ send_room_message (room, room->host, create_message_peer (room->service));
+}
+
+void
merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
{
GNUNET_assert(room);
diff --git a/src/messenger/gnunet-service-messenger_room.h b/src/messenger/gnunet-service-messenger_room.h
index fb477c6d5..eab41ed1f 100644
--- a/src/messenger/gnunet-service-messenger_room.h
+++ b/src/messenger/gnunet-service-messenger_room.h
@@ -209,6 +209,17 @@ forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSE
struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash);
/**
+ * Checks the current state of opening a given <i>room</i> from this peer and re-publishes it
+ * if necessary to a selected <i>tunnel</i> or to all connected tunnels if necessary or if the
+ * selected tunnel is NULL.
+ *
+ * @param[in/out] room Room
+ * @param[in/out] tunnel Tunnel
+ */
+void
+check_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel);
+
+/**
* Reduces all current forks inside of the message history of a <i>room</i> to one remaining last message
* by merging them down. All merge messages will be sent from a given <i>handle</i>.
*
diff --git a/src/messenger/gnunet-service-messenger_tunnel.c b/src/messenger/gnunet-service-messenger_tunnel.c
index eede2ccb3..3c7370a99 100644
--- a/src/messenger/gnunet-service-messenger_tunnel.c
+++ b/src/messenger/gnunet-service-messenger_tunnel.c
@@ -42,6 +42,8 @@ create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerId
tunnel->peer = GNUNET_PEER_intern (door);
+ tunnel->messenger_version = 0;
+
tunnel->peer_message = NULL;
tunnel->last_message = NULL;
@@ -175,9 +177,6 @@ handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header)
case GNUNET_MESSENGER_KIND_INFO:
forward_message = recv_message_info (tunnel->room, tunnel, &message, &hash);
break;
- case GNUNET_MESSENGER_KIND_JOIN:
- forward_message = recv_message_join (tunnel->room, tunnel, &message, &hash);
- break;
case GNUNET_MESSENGER_KIND_PEER:
forward_message = recv_message_peer (tunnel->room, tunnel, &message, &hash);
break;
@@ -275,25 +274,36 @@ send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_M
GNUNET_MQ_send (mq, env);
}
-void
-send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message,
- struct GNUNET_HashCode *hash)
+int
+send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message)
{
- GNUNET_assert((tunnel) && (handle) && (message) && (hash));
+ GNUNET_assert((tunnel) && (handle));
+ if (!message)
+ return GNUNET_NO;
+
+ struct GNUNET_HashCode hash;
struct GNUNET_MQ_Envelope *env = pack_room_message (
tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle,
- message, hash, GNUNET_MESSENGER_PACK_MODE_ENVELOPE
+ message, &hash, GNUNET_MESSENGER_PACK_MODE_ENVELOPE
);
- if (env)
- send_tunnel_envelope (tunnel, env, hash);
+ destroy_message(message);
+
+ if (!env)
+ return GNUNET_NO;
+
+ send_tunnel_envelope (tunnel, env, &hash);
+ return GNUNET_YES;
}
void
forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message,
const struct GNUNET_HashCode *hash)
{
+ if (!message)
+ return;
+
GNUNET_assert((tunnel) && (message) && (hash));
struct GNUNET_MESSENGER_Message *copy = copy_message(message);
@@ -312,3 +322,33 @@ get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
return tunnel->peer_message;
}
+
+void
+get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer)
+{
+ GNUNET_assert(tunnel);
+
+ GNUNET_PEER_resolve(tunnel->peer, peer);
+}
+
+uint32_t
+get_tunnel_messenger_version (const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
+{
+ GNUNET_assert(tunnel);
+
+ return tunnel->messenger_version;
+}
+
+int
+update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, uint32_t version)
+{
+ GNUNET_assert(tunnel);
+
+ if (version != GNUNET_MESSENGER_VERSION)
+ return GNUNET_SYSERR;
+
+ if (version > tunnel->messenger_version)
+ tunnel->messenger_version = version;
+
+ return GNUNET_OK;
+}
diff --git a/src/messenger/gnunet-service-messenger_tunnel.h b/src/messenger/gnunet-service-messenger_tunnel.h
index b942ab64a..d4f81f68b 100644
--- a/src/messenger/gnunet-service-messenger_tunnel.h
+++ b/src/messenger/gnunet-service-messenger_tunnel.h
@@ -40,6 +40,8 @@ struct GNUNET_MESSENGER_SrvTunnel
GNUNET_PEER_Id peer;
+ uint32_t messenger_version;
+
struct GNUNET_HashCode *peer_message;
struct GNUNET_HashCode *last_message;
};
@@ -121,11 +123,10 @@ send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_M
* @param[in/out] tunnel Tunnel
* @param[in/out] handle Handle
* @param[in/out] message Message
- * @param[out] hash Hash of message
+ * @return #GNUNET_YES on success, GNUNET_NO otherwise
*/
-void
-send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message,
- struct GNUNET_HashCode *hash);
+int
+send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message);
/**
* Forwards a given <i>message</i> with a known <i>hash</i> through a <i>tunnel</i>.
@@ -149,4 +150,37 @@ forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct
const struct GNUNET_HashCode*
get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel);
+/**
+ * Writes the peer identity of the peer connected via <i>tunnel</i> to this peer into
+ * the <i>peer</i> parameter.
+ *
+ * @param[in] tunnel Tunnel
+ * @param[out] peer Peer identity
+ */
+void
+get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer);
+
+/**
+ * Returns the current messenger version the peer connected via a given <i>tunnel</i>
+ * has reported to be using if it was compatible during updating.
+ *
+ * @see update_tunnel_messenger_version
+ *
+ * @param[in] tunnel Tunnel
+ * @return Version of messenger
+ */
+uint32_t
+get_tunnel_messenger_version (const struct GNUNET_MESSENGER_SrvTunnel *tunnel);
+
+/**
+ * Updates the messenger version of the <i>tunnel</i> to a given <i>version</i> if
+ * it is compatible to the running peer of the service. Depending on success it
+ * returns #GNUNET_OK or #GNUNET_SYSERR on failure.
+ *
+ * @param[in/out] tunnel Tunnel
+ * @param[in] version Version of messenger
+ */
+int
+update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, uint32_t version);
+
#endif //GNUNET_SERVICE_MESSENGER_TUNNEL_H
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c
index 9944aafb8..d464424e1 100644
--- a/src/messenger/messenger_api_message.c
+++ b/src/messenger/messenger_api_message.c
@@ -178,7 +178,7 @@ get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind)
{
case GNUNET_MESSENGER_KIND_INFO:
length += member_size(struct GNUNET_MESSENGER_Message, body.info.host_key);
- length += member_size(struct GNUNET_MESSENGER_Message, body.info.unique_id);
+ length += member_size(struct GNUNET_MESSENGER_Message, body.info.messenger_version);
break;
case GNUNET_MESSENGER_KIND_JOIN:
length += member_size(struct GNUNET_MESSENGER_Message, body.join.key);
@@ -303,7 +303,7 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET
{
case GNUNET_MESSENGER_KIND_INFO:
encode_step(buffer, offset, &(body->info.host_key));
- encode_step(buffer, offset, &(body->info.unique_id));
+ encode_step(buffer, offset, &(body->info.messenger_version));
break;
case GNUNET_MESSENGER_KIND_JOIN:
encode_step(buffer, offset, &(body->join.key));
@@ -403,7 +403,7 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESS
{
case GNUNET_MESSENGER_KIND_INFO:
decode_step(buffer, offset, &(body->info.host_key));
- decode_step(buffer, offset, &(body->info.unique_id));
+ decode_step(buffer, offset, &(body->info.messenger_version));
break;
case GNUNET_MESSENGER_KIND_JOIN:
decode_step(buffer, offset, &(body->join.key));