GNUnet 0.22.2
gnunet-service-messenger_message_recv.c File Reference
Include dependency graph for gnunet-service-messenger_message_recv.c:

Go to the source code of this file.

Functions

static void forward_about_members (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_CONTAINER_MultiHashMap *map)
 
static enum GNUNET_GenericReturnValue iterate_forward_members (void *cls, const struct GNUNET_CRYPTO_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)
 
enum GNUNET_GenericReturnValue 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 connected to. More...
 
enum GNUNET_GenericReturnValue 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. More...
 
enum GNUNET_GenericReturnValue recv_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Handles a received miss message to react to activity in the basement of a room. More...
 
static void callback_found_message (void *cls, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
enum GNUNET_GenericReturnValue 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 the message was found. More...
 

Function Documentation

◆ forward_about_members()

static void forward_about_members ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvTunnel tunnel,
struct GNUNET_MESSENGER_MemberSession session,
struct GNUNET_CONTAINER_MultiHashMap map 
)
static

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

37{
38 struct GNUNET_MESSENGER_MessageStore *message_store;
39 struct GNUNET_MESSENGER_ListMessage *element;
40
41 GNUNET_assert ((room) && (tunnel) && (session) && (map));
42
43 if (session->prev)
44 forward_about_members (room, tunnel, session->prev, map);
45
46 message_store = get_srv_room_message_store (room);
47
48 for (element = session->messages.head; element; element = element->next)
49 {
50 const struct GNUNET_MESSENGER_Message *message;
51
53 &(element->hash)))
54 continue;
55
57 NULL,
59
61 "Forwarding of session message could be duplicated!\n");
62
63 message = get_store_message (message_store, &(element->hash));
64
65 if (! message)
66 continue;
67
68 forward_tunnel_message (tunnel, message, &(element->hash));
69 }
70}
static void forward_about_members(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_MemberSession *session, struct GNUNET_CONTAINER_MultiHashMap *map)
const struct GNUNET_MESSENGER_Message * get_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Returns the message from a message store matching a given hash.
struct GNUNET_MESSENGER_MessageStore * get_srv_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:63
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
struct GNUNET_MESSENGER_MemberSession * prev
struct GNUNET_MESSENGER_ListMessages messages

References forward_about_members(), forward_tunnel_message(), get_srv_room_message_store(), get_store_message(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, map, GNUNET_MESSENGER_MemberSession::messages, GNUNET_MESSENGER_ListMessage::next, and GNUNET_MESSENGER_MemberSession::prev.

Referenced by forward_about_members(), and iterate_forward_members().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_forward_members()

static enum GNUNET_GenericReturnValue iterate_forward_members ( void *  cls,
const struct GNUNET_CRYPTO_PublicKey public_key,
struct GNUNET_MESSENGER_MemberSession session 
)
static

Definition at line 74 of file gnunet-service-messenger_message_recv.c.

77{
78 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
79
80 GNUNET_assert ((cls) && (session));
81
82 tunnel = cls;
83
85 return GNUNET_YES;
86
87 {
90
91 forward_about_members (tunnel->room, tunnel, session, map);
92
94 }
95
96 return GNUNET_YES;
97}
enum GNUNET_GenericReturnValue is_member_session_completed(const struct GNUNET_MESSENGER_MemberSession *session)
Returns if the given member session has been completed.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_NO
Internal representation of the hash map.
struct GNUNET_MESSENGER_SrvRoom * room

References forward_about_members(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_NO, GNUNET_YES, is_member_session_completed(), map, and GNUNET_MESSENGER_SrvTunnel::room.

Referenced by recv_message_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_message_info()

enum GNUNET_GenericReturnValue 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 connected to.

(all current tunnels will be informed about the id change)

Parameters
[in,out]roomRoom of the message
[in,out]tunnelReceiving connection
[in]messageINFO-Message
[in]hashHash of the message
Returns
GNUNET_NO to not forward the message

Definition at line 101 of file gnunet-service-messenger_message_recv.c.

105{
106 uint32_t version;
107 struct GNUNET_PeerIdentity peer;
108
109 version = get_tunnel_messenger_version (tunnel);
110
112 message->body.info.
113 messenger_version))
114 {
115 disconnect_tunnel (tunnel);
116 return GNUNET_NO;
117 }
118
119 if (version == get_tunnel_messenger_version (tunnel))
120 return GNUNET_NO;
121
122 if (room->host)
124 room->service));
125
126 get_tunnel_peer_identity (tunnel, &peer);
127
128 if (GNUNET_YES != contains_list_tunnels (&(room->basement), &peer))
129 {
130 struct GNUNET_MESSENGER_MessageStore *message_store;
131 struct GNUNET_MESSENGER_MemberStore *member_store;
132 struct GNUNET_MESSENGER_ListTunnel *element;
133
134 message_store = get_srv_room_message_store (room);
135 member_store = get_srv_room_member_store (room);
136
137 for (element = room->basement.head; element; element = element->next)
138 {
139 const struct GNUNET_MESSENGER_Message *msg;
140
141 if (! element->hash)
142 continue;
143
144 msg = get_store_message (message_store, element->hash);
145
146 if (! msg)
147 continue;
148
149 forward_tunnel_message (tunnel, msg, element->hash);
150 }
151
152 iterate_store_members (member_store, iterate_forward_members, tunnel);
153 }
154
155 check_srv_room_peer_status (room, tunnel);
156 return GNUNET_NO;
157}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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 ...
struct GNUNET_MESSENGER_Message * create_message_info(struct GNUNET_MESSENGER_Service *service)
Creates and allocates a new info message containing the hosts service peer identity and version.
static enum GNUNET_GenericReturnValue iterate_forward_members(void *cls, const struct GNUNET_CRYPTO_PublicKey *public_key, struct GNUNET_MESSENGER_MemberSession *session)
void check_srv_room_peer_status(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Checks the current state of opening a given room from this peer and re-publishes it if necessary to a...
struct GNUNET_MESSENGER_MemberStore * get_srv_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
enum GNUNET_GenericReturnValue 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 pee...
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 ...
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.
void disconnect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Disconnects and unbinds a channel from a tunnel.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue 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...
struct GNUNET_MESSENGER_ListTunnel * next
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_MessageInfo info
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_Service * service
struct GNUNET_MESSENGER_ListTunnels basement
struct GNUNET_MESSENGER_SrvHandle * host
The identity of the host (wraps the signing key of the peer).

References GNUNET_MESSENGER_SrvRoom::basement, GNUNET_MESSENGER_Message::body, check_srv_room_peer_status(), contains_list_tunnels(), create_message_info(), disconnect_tunnel(), forward_tunnel_message(), get_srv_room_member_store(), get_srv_room_message_store(), get_store_message(), get_tunnel_messenger_version(), get_tunnel_peer_identity(), GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_ListTunnel::hash, GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_SrvRoom::host, GNUNET_MESSENGER_MessageBody::info, iterate_forward_members(), iterate_store_members(), msg, GNUNET_MESSENGER_ListTunnel::next, send_tunnel_message(), GNUNET_MESSENGER_SrvRoom::service, and update_tunnel_messenger_version().

Referenced by handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_message_peer()

enum GNUNET_GenericReturnValue 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.

(the peer message and the member id can potentially be linked to the tunnel)

Parameters
[in,out]roomRoom of the message
[in,out]tunnelReceiving connection
[in]messagePEER-Message
[in]hashHash of the message
Returns
GNUNET_YES to forward the message

Definition at line 161 of file gnunet-service-messenger_message_recv.c.

165{
166 struct GNUNET_PeerIdentity peer;
167
168 GNUNET_PEER_resolve (tunnel->peer, &peer);
169
170 if (0 == GNUNET_memcmp (&peer, &(message->body.peer.peer)))
171 {
172 if (! tunnel->peer_message)
173 tunnel->peer_message = GNUNET_new (struct GNUNET_HashCode);
174
175 GNUNET_memcpy (tunnel->peer_message, &hash, sizeof(hash));
176 }
177
178 update_to_list_tunnels (&(room->basement), &(message->body.peer.peer), hash);
179 return GNUNET_YES;
180}
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#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_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:220
void update_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *hash)
Updates a specific peer from a tunnel in the list.
A 512-bit hashcode.
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.

References GNUNET_MESSENGER_SrvRoom::basement, GNUNET_MESSENGER_Message::body, GNUNET_memcmp, GNUNET_memcpy, GNUNET_new, GNUNET_PEER_resolve(), GNUNET_YES, GNUNET_MESSENGER_MessagePeer::peer, GNUNET_MESSENGER_MessageBody::peer, GNUNET_MESSENGER_SrvTunnel::peer, GNUNET_MESSENGER_SrvTunnel::peer_message, and update_to_list_tunnels().

Referenced by handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_message_miss()

enum GNUNET_GenericReturnValue recv_message_miss ( struct GNUNET_MESSENGER_SrvRoom room,
struct GNUNET_MESSENGER_SrvTunnel tunnel,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Handles a received miss message to react to activity in the basement of a room.

(the miss message can cause automatic opening of the room)

Parameters
[in,out]roomRoom of the message
[in,out]tunnelReceiving connection
[in]messageMISS-Message
[in]hashHash of the message
Returns
GNUNET_YES to forward the message

Definition at line 184 of file gnunet-service-messenger_message_recv.c.

188{
190
191 service = room->service;
192
193 if ((GNUNET_YES == service->auto_routing) &&
194 (service->min_routers > count_of_tunnels (&(room->basement))))
195 open_srv_room (room, NULL);
196
197 return GNUNET_YES;
198}
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
size_t count_of_tunnels(const struct GNUNET_MESSENGER_ListTunnels *tunnels)
Returns the count of peers in a list (typically from the basement of a room).
enum GNUNET_GenericReturnValue open_srv_room(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Tries to open a room for a given handle.

References GNUNET_MESSENGER_SrvRoom::basement, count_of_tunnels(), GNUNET_YES, open_srv_room(), service, and GNUNET_MESSENGER_SrvRoom::service.

Referenced by handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_found_message()

static void callback_found_message ( void *  cls,
struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 202 of file gnunet-service-messenger_message_recv.c.

206{
207 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
208
209 GNUNET_assert ((cls) && (room) && (hash));
210
211 tunnel = cls;
212
213 if (! message)
214 {
215 struct GNUNET_MESSENGER_OperationStore *operation_store;
216
217 operation_store = get_srv_room_operation_store (room);
218
220 operation_store,
221 hash,
224 );
225 }
226 else
227 forward_tunnel_message (tunnel, message, hash);
228}
enum GNUNET_GenericReturnValue use_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_OperationType type, struct GNUNET_TIME_Relative delay)
Tries to use an operation under a given hash in a specific operation store.
struct GNUNET_MESSENGER_OperationStore * get_srv_room_operation_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used operation store of a given room.
#define GNUNET_MESSENGER_REQUEST_DELAY

References forward_tunnel_message(), get_srv_room_operation_store(), GNUNET_assert, GNUNET_MESSENGER_OP_REQUEST, GNUNET_MESSENGER_REQUEST_DELAY, GNUNET_MESSENGER_OperationStore::room, GNUNET_MESSENGER_SrvTunnel::room, and use_store_operation().

Referenced by recv_message_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_message_request()

enum GNUNET_GenericReturnValue 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 the message was found.

(this can also cause this peer to send a new request instead of only forwarding the received one)

Parameters
[in,out]roomRoom of the message
[in,out]tunnelReceiving connection
[in]messageREQUEST-Message
[in]hashHash of the message
Returns
GNUNET_YES or GNUNET_NO depending on required forwarding

Definition at line 236 of file gnunet-service-messenger_message_recv.c.

240{
241 struct GNUNET_MESSENGER_MemberStore *member_store;
242 struct GNUNET_MESSENGER_Member *member;
243 struct GNUNET_MESSENGER_MemberSession *session;
244
245 member_store = get_srv_room_member_store (room);
246 member = get_store_member_of (member_store, message);
247
248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request for message (%s)\n",
249 GNUNET_h2s (hash));
250
251 if (! member)
252 return GNUNET_NO;
253
254 session = get_member_session_of (member, message, hash);
255
256 if ((! session) || (GNUNET_YES != check_member_session_history (session,
257 &(message->
258 body.request
259 .hash),
260 GNUNET_NO)))
261 return GNUNET_NO;
262
264 &(message->body.request.hash),
265 session, callback_found_message,
266 tunnel))
267 return GNUNET_YES;
268
269 return GNUNET_NO;
270}
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...
enum GNUNET_GenericReturnValue check_member_session_history(const struct GNUNET_MESSENGER_MemberSession *session, const struct GNUNET_HashCode *hash, enum GNUNET_GenericReturnValue ownership)
Checks the history of a session for a specific message which is identified by its hash and if the own...
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.
static void callback_found_message(void *cls, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
enum GNUNET_GenericReturnValue request_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_MemberSession *session, GNUNET_MESSENGER_MessageRequestCallback callback, void *cls)
Requests a message from a room identified by a given hash.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_HashCode hash
The hash of the requested message.

References GNUNET_MESSENGER_Message::body, callback_found_message(), check_member_session_history(), get_member_session_of(), get_srv_room_member_store(), get_store_member_of(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_MessageRequest::hash, GNUNET_MESSENGER_MemberSession::member, GNUNET_MESSENGER_MessageBody::request, and request_srv_room_message().

Referenced by handle_tunnel_message().

Here is the call graph for this function:
Here is the caller graph for this function: