GNUnet  0.11.x
Data Structures | Functions
gnunet-service-messenger_tunnel.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_tunnel.h"
#include "gnunet-service-messenger_handle.h"
#include "gnunet-service-messenger_message_recv.h"
#include "messenger_api_util.h"
Include dependency graph for gnunet-service-messenger_tunnel.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MessageSent
 

Functions

struct GNUNET_MESSENGER_SrvTunnelcreate_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door)
 Creates and allocates a tunnel of a room to a specific peer identity (called door). More...
 
void destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Destroys a tunnel and frees its memory fully. More...
 
void bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel)
 Binds a CADET channel to a tunnel and replaces its channel the tunnel is currently bound to if necessary. More...
 
void callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls)
 
void callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel)
 
int callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
 
int check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header)
 
int update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
void callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void update_tunnel_last_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_HashCode *hash)
 
void handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header)
 
int connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Tries to connect a tunnel by creating a new CADET channel and binding it. More...
 
void disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Disconnects and unbinds a channel from a tunnel. More...
 
int is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Returns the status of a currently bound channel of a tunnel. More...
 
static void callback_tunnel_sent (void *cls)
 
void send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash)
 Sends an envelope containing a message with a given hash through a tunnel. More...
 
int send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message)
 Sends a message by packing it automatically into an envelope and passing it through the tunnel. More...
 
void forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Forwards a given message with a known hash through a tunnel. More...
 
const struct GNUNET_HashCodeget_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Returns the hash of the latest peer message published through a given tunnel and matching the tunnels peer identity. More...
 
void get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer)
 Writes the peer identity of the peer connected via tunnel to this peer into the peer parameter. More...
 
uint32_t get_tunnel_messenger_version (const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Returns the current messenger version the peer connected via a given tunnel has reported to be using if it was compatible during updating. More...
 
int update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, uint32_t version)
 Updates the messenger version of the tunnel to a given version if it is compatible to the running peer of the service. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_tunnel.c.

Function Documentation

◆ create_tunnel()

struct GNUNET_MESSENGER_SrvTunnel* create_tunnel ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_PeerIdentity door 
)

Creates and allocates a tunnel of a room to a specific peer identity (called door).

Parameters

Definition at line 33 of file gnunet-service-messenger_tunnel.c.

References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_assert, GNUNET_new, GNUNET_PEER_intern(), GNUNET_MESSENGER_SrvTunnel::last_message, GNUNET_MESSENGER_SrvTunnel::messenger_version, GNUNET_MESSENGER_SrvTunnel::peer, GNUNET_MESSENGER_SrvTunnel::peer_message, and GNUNET_MESSENGER_SrvTunnel::room.

Referenced by callback_room_connect(), and enter_room_at().

34 {
35  GNUNET_assert((room) && (door));
36 
38 
39  tunnel->room = room;
40  tunnel->channel = NULL;
41 
42  tunnel->peer = GNUNET_PEER_intern (door);
43 
44  tunnel->messenger_version = 0;
45 
46  tunnel->peer_message = NULL;
47  tunnel->last_message = NULL;
48 
49  return tunnel;
50 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MESSENGER_SrvRoom * room
struct GNUNET_CADET_Channel * channel
GNUNET_PEER_Id GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
Intern an peer identity.
Definition: peer.c:107
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_tunnel()

void destroy_tunnel ( struct GNUNET_MESSENGER_SrvTunnel tunnel)

Destroys a tunnel and frees its memory fully.

Parameters

Definition at line 53 of file gnunet-service-messenger_tunnel.c.

References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_assert, GNUNET_CADET_channel_destroy(), GNUNET_free, GNUNET_PEER_change_rc(), GNUNET_MESSENGER_SrvTunnel::last_message, GNUNET_MESSENGER_SrvTunnel::peer, and GNUNET_MESSENGER_SrvTunnel::peer_message.

54 {
55  GNUNET_assert(tunnel);
56 
57  if (tunnel->channel)
59 
60  GNUNET_PEER_change_rc (tunnel->peer, -1);
61 
62  if (tunnel->peer_message)
63  GNUNET_free(tunnel->peer_message);
64 
65  if (tunnel->last_message)
66  GNUNET_free(tunnel->last_message);
67 
68  GNUNET_free(tunnel);
69 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CADET_Channel * channel
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:197
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:837
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ bind_tunnel()

void bind_tunnel ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
struct GNUNET_CADET_Channel channel 
)

Binds a CADET channel to a tunnel and replaces its channel the tunnel is currently bound to if necessary.

Parameters

Definition at line 72 of file gnunet-service-messenger_tunnel.c.

References callback_room_disconnect(), GNUNET_MESSENGER_SrvTunnel::channel, delayed_disconnect_channel(), GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::room.

Referenced by callback_room_connect().

73 {
74  GNUNET_assert(tunnel);
75 
76  if (tunnel->channel)
78 
79  tunnel->channel = channel;
80 }
void delayed_disconnect_channel(struct GNUNET_CADET_Channel *channel)
Starts an urgent task to close a CADET channel asynchronously.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CADET_Channel * channel
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_room_disconnect()

void callback_room_disconnect ( struct GNUNET_MESSENGER_SrvRoom room,
void *  cls 
)

Definition at line 714 of file gnunet-service-messenger_room.c.

References GNUNET_MESSENGER_SrvRoom::basement, contains_list_tunnels(), create_message_miss(), get_tunnel_peer_identity(), GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_YES, GNUNET_MESSENGER_SrvRoom::host, send_room_message(), and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by bind_tunnel(), and callback_tunnel_disconnect().

715 {
716  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
717 
718  if (!room->host)
719  return;
720 
723 
726  return;
727 
730 }
int contains_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Tests linearly if the list of tunnels peer identities contains a specific peer identity and returns G...
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
int send_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle into a room.
void get_tunnel_peer_identity(const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer)
Writes the peer identity of the peer connected via tunnel to this peer into the peer parameter...
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
struct GNUNET_MESSENGER_SrvHandle * host
struct GNUNET_MESSENGER_Message * create_message_miss(const struct GNUNET_PeerIdentity *peer)
Creates and allocates a new miss message containing the missing peer identity.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_MESSENGER_ListTunnels basement
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_tunnel_disconnect()

void callback_tunnel_disconnect ( void *  cls,
const struct GNUNET_CADET_Channel channel 
)

Definition at line 86 of file gnunet-service-messenger_tunnel.c.

References callback_room_disconnect(), callback_verify_room_message(), GNUNET_MESSENGER_SrvTunnel::channel, and GNUNET_MESSENGER_SrvTunnel::room.

Referenced by connect_tunnel(), join_room_locally(), and open_room().

87 {
88  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
89 
90  if (tunnel)
91  {
92  tunnel->channel = NULL;
93 
94  callback_room_disconnect (tunnel->room, cls);
95  }
96 }
struct GNUNET_MESSENGER_SrvRoom * room
void callback_room_disconnect(struct GNUNET_MESSENGER_SrvRoom *room, void *cls)
struct GNUNET_CADET_Channel * channel
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_verify_room_message()

int callback_verify_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
void *  cls,
struct GNUNET_MESSENGER_Message message,
struct GNUNET_HashCode hash 
)

Definition at line 733 of file gnunet-service-messenger_room.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_name_of_kind(), GNUNET_OK, GNUNET_SYSERR, GNUNET_MESSENGER_Message::header, and GNUNET_MESSENGER_MessageHeader::kind.

Referenced by callback_tunnel_disconnect(), and check_tunnel_message().

735 {
736  if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind)
737  {
738  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Message error: Kind is unknown! (%d)\n", message->header.kind);
739  return GNUNET_SYSERR;
740  }
741 
742  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving message of kind: %s!\n",
744 
745  return GNUNET_OK;
746 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:35
#define GNUNET_log(kind,...)
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_tunnel_message()

int check_tunnel_message ( void *  cls,
const struct GNUNET_MessageHeader header 
)

Definition at line 103 of file gnunet-service-messenger_tunnel.c.

References callback_room_handle_message(), callback_verify_room_message(), decode_message(), get_message_kind_size(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_SYSERR, GNUNET_YES, handle, hash_message(), GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MessageHeader::size, and update_room_message().

Referenced by join_room_locally().

104 {
105  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
106 
107  if (!tunnel)
108  return GNUNET_SYSERR;
109 
110  const uint16_t length = ntohs (header->size) - sizeof(*header);
111  const char *buffer = (const char*) &header[1];
112 
113  struct GNUNET_MESSENGER_Message message;
114 
116  {
117  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Tunnel error: Message too short! (%d)\n", length);
118  return GNUNET_SYSERR;
119  }
120 
121  uint16_t padding = 0;
122 
123  if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, &padding))
124  {
125  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Tunnel error: Decoding failed!\n");
126  return GNUNET_SYSERR;
127  }
128 
129  struct GNUNET_HashCode hash;
130  hash_message (&message, length - padding, buffer, &hash);
131 
132  return callback_verify_room_message (tunnel->room, cls, &message, &hash);
133 }
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_signature, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
Returns the minimal size in bytes to encode a message of a specific kind.
int callback_verify_room_message(struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
struct GNUNET_MESSENGER_SrvRoom * room
A 512-bit hashcode.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_room_message()

int update_room_message ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Definition at line 862 of file gnunet-service-messenger_room.c.

References add_to_list_messages(), GNUNET_MESSENGER_Message::body, cancel_store_operation(), destroy_message(), get_room_key(), get_room_message(), get_room_message_store(), get_room_operation_store(), get_store_operation_type(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_OP_REQUEST, GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_SrvRoom::last_messages, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageHeader::previous, put_store_message(), and remove_room_last_message().

Referenced by check_tunnel_message(), handle_tunnel_message(), iterate_send_room_message(), and send_room_message().

864 {
865  GNUNET_assert((room) && (message) && (hash));
866 
867  struct GNUNET_MESSENGER_OperationStore *operation_store = get_room_operation_store(room);
868 
869  const int requested = (GNUNET_MESSENGER_OP_REQUEST == get_store_operation_type(operation_store, hash)?
871  );
872 
873  if (GNUNET_YES == requested)
874  cancel_store_operation(operation_store, hash);
875 
876  const struct GNUNET_MESSENGER_Message *old_message = get_room_message (room, NULL, hash, GNUNET_NO);
877 
878  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Handle a message in room (%s).\n", GNUNET_h2s (get_room_key(room)));
879 
880  if ((old_message) || (GNUNET_OK != put_store_message (get_room_message_store(room), hash, message)))
881  {
882  if (old_message != message)
883  destroy_message(message);
884 
885  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Duplicate message got dropped!\n");
886  return GNUNET_NO;
887  }
888 
889  if ((GNUNET_YES == requested) ||
890  (GNUNET_MESSENGER_KIND_INFO == message->header.kind) ||
892  return GNUNET_YES;
893 
894  if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind)
895  remove_room_last_message(room, &(message->body.merge.previous));
896  remove_room_last_message(room, &(message->header.previous));
897 
898  add_to_list_messages (&(room->last_messages), hash);
899 
900  return GNUNET_YES;
901 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageStore * get_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
static void remove_room_last_message(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_MESSENGER_OperationStore * get_room_operation_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used operation store of a given room.
struct GNUNET_MESSENGER_ListMessages last_messages
struct GNUNET_HashCode previous
The hash of a second previous message.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageMerge merge
enum GNUNET_MESSENGER_OperationType get_store_operation_type(const struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
Retruns the type of the active operation under a given hash in a specific operation store...
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
void cancel_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
Stops any active operation under a given hash in a specific operation store.
#define GNUNET_log(kind,...)
const struct GNUNET_HashCode * get_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
int put_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_Message *message)
Stores a message into the message store.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_room_handle_message()

void callback_room_handle_message ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvHandle handle,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Definition at line 943 of file gnunet-service-messenger_room.c.

References add_to_list_messages(), get_member_session_of(), get_room_member_store(), get_store_member_of(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_NO, GNUNET_YES, handle_message_delete(), handle_message_id(), handle_message_join(), handle_message_key(), handle_message_leave(), handle_message_miss(), handle_message_name(), handle_message_peer(), handle_room_messages(), GNUNET_MESSENGER_SrvRoom::handling, GNUNET_MESSENGER_MemberUpdate::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_MemberUpdate::head, GNUNET_MESSENGER_Message::header, iterate_store_members(), iterate_update_member_sessions(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MemberUpdate::message, remove_member_session(), GNUNET_MESSENGER_MemberNotify::session, GNUNET_MESSENGER_MemberSessionCompletion::session, and GNUNET_MESSENGER_MemberUpdate::tail.

Referenced by check_tunnel_message(), handle_tunnel_message(), iterate_send_room_message(), and send_room_message().

945 {
946  struct GNUNET_MESSENGER_MemberStore *member_store = get_room_member_store(room);
947  struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
948 
949  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Callback for message (%s)\n", GNUNET_h2s (hash));
950 
951  if (!member)
952  {
953  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Message handling dropped: Member is missing!\n");
954  return;
955  }
956 
957  struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, hash);
958 
959  if (!session)
960  {
961  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Message handling dropped: Session is missing!\n");
962  return;
963  }
964 
965  struct GNUNET_MESSENGER_MemberUpdate update;
966  update.message = message;
967  update.hash = hash;
968 
969  update.head = NULL;
970  update.tail = NULL;
971 
973 
974  while (update.head)
975  {
976  struct GNUNET_MESSENGER_MemberSessionCompletion *element = update.head;
977 
978  remove_member_session (element->session->member, element->session);
979 
980  GNUNET_CONTAINER_DLL_remove(update.head, update.tail, element);
981  GNUNET_free (element);
982  }
983 
984  const int start_handle = room->handling.head ? GNUNET_NO : GNUNET_YES;
985 
986  add_to_list_messages (&(room->handling), hash);
987 
988  switch (message->header.kind)
989  {
991  handle_message_join (room, session, message, hash);
992  break;
994  handle_message_leave (room, session, message, hash);
995  break;
997  handle_message_name (room, session, message, hash);
998  break;
1000  handle_message_key (room, session, message, hash);
1001  break;
1003  handle_message_peer (room, session, message, hash);
1004  break;
1006  handle_message_id (room, session, message, hash);
1007  break;
1009  handle_message_miss (room, session, message, hash);
1010  break;
1012  handle_message_delete (room, session, message, hash);
1013  break;
1014  default:
1015  break;
1016  }
1017 
1018  if (GNUNET_YES == start_handle)
1019  handle_room_messages (room);
1020 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MESSENGER_MessageHeader header
Header.
void handle_message_name(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent name message to rename a current member.
void handle_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent peer message to make changes of the basement in the room.
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_MemberSession * session
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)
Handles a received or sent leave message to make changes of current member information.
int iterate_store_members(struct GNUNET_MESSENGER_MemberStore *store, GNUNET_MESSENGER_MemberIteratorCallback it, void *cls)
Iterate through all member sessions currently connected to the members of the given member store and ...
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void handle_message_key(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent key message to change the key of a member and rearrange the contacts accor...
struct GNUNET_MESSENGER_MemberStore * get_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
void handle_message_miss(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent miss message to drop a peer from the basement in the room.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
struct GNUNET_MESSENGER_ListMessages handling
static int iterate_update_member_sessions(void *cls, const struct GNUNET_IDENTITY_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)
const struct GNUNET_HashCode * hash
void remove_member_session(struct GNUNET_MESSENGER_Member *member, struct GNUNET_MESSENGER_MemberSession *session)
Removes a given member session from its member.
const struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_Member * get_store_member_of(struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_MESSENGER_Message *message)
Returns the member of a store using a sender id of a given message.
void handle_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent id message to change a members id.
#define GNUNET_log(kind,...)
static void handle_room_messages(struct GNUNET_MESSENGER_SrvRoom *room)
struct GNUNET_MESSENGER_MemberSession * get_member_session_of(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Returns the member session of a member using a public key which can verify the signature of a given m...
void handle_message_delete(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent delete message to delete a specific message from the store.
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)
Handles a received or sent join message to make changes of current member information.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_tunnel_last_message()

static void update_tunnel_last_message ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
const struct GNUNET_HashCode hash 
)
static

Definition at line 144 of file gnunet-service-messenger_tunnel.c.

References GNUNET_memcpy, GNUNET_new, and GNUNET_MESSENGER_SrvTunnel::last_message.

Referenced by callback_tunnel_sent(), and handle_tunnel_message().

145 {
146  if (!tunnel->last_message)
147  tunnel->last_message = GNUNET_new(struct GNUNET_HashCode);
148 
149  GNUNET_memcpy(tunnel->last_message, hash, sizeof(*hash));
150 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A 512-bit hashcode.
Here is the caller graph for this function:

◆ handle_tunnel_message()

void handle_tunnel_message ( void *  cls,
const struct GNUNET_MessageHeader header 
)

Definition at line 153 of file gnunet-service-messenger_tunnel.c.

References callback_room_handle_message(), GNUNET_MESSENGER_SrvTunnel::channel, copy_message(), decode_message(), forward_room_message(), GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_name_of_kind(), GNUNET_YES, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, recv_message_info(), recv_message_peer(), recv_message_request(), GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MessageHeader::size, update_room_message(), and update_tunnel_last_message().

Referenced by join_room_locally().

154 {
155  struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
156 
157  const uint16_t length = ntohs (header->size) - sizeof(*header);
158  const char *buffer = (const char*) &header[1];
159 
160  struct GNUNET_MESSENGER_Message message;
161  struct GNUNET_HashCode hash;
162 
163  uint16_t padding = 0;
164 
165  decode_message (&message, length, buffer, GNUNET_YES, &padding);
166  hash_message (&message, length - padding, buffer, &hash);
167 
168  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n",
169  GNUNET_MESSENGER_name_of_kind(message.header.kind));
170 
171  if (!tunnel)
172  return;
173 
174  const int new_message = update_room_message (tunnel->room, copy_message (&message), &hash);
175 
176  if (GNUNET_YES != new_message)
177  goto receive_done;
178 
179  update_tunnel_last_message (tunnel, &hash);
180 
181  int forward_message = GNUNET_YES;
182 
183  switch (message.header.kind)
184  {
186  forward_message = recv_message_info (tunnel->room, tunnel, &message, &hash);
187  break;
189  forward_message = recv_message_peer (tunnel->room, tunnel, &message, &hash);
190  break;
192  forward_message = recv_message_request (tunnel->room, tunnel, &message, &hash);
193  break;
194  default:
195  break;
196  }
197 
198  if (GNUNET_YES == forward_message)
199  {
200  forward_room_message (tunnel->room, tunnel, &message, &hash);
201  callback_room_handle_message (tunnel->room, NULL, &message, &hash);
202  }
203 
204 receive_done:
206 }
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_signature, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
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)
Handles a received info message to change the current member id to the one generated by the host conn...
int update_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:35
struct GNUNET_MESSENGER_SrvRoom * room
A 512-bit hashcode.
int recv_message_request(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received request message by checking for the requested message and forwarding it back if th...
void callback_room_handle_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
struct GNUNET_CADET_Channel * channel
int recv_message_peer(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...
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:888
#define GNUNET_log(kind,...)
static void update_tunnel_last_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_HashCode *hash)
void forward_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Forwards a message with a given hash to a specific tunnel inside of a room.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_tunnel()

int connect_tunnel ( struct GNUNET_MESSENGER_SrvTunnel tunnel)

Tries to connect a tunnel by creating a new CADET channel and binding it.

The function returns GNUNET_YES on success, otherwise GNUNET_NO.

Parameters

Definition at line 209 of file gnunet-service-messenger_tunnel.c.

References cadet, callback_tunnel_disconnect(), GNUNET_MESSENGER_SrvTunnel::channel, get_room_cadet(), get_room_key(), GNUNET_assert, GNUNET_CADET_channel_create(), GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_PEER_resolve2(), GNUNET_YES, key, GNUNET_MESSENGER_SrvTunnel::peer, and GNUNET_MESSENGER_SrvTunnel::room.

Referenced by enter_room_at(), and rebuild_room_basement_structure().

210 {
211  GNUNET_assert(tunnel);
212 
213  if (tunnel->channel)
214  return GNUNET_NO;
215 
216  const struct GNUNET_PeerIdentity *door = GNUNET_PEER_resolve2 (tunnel->peer);
217 
218  struct GNUNET_CADET_Handle *cadet = get_room_cadet (tunnel->room);
219  const struct GNUNET_HashCode *key = get_room_key (tunnel->room);
220 
222  struct GNUNET_MessageHeader, NULL),
224 
225  tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, key, NULL, callback_tunnel_disconnect, handlers);
226 
227  return GNUNET_YES;
228 }
const struct GNUNET_PeerIdentity * GNUNET_PEER_resolve2(GNUNET_PEER_Id id)
Convert an interned PID to a normal peer identity.
Definition: peer.c:245
static struct GNUNET_CADET_Handle * cadet
Handle for cadet.
Opaque handle to the service.
Definition: cadet_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void callback_tunnel_disconnect(void *cls, const struct GNUNET_CADET_Channel *channel)
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
struct GNUNET_CADET_Handle * get_room_cadet(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the CADET handle from a rooms service.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_MESSENGER_SrvRoom * room
A 512-bit hashcode.
Message handler for a specific message type.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CADET_Channel * channel
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CADET_Channel * GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Create a new channel towards a remote peer.
Definition: cadet_api.c:1031
const struct GNUNET_HashCode * get_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
Header for all communications.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect_tunnel()

void disconnect_tunnel ( struct GNUNET_MESSENGER_SrvTunnel tunnel)

Disconnects and unbinds a channel from a tunnel.

The actual disconnection will be asynchronous.

Parameters

Definition at line 231 of file gnunet-service-messenger_tunnel.c.

References GNUNET_MESSENGER_SrvTunnel::channel, delayed_disconnect_channel(), and GNUNET_assert.

Referenced by callback_room_connect(), rebuild_room_basement_structure(), and recv_message_info().

232 {
233  GNUNET_assert(tunnel);
234 
235  if (tunnel->channel)
236  {
238 
239  tunnel->channel = NULL;
240  }
241 }
void delayed_disconnect_channel(struct GNUNET_CADET_Channel *channel)
Starts an urgent task to close a CADET channel asynchronously.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CADET_Channel * channel
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_tunnel_connected()

int is_tunnel_connected ( const struct GNUNET_MESSENGER_SrvTunnel tunnel)

Returns the status of a currently bound channel of a tunnel.

Parameters
[in]tunnelTunnel
Returns
GNUNET_YES or GNUNET_NO

Definition at line 244 of file gnunet-service-messenger_tunnel.c.

References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_assert, GNUNET_NO, and GNUNET_YES.

Referenced by iterate_send_room_message(), and send_room_info().

245 {
246  GNUNET_assert(tunnel);
247 
248  return (tunnel->channel ? GNUNET_YES : GNUNET_NO);
249 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CADET_Channel * channel
Here is the caller graph for this function:

◆ callback_tunnel_sent()

static void callback_tunnel_sent ( void *  cls)
static

Definition at line 258 of file gnunet-service-messenger_tunnel.c.

References GNUNET_free, GNUNET_MESSENGER_MessageSent::hash, GNUNET_MESSENGER_MessageSent::tunnel, and update_tunnel_last_message().

Referenced by send_tunnel_envelope().

259 {
260  struct GNUNET_MESSENGER_MessageSent *sent = cls;
261 
262  if (sent->tunnel)
263  update_tunnel_last_message (sent->tunnel, &(sent->hash));
264 
265  GNUNET_free(sent);
266 }
struct GNUNET_MESSENGER_SrvTunnel * tunnel
static void update_tunnel_last_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_HashCode *hash)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_tunnel_envelope()

void send_tunnel_envelope ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
struct GNUNET_MQ_Envelope env,
const struct GNUNET_HashCode hash 
)

Sends an envelope containing a message with a given hash through a tunnel.

Parameters

Definition at line 269 of file gnunet-service-messenger_tunnel.c.

References callback_tunnel_sent(), GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_assert, GNUNET_CADET_get_mq(), GNUNET_memcpy, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_new, GNUNET_MESSENGER_MessageSent::hash, mq, and GNUNET_MESSENGER_MessageSent::tunnel.

Referenced by forward_tunnel_message(), iterate_send_room_message(), and send_tunnel_message().

271 {
272  GNUNET_assert((tunnel) && (env) && (hash));
273 
274  struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (tunnel->channel);
275 
277 
278  GNUNET_memcpy(&(sent->hash), hash, sizeof(struct GNUNET_HashCode));
279 
280  sent->tunnel = tunnel;
281 
283  GNUNET_MQ_send (mq, env);
284 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:787
A 512-bit hashcode.
struct GNUNET_MESSENGER_SrvTunnel * tunnel
struct GNUNET_CADET_Channel * channel
Handle to a message queue.
Definition: mq.c:85
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
static void callback_tunnel_sent(void *cls)
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
Definition: cadet_api.c:1082
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_tunnel_message()

int send_tunnel_message ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
void *  handle,
struct GNUNET_MESSENGER_Message message 
)

Sends a message by packing it automatically into an envelope and passing it through the tunnel.

The used handle will sign the message and the hash will be calculated and stored.

Parameters

Definition at line 287 of file gnunet-service-messenger_tunnel.c.

References destroy_message(), env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_NO, GNUNET_YES, pack_room_message(), GNUNET_MESSENGER_SrvTunnel::room, and send_tunnel_envelope().

Referenced by recv_message_info(), and send_room_info().

288 {
289  GNUNET_assert((tunnel) && (handle));
290 
291  if (!message)
292  return GNUNET_NO;
293 
294  struct GNUNET_HashCode hash;
296  tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle,
298  );
299 
300  destroy_message(message);
301 
302  if (!env)
303  return GNUNET_NO;
304 
305  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending tunnel message: %s\n",
306  GNUNET_h2s(&hash));
307 
308  send_tunnel_envelope (tunnel, env, &hash);
309  return GNUNET_YES;
310 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_MQ_Envelope * pack_room_message(const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode)
Packs a message depending on the selected mode into a newly allocated envelope.
struct GNUNET_MESSENGER_SrvRoom * room
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
void send_tunnel_envelope(struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash)
Sends an envelope containing a message with a given hash through a tunnel.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forward_tunnel_message()

void forward_tunnel_message ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Forwards a given message with a known hash through a tunnel.

Parameters

Definition at line 313 of file gnunet-service-messenger_tunnel.c.

References copy_message(), destroy_message(), env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, pack_message(), and send_tunnel_envelope().

Referenced by check_room_peer_status(), iterate_forward_members(), and recv_message_request().

315 {
316  if (!message)
317  return;
318 
319  GNUNET_assert((tunnel) && (message) && (hash));
320 
321  struct GNUNET_MESSENGER_Message *copy = copy_message(message);
323 
324  destroy_message(copy);
325 
326  if (!env)
327  return;
328 
329  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Forwarding tunnel message: %s\n",
330  GNUNET_h2s(hash));
331 
332  send_tunnel_envelope (tunnel, env, hash);
333 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego, int mode)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
#define GNUNET_MESSENGER_PACK_MODE_ENVELOPE
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
void send_tunnel_envelope(struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash)
Sends an envelope containing a message with a given hash through a tunnel.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tunnel_peer_message()

const struct GNUNET_HashCode* get_tunnel_peer_message ( const struct GNUNET_MESSENGER_SrvTunnel tunnel)

Returns the hash of the latest peer message published through a given tunnel and matching the tunnels peer identity.

If no peer message has been linked to the tunnel yet, NULL gets returned.

Parameters
[in]tunnelTunnel
Returns
Hash of peer message or NULL

Definition at line 336 of file gnunet-service-messenger_tunnel.c.

References GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::peer_message.

337 {
338  GNUNET_assert(tunnel);
339 
340  return tunnel->peer_message;
341 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

◆ get_tunnel_peer_identity()

void get_tunnel_peer_identity ( const struct GNUNET_MESSENGER_SrvTunnel tunnel,
struct GNUNET_PeerIdentity peer 
)

Writes the peer identity of the peer connected via tunnel to this peer into the peer parameter.

Parameters
[in]tunnelTunnel
[out]peerPeer identity

Definition at line 344 of file gnunet-service-messenger_tunnel.c.

References GNUNET_assert, GNUNET_PEER_resolve(), and GNUNET_MESSENGER_SrvTunnel::peer.

Referenced by callback_room_disconnect(), and recv_message_info().

345 {
346  GNUNET_assert(tunnel);
347 
348  GNUNET_PEER_resolve(tunnel->peer, peer);
349 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:225
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tunnel_messenger_version()

uint32_t get_tunnel_messenger_version ( const struct GNUNET_MESSENGER_SrvTunnel tunnel)

Returns the current messenger version the peer connected via a given tunnel has reported to be using if it was compatible during updating.

See also
update_tunnel_messenger_version
Parameters
[in]tunnelTunnel
Returns
Version of messenger

Definition at line 352 of file gnunet-service-messenger_tunnel.c.

References GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::messenger_version.

Referenced by iterate_send_room_message(), and recv_message_info().

353 {
354  GNUNET_assert(tunnel);
355 
356  return tunnel->messenger_version;
357 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the caller graph for this function:

◆ update_tunnel_messenger_version()

int update_tunnel_messenger_version ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
uint32_t  version 
)

Updates the messenger version of the tunnel to a given version if it is compatible to the running peer of the service.

Depending on success it returns GNUNET_OK or GNUNET_SYSERR on failure.

Parameters

Definition at line 360 of file gnunet-service-messenger_tunnel.c.

References GNUNET_assert, GNUNET_MESSENGER_VERSION, GNUNET_OK, GNUNET_SYSERR, and GNUNET_MESSENGER_SrvTunnel::messenger_version.

Referenced by recv_message_info().

361 {
362  GNUNET_assert(tunnel);
363 
364  if (version != GNUNET_MESSENGER_VERSION)
365  return GNUNET_SYSERR;
366 
367  if (version > tunnel->messenger_version)
368  tunnel->messenger_version = version;
369 
370  return GNUNET_OK;
371 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSENGER_VERSION
Version number of GNUnet Messenger API.
Here is the caller graph for this function: