GNUnet 0.21.1
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). 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...
 
enum GNUNET_GenericReturnValue 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...
 
enum GNUNET_GenericReturnValue is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Returns the status of a currently bound channel of a tunnel. More...
 
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...
 
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. 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...
 
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. More...
 

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

39{
40 GNUNET_assert ((room) && (door));
41
42 struct GNUNET_MESSENGER_SrvTunnel *tunnel = GNUNET_new (struct
44
45 tunnel->room = room;
46 tunnel->channel = NULL;
47
48 tunnel->peer = GNUNET_PEER_intern (door);
49
50 tunnel->messenger_version = 0;
51
52 tunnel->peer_message = NULL;
53
54 init_message_state (&(tunnel->state));
55
56 return tunnel;
57}
void init_message_state(struct GNUNET_MESSENGER_MessageState *state)
#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.
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_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 61 of file gnunet-service-messenger_tunnel.c.

62{
63 GNUNET_assert (tunnel);
64
65 if (tunnel->channel)
67
68 GNUNET_PEER_change_rc (tunnel->peer, -1);
69
70 if (tunnel->peer_message)
71 GNUNET_free (tunnel->peer_message);
72
73 clear_message_state (&(tunnel->state));
74
75 GNUNET_free (tunnel);
76}
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:830
#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_free, 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 80 of file gnunet-service-messenger_tunnel.c.

82{
83 GNUNET_assert (tunnel);
84
85 if (tunnel->channel)
87
88 tunnel->channel = channel;
89}
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:

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

256{
257 GNUNET_assert (tunnel);
258
259 if (tunnel->channel)
260 return GNUNET_NO;
261
262 const struct GNUNET_PeerIdentity *door = GNUNET_PEER_resolve2 (tunnel->peer);
263
265 const struct GNUNET_HashCode *key = get_srv_room_key (tunnel->room);
266
268 tunnel_message,
270 struct
273
274 struct GNUNET_HashCode port;
276 tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, &port,
277 NULL,
279 handlers);
280
281 return GNUNET_YES;
282}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
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.
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 callback_tunnel_disconnect(void *cls, const struct GNUNET_CADET_Channel *channel)
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:1015
@ GNUNET_YES
@ GNUNET_NO
#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 struct GNUNET_HashCode *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
A 512-bit hashcode.
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).

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_MESSAGE_TYPE_CADET_CLI, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_PEER_resolve2(), GNUNET_YES, handlers, key, GNUNET_MESSENGER_SrvTunnel::peer, port, and GNUNET_MESSENGER_SrvTunnel::room.

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

287{
288 GNUNET_assert (tunnel);
289
290 if (tunnel->channel)
291 {
293
294 tunnel->channel = NULL;
295 }
296}

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

301{
302 GNUNET_assert (tunnel);
303
304 return (tunnel->channel ? GNUNET_YES : GNUNET_NO);
305}

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

Referenced by iterate_send_room_message(), 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 327 of file gnunet-service-messenger_tunnel.c.

330{
331 GNUNET_assert ((tunnel) && (env) && (hash));
332
334
335 struct GNUNET_MESSENGER_MessageSent *sent = GNUNET_new (struct
337
338 GNUNET_memcpy (&(sent->hash), hash, sizeof(struct GNUNET_HashCode));
339
340 sent->tunnel = tunnel;
341
344}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
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:1066
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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:304
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:638
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 forward_tunnel_message(), iterate_send_room_message(), and send_tunnel_message().

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

351{
352 GNUNET_assert ((tunnel) && (handle));
353
354 if (! message)
355 return GNUNET_NO;
356
357 struct GNUNET_HashCode hash;
359 tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle,
361 );
362
363 destroy_message (message);
364
365 if (! env)
366 return GNUNET_NO;
367
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending tunnel message: %s\n",
369 GNUNET_h2s (&hash));
370
371 send_tunnel_envelope (tunnel, env, &hash);
372 return GNUNET_YES;
373}
struct GNUNET_MQ_Envelope * pack_srv_room_message(const struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_PackMode mode)
Packs a message depending on the selected mode into a newly allocated 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.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
#define GNUNET_log(kind,...)
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE

References destroy_message(), env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, GNUNET_NO, GNUNET_YES, handle, pack_srv_room_message(), GNUNET_MESSENGER_SrvTunnel::room, send_tunnel_envelope(), and GNUNET_MESSENGER_MessageSent::tunnel.

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

380{
381 GNUNET_assert ((tunnel) && (message) && (hash));
382
383 struct GNUNET_MESSENGER_Message *copy = copy_message (message);
384 struct GNUNET_MQ_Envelope *env = pack_message (copy, NULL, NULL,
386 NULL);
387
388 destroy_message (copy);
389
390 if (! env)
391 return;
392
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarding tunnel message: %s\n",
394 GNUNET_h2s (hash));
395
396 send_tunnel_envelope (tunnel, env, hash);
397}
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const GNUNET_MESSENGER_SignFunction sign, enum GNUNET_MESSENGER_PackMode mode, const void *cls)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...

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

402{
403 GNUNET_assert (tunnel);
404
405 return tunnel->peer_message;
406}

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

412{
413 GNUNET_assert (tunnel);
414
415 GNUNET_PEER_resolve (tunnel->peer, peer);
416}
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

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

Referenced by callback_room_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 420 of file gnunet-service-messenger_tunnel.c.

421{
422 GNUNET_assert (tunnel);
423
424 return tunnel->messenger_version;
425}

References GNUNET_assert, and GNUNET_MESSENGER_SrvTunnel::messenger_version.

Referenced by iterate_send_room_message(), 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 429 of file gnunet-service-messenger_tunnel.c.

431{
432 GNUNET_assert (tunnel);
433
434 if (version != GNUNET_MESSENGER_VERSION)
435 return GNUNET_SYSERR;
436
437 if (version > tunnel->messenger_version)
438 tunnel->messenger_version = version;
439
440 return GNUNET_OK;
441}
@ GNUNET_OK
@ GNUNET_SYSERR
#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: