GNUnet 0.26.2-98-gb402d9955
 
Loading...
Searching...
No Matches
gnunet-service-messenger_tunnel.h File Reference
Include dependency graph for gnunet-service-messenger_tunnel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_SrvTunnel
 

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).
 
void destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Destroys a tunnel and frees its memory fully.
 
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.
 
enum GNUNET_GenericReturnValue check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header)
 Callback for message verification via header in a tunnel that is provided as a closure from a CADET channel.
 
void handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header)
 Callback for message handling via header in a tunnel that is provided as a closure from a CADET channel.
 
void callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel)
 Callback for a CADET channel disconnecting to manage this event as a proper tunnel provided as its closure.
 
enum GNUNET_GenericReturnValue connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Tries to connect a tunnel by creating a new CADET channel and binding it.
 
void disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Disconnects and unbinds a channel from a tunnel.
 
enum GNUNET_GenericReturnValue is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Returns the status of a currently bound channel of a tunnel.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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 peer of the service.
 

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
[in,out]roomRoom
[in]doorPeer identity
Returns
New tunnel

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

45{
46 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
47
48 GNUNET_assert ((room) && (door));
49
50 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new tunnel: %s\n",
51 GNUNET_i2s (door));
52
53 tunnel = GNUNET_new (struct GNUNET_MESSENGER_SrvTunnel);
54
55 tunnel->room = room;
56 tunnel->channel = NULL;
57
58 tunnel->peer = GNUNET_PEER_intern (door);
59
60 tunnel->messenger_version = 0;
61
62 tunnel->peer_message = NULL;
63
64 init_message_state (&(tunnel->state));
65
66 return tunnel;
67}
void init_message_state(struct GNUNET_MESSENGER_MessageState *state)
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_PEER_Id GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
Intern an peer identity.
Definition peer.c:108
struct GNUNET_CADET_Channel * channel
struct GNUNET_MESSENGER_MessageState state
struct GNUNET_MESSENGER_SrvRoom * room

References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_PEER_intern(), init_message_state(), GNUNET_MESSENGER_SrvTunnel::messenger_version, GNUNET_MESSENGER_SrvTunnel::peer, GNUNET_MESSENGER_SrvTunnel::peer_message, GNUNET_MESSENGER_SrvTunnel::room, and GNUNET_MESSENGER_SrvTunnel::state.

Referenced by callback_room_connect(), and enter_srv_room_at().

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
[in,out]tunnel

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

72{
73 GNUNET_assert (tunnel);
74
75 if (tunnel->channel)
77
78 GNUNET_PEER_change_rc (tunnel->peer, -1);
79
80 if (tunnel->peer_message)
81 GNUNET_free (tunnel->peer_message);
82
83 clear_message_state (&(tunnel->state));
84
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free tunnel!\n");
86
87 GNUNET_free (tunnel);
88}
void clear_message_state(struct GNUNET_MESSENGER_MessageState *state)
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition cadet_api.c:833
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition peer.c:192

References GNUNET_MESSENGER_SrvTunnel::channel, clear_message_state(), GNUNET_assert, GNUNET_CADET_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PEER_change_rc(), GNUNET_MESSENGER_SrvTunnel::peer, GNUNET_MESSENGER_SrvTunnel::peer_message, and GNUNET_MESSENGER_SrvTunnel::state.

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
[in,out]tunnelTunnel
[in,out]channelCADET channel

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

94{
95 GNUNET_assert (tunnel);
96
97 if (tunnel->channel)
99
100 tunnel->channel = channel;
101}
void delayed_disconnect_channel(struct GNUNET_CADET_Channel *channel)
Starts an urgent task to close a CADET channel asynchronously.

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

Referenced by callback_room_connect().

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

◆ check_tunnel_message()

enum GNUNET_GenericReturnValue check_tunnel_message ( void *  cls,
const struct GNUNET_MessageHeader header 
)

Callback for message verification via header in a tunnel that is provided as a closure from a CADET channel.

Parameters
[in,out]clsClosure
[in]headerMessage header

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

238{
239 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
240 struct GNUNET_MESSENGER_Message message;
241 struct GNUNET_HashCode hash;
242 uint16_t length;
243 const char *buffer;
244
245 GNUNET_assert (header);
246
247 tunnel = cls;
248
249 if (! tunnel)
250 return GNUNET_SYSERR;
251
252 length = ntohs (header->size) - sizeof(*header);
253 buffer = (const char*) &header[1];
254
256 GNUNET_YES))
257 {
259 "Tunnel error: Message too short! (%d)\n", length);
260 return GNUNET_SYSERR;
261 }
262
263 {
264 uint16_t padding;
265 padding = 0;
266
267 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES,
268 &padding))
269 {
271 "Tunnel error: Decoding failed!\n");
272 return GNUNET_SYSERR;
273 }
274
275 hash_message (&message, length - padding, buffer, &hash);
276 }
277
278 return verify_tunnel_message (tunnel->room, &message, &hash);
279}
static enum GNUNET_GenericReturnValue verify_tunnel_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_YES
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
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.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximum length in bytes.
A 512-bit hashcode.

References decode_message(), get_message_kind_size(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_SYSERR, GNUNET_YES, hash_message(), GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MessageHeader::size, and verify_tunnel_message().

Here is the call graph for this function:

◆ handle_tunnel_message()

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

Callback for message handling via header in a tunnel that is provided as a closure from a CADET channel.

Parameters
[in,out]clsClosure
[in]headerMessage header

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

324{
325 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
326 struct GNUNET_MESSENGER_Message message;
327 struct GNUNET_HashCode hash;
328 uint16_t length;
329 const char *buffer;
330
331 GNUNET_assert (header);
332
333 tunnel = cls;
334
335 if (! tunnel)
336 return;
337
338 length = ntohs (header->size) - sizeof(*header);
339 buffer = (const char*) &header[1];
340
341 {
342 uint16_t padding;
343 padding = 0;
344
345 decode_message (&message, length, buffer, GNUNET_YES, &padding);
346 hash_message (&message, length - padding, buffer, &hash);
347 }
348
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n",
350 GNUNET_MESSENGER_name_of_kind (message.header.kind));
351
352 {
353 enum GNUNET_GenericReturnValue new_message;
354 new_message = update_room_message (tunnel->room,
355 copy_message (&message),
356 &hash);
357
358 if (GNUNET_YES != new_message)
359 goto receive_done;
360 }
361
362 update_tunnel_last_message (tunnel, &hash);
363
364 {
365 enum GNUNET_GenericReturnValue forward_message;
366 forward_message = GNUNET_YES;
367
368 switch (message.header.kind)
369 {
371 forward_message = recv_message_info (
372 tunnel->room,
373 tunnel,
374 &message,
375 &hash);
376 break;
378 forward_message = recv_message_peer (
379 tunnel->room,
380 tunnel,
381 &message,
382 &hash);
383 break;
385 forward_message = recv_message_miss (
386 tunnel->room,
387 tunnel,
388 &message,
389 &hash);
390 break;
392 forward_message = recv_message_request (
393 tunnel->room,
394 tunnel,
395 &message,
396 &hash);
397 break;
398 default:
399 break;
400 }
401
402 if (GNUNET_YES == forward_message)
403 {
404 struct GNUNET_MQ_Envelope *envelope;
405
406 envelope = pack_message (&message, NULL,
408
409 if (! envelope)
410 {
412 "Packing message into envelope failed: %s\n",
413 GNUNET_h2s (&hash));
414 goto receive_done;
415 }
416
417 send_srv_room_envelope (tunnel->room, tunnel, envelope, &hash);
418 callback_room_handle_message (tunnel->room, &message, &hash);
419 }
420 }
421
422receive_done:
423 cleanup_message (&message);
424
426 "# messages received",
427 1,
428 GNUNET_NO);
429
431}
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 th...
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.
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 conn...
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.
void send_srv_room_envelope(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *envelope, const struct GNUNET_HashCode *hash)
Sends an envelope from a message with a given hash excluding a specific tunnel inside of a room.
enum GNUNET_GenericReturnValue 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, 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 GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Indicate readiness to receive the next message on a channel.
Definition cadet_api.c:875
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_PackMode 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.
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
struct GNUNET_STATISTICS_Handle * statistics
struct GNUNET_MESSENGER_Service * service

References callback_room_handle_message(), GNUNET_MESSENGER_SrvTunnel::channel, cleanup_message(), copy_message(), decode_message(), GNUNET_assert, GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_name_of_kind(), GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, hash_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, pack_message(), recv_message_info(), recv_message_miss(), recv_message_peer(), recv_message_request(), GNUNET_MESSENGER_SrvTunnel::room, send_srv_room_envelope(), GNUNET_MESSENGER_SrvRoom::service, GNUNET_MessageHeader::size, GNUNET_MESSENGER_Service::statistics, update_room_message(), and update_tunnel_last_message().

Here is the call graph for this function:

◆ callback_tunnel_disconnect()

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

Callback for a CADET channel disconnecting to manage this event as a proper tunnel provided as its closure.

Parameters
[in,out]clsClosure
[in]channelCADET channel

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

107{
108 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
109 struct GNUNET_MESSENGER_SrvRoom *room;
111
112 tunnel = cls;
113
114 if (! tunnel)
115 return;
116
117 GNUNET_assert (tunnel->room);
118
119 room = tunnel->room;
120
122
124 "Connection dropped to room (%s) from peer: %s\n",
126
127 tunnel->channel = NULL;
128
129 if (! room->host)
130 return;
131
133 &identity,
134 tunnel)) ||
136 &identity)))
137 return;
138
140 "# tunnels connected",
141 -1,
142 GNUNET_NO);
143
145 {
146 struct GNUNET_MESSENGER_Message *message;
147
148 message = create_message_miss (&identity);
149
150 if (! message)
152 "Sending miss message about tunnel failed: %s\n",
153 GNUNET_h2s (&(room->key)));
154 else
155 send_srv_room_message (room, room->host, message);
156 }
157
160 return;
161
163 "Search for alternate tunnel for room: %s\n",
165
166 {
167 struct GNUNET_MESSENGER_ListTunnel *element;
168 element = find_list_tunnels_alternate (&(room->basement), &identity);
169
170 if (! element)
171 {
173 "No alternative tunnel was found!\n");
174 return;
175 }
176
177 GNUNET_PEER_resolve (element->peer, &identity);
178 }
179
180 enter_srv_room_at (room, room->host, &identity);
181}
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
struct GNUNET_MESSENGER_Message * create_message_miss(const struct GNUNET_PeerIdentity *peer)
Creates and allocates a new miss message containing the missing peer identity.
enum GNUNET_GenericReturnValue enter_srv_room_at(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door)
Connects a tunnel to a hosting peer of a room through a so called door which is represented by a peer...
enum GNUNET_GenericReturnValue send_srv_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.
const struct GNUNET_HashCode * get_srv_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access 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.
enum GNUNET_GenericReturnValue 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).
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
enum GNUNET_GenericReturnValue 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.
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
struct GNUNET_MESSENGER_ListTunnel * find_list_tunnels_alternate(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Searches linearly through the list of tunnels peer identities for matching against a specific peer id...
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...
enum GNUNET_GenericReturnValue auto_connecting
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
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_Service::auto_connecting, GNUNET_MESSENGER_SrvRoom::basement, GNUNET_MESSENGER_SrvTunnel::channel, contains_list_tunnels(), create_message_miss(), enter_srv_room_at(), find_list_tunnels_alternate(), get_srv_room_key(), get_tunnel_peer_identity(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_PEER_resolve(), GNUNET_STATISTICS_update(), GNUNET_YES, GNUNET_MESSENGER_SrvRoom::host, identity, GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_ListTunnel::peer, GNUNET_MESSENGER_SrvTunnel::room, send_srv_room_message(), GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_Service::statistics, and GNUNET_MESSENGER_SrvRoom::tunnels.

Referenced by connect_tunnel(), and open_srv_room().

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

◆ connect_tunnel()

enum GNUNET_GenericReturnValue 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
[in,out]tunnelTunnel
Returns
GNUNET_YES on success, otherwise GNUNET_NO

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

436{
437 const struct GNUNET_PeerIdentity *door;
440
441 GNUNET_assert (tunnel);
442
443 if (tunnel->channel)
444 return GNUNET_NO;
445
446 door = GNUNET_PEER_resolve2 (tunnel->peer);
447 cadet = get_srv_room_cadet (tunnel->room);
448
450 &(key.hash),
451 get_srv_room_key (tunnel->room),
452 sizeof (key.hash));
453
454 if ((key.code.feed_bit) && (! key.code.group_bit))
455 {
457 "Tunnel to personal room containing private feeds failed!");
458 return GNUNET_SYSERR;
459 }
460
461 {
462 struct GNUNET_HashCode port;
464 tunnel_message,
466 struct
468 ,
470
472 tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, &port,
473 NULL,
475 handlers);
476 }
477
478 if (! tunnel->channel)
479 return GNUNET_SYSERR;
480
482 "# tunnels connected",
483 1,
484 GNUNET_NO);
485
486 return GNUNET_YES;
487}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
static uint16_t port
Port number.
Definition gnunet-bcd.c:146
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_CADET_Handle * cadet
Handle for cadet.
struct GNUNET_CADET_Handle * get_srv_room_cadet(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the CADET handle from a rooms service.
void callback_tunnel_disconnect(void *cls, const struct GNUNET_CADET_Channel *channel)
Callback for a CADET channel disconnecting to manage this event as a proper tunnel provided as its cl...
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:1030
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
const struct GNUNET_PeerIdentity * GNUNET_PEER_resolve2(GNUNET_PEER_Id id)
Convert an interned PID to a normal peer identity.
Definition peer.c:234
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
void convert_messenger_key_to_port(const union GNUNET_MESSENGER_RoomKey *key, struct GNUNET_HashCode *port)
Converts a Messenger service key of a room to the specific port which gets used for the CADET channel...
Opaque handle to the service.
Definition cadet_api.c:39
Message handler for a specific message type.
Header for all communications.
A room key unifies a room key code and its 512bit hash representation.

References cadet, callback_tunnel_disconnect(), GNUNET_MESSENGER_SrvTunnel::channel, convert_messenger_key_to_port(), get_srv_room_cadet(), get_srv_room_key(), GNUNET_assert, GNUNET_CADET_channel_create(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_CADET_CLI, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_PEER_resolve2(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, handlers, key, GNUNET_MESSENGER_SrvTunnel::peer, port, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvRoom::service, and GNUNET_MESSENGER_Service::statistics.

Referenced by enter_srv_room_at(), and rebuild_srv_room_basement_structure().

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
[in,out]tunnelTunnel

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

492{
493 GNUNET_assert (tunnel);
494
495 if (tunnel->channel)
496 {
498
499 tunnel->channel = NULL;
500 }
501}

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

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

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

◆ is_tunnel_connected()

enum GNUNET_GenericReturnValue 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 505 of file gnunet-service-messenger_tunnel.c.

506{
507 GNUNET_assert (tunnel);
508
509 return (tunnel->channel ? GNUNET_YES : GNUNET_NO);
510}

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

Referenced by iterate_send_room_envelope(), and send_room_info().

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
[in,out]tunnelTunnel
[in,out]envEnvelope
[in]hashHash of message

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

546{
547 struct GNUNET_MQ_Handle *mq;
548 struct GNUNET_MESSENGER_MessageSent *sent;
549
550 GNUNET_assert ((tunnel) && (env) && (hash));
551
554
555 GNUNET_memcpy (&(sent->hash), hash, sizeof(struct GNUNET_HashCode));
556
557 sent->tunnel = tunnel;
558
561}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
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 channel.
Definition cadet_api.c:1081
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:305
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:655
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
struct GNUNET_MESSENGER_SrvTunnel * tunnel
Handle to a message queue.
Definition mq.c:87

References callback_tunnel_sent(), GNUNET_MESSENGER_SrvTunnel::channel, env, 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 callback_tunnel_message_signed(), forward_tunnel_message(), and iterate_send_room_envelope().

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

◆ send_tunnel_message()

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.

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

Parameters
[in,out]tunnelTunnel
[in,out]handleHandle
[in,out]messageMessage
Returns
GNUNET_YES on success, GNUNET_NO otherwise

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

590{
591 GNUNET_assert ((tunnel) && (tunnel->room));
592
593 if (! message)
594 return GNUNET_NO;
595
597 "Sending message from tunnel in room: %s (%s)\n",
598 GNUNET_h2s (&(tunnel->room->key)),
600
601 return sign_srv_room_message (tunnel->room, message,
603 tunnel);
604}
enum GNUNET_GenericReturnValue sign_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, GNUNET_MESSENGER_SignedCallback callback, void *closure)
Packs a message depending on its kind into a newly allocated envelope.
static void callback_tunnel_message_signed(void *cls, struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MQ_Envelope *envelope, const struct GNUNET_HashCode *hash)
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.

References callback_tunnel_message_signed(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_name_of_kind(), GNUNET_NO, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_SrvRoom::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_SrvTunnel::room, and sign_srv_room_message().

Referenced by recv_message_info(), and send_room_info().

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
[in,out]tunnelTunnel
[in]messageMessage
[in]hashHash of message

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

611{
612 struct GNUNET_MESSENGER_Message *copy;
613 struct GNUNET_MQ_Envelope *envelope;
614
615 GNUNET_assert ((tunnel) && (message) && (hash));
616
617 copy = copy_message (message);
618 envelope = pack_message (copy, NULL,
620
621 destroy_message (copy);
622
623 if (! envelope)
624 return;
625
626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarding tunnel message: %s\n",
627 GNUNET_h2s (hash));
628
629 send_tunnel_envelope (tunnel, envelope, hash);
630}
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.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.

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

Referenced by callback_found_message(), check_srv_room_peer_status(), forward_about_members(), and recv_message_info().

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 634 of file gnunet-service-messenger_tunnel.c.

635{
636 GNUNET_assert (tunnel);
637
638 return tunnel->peer_message;
639}

References GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::peer_message.

◆ 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 643 of file gnunet-service-messenger_tunnel.c.

645{
646 GNUNET_assert (tunnel);
647
648 GNUNET_PEER_resolve (tunnel->peer, peer);
649}

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

Referenced by callback_tunnel_disconnect(), and recv_message_info().

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 653 of file gnunet-service-messenger_tunnel.c.

654{
655 GNUNET_assert (tunnel);
656
657 return tunnel->messenger_version;
658}

References GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::messenger_version.

Referenced by iterate_send_room_envelope(), and recv_message_info().

Here is the caller graph for this function:

◆ update_tunnel_messenger_version()

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 peer of the service.

Depending on success it returns GNUNET_OK or GNUNET_SYSERR on failure.

Parameters
[in,out]tunnelTunnel
[in]versionVersion of messenger
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

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

664{
665 GNUNET_assert (tunnel);
666
667 if (version != GNUNET_MESSENGER_VERSION)
668 return GNUNET_SYSERR;
669
670 if (version > tunnel->messenger_version)
671 tunnel->messenger_version = version;
672
673 return GNUNET_OK;
674}
@ GNUNET_OK
#define GNUNET_MESSENGER_VERSION
Version number of GNUnet Messenger API.

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

Referenced by recv_message_info().

Here is the caller graph for this function: