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

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_cadet_service.h"
#include "gnunet_peer_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet-service-messenger_room.h"
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. More...
 
void destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel)
 Destroys a tunnel and frees its memory fully. More...
 
int bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel)
 Binds a CADET channel to a tunnel on returns GNUNET_YES only if the bounds channel was replaced successfully, otherwise GNUNET_NO gets returned. More...
 
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...
 
void send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MQ_Envelope *env, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Sends an envelope containing a message with a given hash through a tunnel by a given handle. More...
 
void send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
 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...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_tunnel.h.

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.

Parameters
roomRoom
doorPeer identity
Returns
New tunnel

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

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

Referenced by callback_room_connect(), and entry_room_at().

33 {
34  GNUNET_assert((room) && (door));
35 
37 
38  tunnel->room = room;
39  tunnel->channel = NULL;
40 
41  tunnel->peer = GNUNET_PEER_intern (door);
42  tunnel->contact_id = NULL;
43 
44  tunnel->peer_message = NULL;
45  tunnel->last_message = NULL;
46 
47  return tunnel;
48 }
#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
struct GNUNET_ShortHashCode * contact_id
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
tunnel

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

References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_MESSENGER_SrvTunnel::contact_id, 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.

52 {
53  GNUNET_assert(tunnel);
54 
55  if (tunnel->channel)
57 
58  GNUNET_PEER_change_rc (tunnel->peer, -1);
59 
60  if (tunnel->contact_id)
61  GNUNET_free(tunnel->contact_id);
62 
63  if (tunnel->peer_message)
64  GNUNET_free(tunnel->peer_message);
65 
66  if (tunnel->last_message)
67  GNUNET_free(tunnel->last_message);
68 
69  GNUNET_free(tunnel);
70 }
#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
struct GNUNET_ShortHashCode * contact_id
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()

int bind_tunnel ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
struct GNUNET_CADET_Channel channel 
)

Binds a CADET channel to a tunnel on returns GNUNET_YES only if the bounds channel was replaced successfully, otherwise GNUNET_NO gets returned.

Parameters
tunnelTunnel
channelCADET channel
Returns
GNUNET_YES on success, otherwise GNUNET_NO

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

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

Referenced by callback_room_connect().

74 {
75  GNUNET_assert(tunnel);
76 
77  if (tunnel->channel)
78  {
79  if (tunnel->contact_id)
80  return GNUNET_NO;
81 
83  }
84 
85  tunnel->channel = channel;
86 
87  return GNUNET_YES;
88 }
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
struct GNUNET_ShortHashCode * contact_id
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
tunnelTunnel
Returns
GNUNET_YES on success, otherwise GNUNET_NO

Definition at line 191 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 entry_room_at(), and rebuild_room_basement_structure().

192 {
193  GNUNET_assert(tunnel);
194 
195  if (tunnel->channel)
196  return GNUNET_NO;
197 
198  const struct GNUNET_PeerIdentity *door = GNUNET_PEER_resolve2 (tunnel->peer);
199 
200  struct GNUNET_CADET_Handle *cadet = get_room_cadet (tunnel->room);
201  struct GNUNET_HashCode *key = get_room_key (tunnel->room);
202 
204  struct GNUNET_MessageHeader, NULL),
206 
207  tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, key, NULL, callback_tunnel_disconnect, handlers);
208 
209  return GNUNET_YES;
210 }
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.
struct GNUNET_HashCode * get_room_key(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
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
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
tunnelTunnel

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

References GNUNET_MESSENGER_SrvTunnel::channel, and delayed_disconnect_channel().

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

214 {
215  if (tunnel->channel)
216  {
218 
219  tunnel->channel = NULL;
220  }
221 }
void delayed_disconnect_channel(struct GNUNET_CADET_Channel *channel)
Starts an urgent task to close a CADET channel asynchronously.
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
tunnelTunnel
Returns
GNUNET_YES or GNUNET_NO

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

References GNUNET_MESSENGER_SrvTunnel::channel, GNUNET_NO, and GNUNET_YES.

Referenced by iterate_send_room_message(), and send_room_info().

225 {
226  return (tunnel->channel ? GNUNET_YES : GNUNET_NO);
227 }
struct GNUNET_CADET_Channel * channel
Here is the caller graph for this function:

◆ send_tunnel_envelope()

void send_tunnel_envelope ( struct GNUNET_MESSENGER_SrvTunnel tunnel,
void *  handle,
struct GNUNET_MQ_Envelope env,
struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

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

Parameters
tunnelTunnel
handleHandle
envEnvelope
messageMessage
hashHash of message

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

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

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

258 {
259  struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (tunnel->channel);
260 
262 
263  GNUNET_memcpy(&(sent->hash), hash, sizeof(struct GNUNET_HashCode));
264 
265  sent->tunnel = tunnel;
266 
268  GNUNET_MQ_send (mq, env);
269 
270  callback_room_sent (tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle, tunnel, message, hash);
271 }
#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
struct GNUNET_MESSENGER_SrvRoom * room
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
struct GNUNET_MESSENGER_SrvTunnel * tunnel
struct GNUNET_CADET_Channel * channel
Handle to a message queue.
Definition: mq.c:85
void callback_room_sent(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, void *cls, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
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()

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

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

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

References copy_message(), env, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, pack_room_message(), GNUNET_MESSENGER_SrvTunnel::room, and send_tunnel_envelope().

Referenced by recv_message_info(), and send_room_info().

276 {
278  message, hash,
280 
281  if (env)
282  send_tunnel_envelope (tunnel, handle, env, copy_message (message), hash);
283 }
void send_tunnel_envelope(struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MQ_Envelope *env, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Sends an envelope containing a message with a given hash through a tunnel by a given handle...
struct GNUNET_MESSENGER_SrvRoom * room
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
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
struct GNUNET_MQ_Envelope * pack_room_message(struct GNUNET_MESSENGER_SrvRoom *room, 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.
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
tunnelTunnel
messageMessage
hashHash of message

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

References copy_message(), env, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, pack_message(), and send_tunnel_envelope().

Referenced by iterate_send_member_infos(), recv_message_request(), and send_message_join().

288 {
289  struct GNUNET_MESSENGER_Message *clone = copy_message (message);
291 
292  if (env)
293  send_tunnel_envelope (tunnel, NULL, env, clone, hash);
294 }
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...
void send_tunnel_envelope(struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MQ_Envelope *env, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Sends an envelope containing a message with a given hash through a tunnel by a given handle...
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
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
tunnelTunnel
Returns
Hash of peer message or NULL

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

References GNUNET_MESSENGER_SrvTunnel::peer_message.

298 {
299  return tunnel->peer_message;
300 }