GNUnet 0.29.1-7-g14698f198
 
Loading...
Searching...
No Matches
gnunet-service-messenger_tunnel.c File Reference
Include dependency graph for gnunet-service-messenger_tunnel.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MessageSent
 

Functions

struct GNUNET_MESSENGER_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).
 
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.
 
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.
 
static enum GNUNET_GenericReturnValue verify_tunnel_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
 
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.
 
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 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.
 
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.
 
static void callback_tunnel_sent (void *cls)
 
void send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MQ_Envelope *env, const struct GNUNET_HashCode *hash)
 Sends an envelope containing a message with a given hash through a tunnel.
 
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_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_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.
 
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 42 of file gnunet-service-messenger_tunnel.c.

44{
45 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
46
47 GNUNET_assert ((room) && (door));
48
49 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new tunnel: %s\n",
50 GNUNET_i2s (door));
51
52 tunnel = GNUNET_new (struct GNUNET_MESSENGER_SrvTunnel);
53
54 tunnel->room = room;
55 tunnel->channel = NULL;
56
57 tunnel->peer = GNUNET_PEER_intern (door);
58
59 tunnel->messenger_version = 0;
60
61 tunnel->peer_message = NULL;
62
63 init_message_state (&(tunnel->state));
64
65 return tunnel;
66}
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 70 of file gnunet-service-messenger_tunnel.c.

71{
72 GNUNET_assert (tunnel);
73
74 if (tunnel->channel)
76
77 GNUNET_PEER_change_rc (tunnel->peer, -1);
78
79 if (tunnel->peer_message)
80 GNUNET_free (tunnel->peer_message);
81
82 clear_message_state (&(tunnel->state));
83
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free tunnel!\n");
85
86 GNUNET_free (tunnel);
87}
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 91 of file gnunet-service-messenger_tunnel.c.

93{
94 GNUNET_assert (tunnel);
95
96 if (tunnel->channel)
98
99 tunnel->channel = channel;
100}
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:

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

106{
107 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
108 struct GNUNET_MESSENGER_SrvRoom *room;
110
111 tunnel = cls;
112
113 if (! tunnel)
114 return;
115
116 GNUNET_assert (tunnel->room);
117
118 room = tunnel->room;
119
121
123 "Connection dropped to room (%s) from peer: %s\n",
125
126 tunnel->channel = NULL;
127
128 if (! room->host)
129 return;
130
132 &identity,
133 tunnel)) ||
135 &identity)))
136 return;
137
139 "# tunnels connected",
140 -1,
141 GNUNET_NO);
142
144 {
145 struct GNUNET_MESSENGER_Message *message;
146
147 message = create_message_miss (&identity);
148
149 if (! message)
151 "Sending miss message about tunnel failed: %s\n",
152 GNUNET_h2s (&(room->key)));
153 else
154 send_srv_room_message (room, room->host, message);
155 }
156
159 return;
160
162 "Search for alternate tunnel for room: %s\n",
164
165 {
166 struct GNUNET_MESSENGER_ListTunnel *element;
167 element = find_list_tunnels_alternate (&(room->basement), &identity);
168
169 if (! element)
170 {
172 "No alternative tunnel was found!\n");
173 return;
174 }
175
176 GNUNET_PEER_resolve (element->peer, &identity);
177 }
178
179 enter_srv_room_at (room, room->host, &identity);
180}
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.
@ GNUNET_YES
@ 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_WARNING
@ GNUNET_ERROR_TYPE_ERROR
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 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_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_STATISTICS_Handle * statistics
struct GNUNET_CONTAINER_MultiPeerMap * tunnels
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_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:

◆ verify_tunnel_message()

static enum GNUNET_GenericReturnValue verify_tunnel_message ( struct GNUNET_MESSENGER_SrvRoom *  room,
struct GNUNET_MESSENGER_Message *  message,
struct GNUNET_HashCode *  hash 
)
static

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

187{
188 const struct GNUNET_MESSENGER_Message *previous;
189
190 GNUNET_assert ((room) && (message));
191
193 {
195 "Message error: Kind is unknown! (%d)\n", message->header.kind);
196 return GNUNET_SYSERR;
197 }
198
199 {
200 struct GNUNET_MESSENGER_MessageStore *message_store;
201
202 message_store = get_srv_room_message_store (room);
203
204 previous = get_store_message (
205 message_store, &(message->header.previous));
206 }
207
208 if (! previous)
209 goto skip_time_comparison;
210
211 {
213 struct GNUNET_TIME_Absolute last;
214
216 last = GNUNET_TIME_absolute_ntoh (previous->header.timestamp);
217
218 if (GNUNET_TIME_relative_get_zero_ ().rel_value_us !=
220 {
222 "Message warning: Timestamp does not check out!\n");
223 }
224 }
225
226skip_time_comparison:
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message of kind: %s!\n",
229
230 return GNUNET_OK;
231}
static uint64_t timestamp(void)
Get current timestamp.
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.
@ GNUNET_OK
@ GNUNET_SYSERR
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition time.c:133
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition time.c:423
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
Time for absolute times used by GNUnet, in microseconds.

References get_srv_room_message_store(), get_store_message(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_MESSENGER_name_of_kind(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_get_zero_(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageHeader::timestamp, and timestamp().

Referenced by check_tunnel_message().

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

237{
238 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
239 struct GNUNET_MESSENGER_Message message;
240 struct GNUNET_HashCode hash;
241 uint16_t length;
242 const char *buffer;
243
244 GNUNET_assert (header);
245
246 tunnel = cls;
247
248 if (! tunnel)
249 return GNUNET_SYSERR;
250
251 length = ntohs (header->size) - sizeof(*header);
252 buffer = (const char*) &header[1];
253
255 GNUNET_YES))
256 {
258 "Tunnel error: Message too short! (%d)\n", length);
259 return GNUNET_SYSERR;
260 }
261
262 {
263 uint16_t padding;
264 padding = 0;
265
266 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES,
267 &padding))
268 {
270 "Tunnel error: Decoding failed!\n");
271 return GNUNET_SYSERR;
272 }
273
274 hash_message (&message, length - padding, buffer, &hash);
275 }
276
277 return verify_tunnel_message (tunnel->room, &message, &hash);
278}
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.
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:

◆ update_room_message()

enum GNUNET_GenericReturnValue update_room_message ( struct GNUNET_MESSENGER_SrvRoom *  room,
struct GNUNET_MESSENGER_Message *  message,
const struct GNUNET_HashCode *  hash 
)
extern

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

1436{
1437 struct GNUNET_MESSENGER_OperationStore *operation_store;
1438 struct GNUNET_MESSENGER_MessageStore *message_store;
1439 enum GNUNET_GenericReturnValue requested;
1440
1441 GNUNET_assert ((room) && (message) && (hash));
1442
1443 operation_store = get_srv_room_operation_store (room);
1444
1445 if (! operation_store)
1446 {
1447 destroy_message (message);
1448
1449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Operation store invalid!\n");
1450 return GNUNET_NO;
1451 }
1452
1453 requested = (GNUNET_MESSENGER_OP_REQUEST ==
1454 get_store_operation_type (operation_store, hash)?
1456
1457 if (GNUNET_YES == requested)
1458 cancel_store_operation (operation_store, hash);
1459
1460 message_store = get_srv_room_message_store (room);
1461
1462 if (! message_store)
1463 {
1464 destroy_message (message);
1465
1466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message store invalid!\n");
1467 return GNUNET_NO;
1468 }
1469
1470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle a message in room (%s).\n",
1471 GNUNET_h2s (get_srv_room_key (room)));
1472
1473 if (GNUNET_YES == contains_store_message (message_store, hash))
1474 {
1475 destroy_message (message);
1476
1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Duplicate message got dropped!\n");
1478 return GNUNET_NO;
1479 }
1480
1481 if (GNUNET_OK != put_store_message (message_store, hash, message))
1482 {
1483 destroy_message (message);
1484
1485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing message failed!\n");
1486 return GNUNET_NO;
1487 }
1488
1489 update_message_state (&(room->state), requested, message, hash);
1490
1491 if ((GNUNET_YES == requested) ||
1492 (GNUNET_MESSENGER_KIND_INFO == message->header.kind) ||
1494 return GNUNET_YES;
1495
1496 if ((GNUNET_MESSENGER_KIND_MERGE == message->header.kind) &&
1498 &(message->body.
1499 merge.previous))
1500 ))
1501 cancel_store_operation (operation_store, &(message->body.merge.previous));
1502
1504 &(message->header.
1505 previous)))
1506 cancel_store_operation (operation_store, &(message->header.previous));
1507
1508 if (! room->save_task)
1513
1514 return GNUNET_YES;
1515}
void update_message_state(struct GNUNET_MESSENGER_MessageState *state, enum GNUNET_GenericReturnValue requested, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
enum GNUNET_GenericReturnValue contains_store_message(const struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Checks if a message matching a given hash is stored in a message store.
enum GNUNET_GenericReturnValue put_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, struct GNUNET_MESSENGER_Message *message)
Stores a message into the message store.
void cancel_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
Stops any active operation under a given hash in a specific operation store.
enum GNUNET_MESSENGER_OperationType get_store_operation_type(const struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
Returns the type of the active 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.
static void autosave_room_messages(void *cls)
#define GNUNET_MESSENGER_SAVE_DELAY
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1213
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_SCHEDULER_Task * save_task
struct GNUNET_MESSENGER_MessageState state

References autosave_room_messages(), GNUNET_MESSENGER_Message::body, cancel_store_operation(), contains_store_message(), destroy_message(), get_srv_room_key(), get_srv_room_message_store(), get_srv_room_operation_store(), get_store_operation_type(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_MESSENGER_OP_MERGE, GNUNET_MESSENGER_OP_REQUEST, GNUNET_MESSENGER_SAVE_DELAY, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageHeader::previous, GNUNET_MESSENGER_MessageMerge::previous, put_store_message(), GNUNET_MESSENGER_SrvRoom::save_task, GNUNET_MESSENGER_SrvRoom::state, and update_message_state().

Referenced by callback_srv_room_message_signed(), handle_tunnel_message(), and it_handle_epoch_message_delayed().

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

◆ callback_room_handle_message()

void callback_room_handle_message ( struct GNUNET_MESSENGER_SrvRoom *  room,
const struct GNUNET_MESSENGER_Message *  message,
const struct GNUNET_HashCode *  hash 
)
extern

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

1645{
1646 struct GNUNET_MESSENGER_PeerStore *peer_store;
1647 struct GNUNET_MESSENGER_MemberStore *member_store;
1648 struct GNUNET_MESSENGER_SenderSession session;
1649 enum GNUNET_GenericReturnValue start_handle;
1650
1651 GNUNET_assert ((room) && (message) && (hash));
1652
1653 peer_store = get_srv_room_peer_store (room);
1654 member_store = get_srv_room_member_store (room);
1655
1656 if (GNUNET_YES == is_peer_message (message))
1657 {
1658 session.peer = get_store_peer_of (peer_store, message, hash);
1659
1660 if (! session.peer)
1661 {
1663 "Message handling dropped: Peer is missing!\n");
1664 return;
1665 }
1666 }
1667 else
1668 {
1669 struct GNUNET_MESSENGER_Member *member;
1670 member = get_store_member_of (member_store, message);
1671
1672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for message (%s)\n",
1673 GNUNET_h2s (hash));
1674
1675 if (! member)
1676 {
1678 "Message handling dropped: Member is missing!\n");
1679 return;
1680 }
1681
1682 session.member = get_member_session_of (member, message, hash);
1683
1684 if (! session.member)
1685 {
1687 "Message handling dropped: Session is missing!\n");
1688 return;
1689 }
1690 }
1691
1692 {
1693 struct GNUNET_MESSENGER_MemberUpdate update;
1694 update.message = message;
1695 update.hash = hash;
1696
1697 update.head = NULL;
1698 update.tail = NULL;
1699
1701 member_store,
1703 &update);
1704
1705 while (update.head)
1706 {
1707 struct GNUNET_MESSENGER_SrvMemberSessionCompletion *element = update.head;
1708
1709 remove_room_member_session (room, element->session);
1710
1711 GNUNET_CONTAINER_DLL_remove (update.head, update.tail, element);
1713 "Remove member session completion from queue!\n");
1714
1715 GNUNET_free (element);
1716 }
1717 }
1718
1719 start_handle = room->handling.head ? GNUNET_NO : GNUNET_YES;
1720
1721 add_to_list_messages (&(room->handling), hash);
1722
1723 switch (message->header.kind)
1724 {
1726 handle_message_join (room, &session, message, hash);
1727 break;
1729 handle_message_leave (room, &session, message, hash);
1730 break;
1732 handle_message_key (room, &session, message, hash);
1733 break;
1735 handle_message_peer (room, &session, message, hash);
1736 break;
1738 handle_message_id (room, &session, message, hash);
1739 break;
1741 handle_message_miss (room, &session, message, hash);
1742 break;
1744 handle_message_delete (room, &session, message, hash);
1745 break;
1747 handle_message_connection (room, &session, message, hash);
1748 break;
1750 handle_message_subscribe (room, &session, message, hash);
1751 break;
1752 default:
1753 break;
1754 }
1755
1756 if (GNUNET_YES == start_handle)
1757 handle_room_messages (room);
1758}
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
struct GNUNET_MESSENGER_SrvMemberSession * 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...
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.
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 ...
void handle_message_id(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent id message to change a members id.
void handle_message_delete(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent delete message to delete a specific message from the store.
void handle_message_peer(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent peer message to make changes of the basement in the room.
void handle_message_join(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent join message to make changes of current member information.
void handle_message_key(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent key message to change the key of a member and rearrange the contacts accor...
void handle_message_leave(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent leave message to make changes of current member information.
void handle_message_subscribe(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent subscribe message to subscribe a member to a discourse.
void handle_message_connection(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent connection message to update connection information about a peer.
void handle_message_miss(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a received or sent miss message to drop a peer from the basement in the room.
struct GNUNET_PeerIdentity * get_store_peer_of(struct GNUNET_MESSENGER_PeerStore *store, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Returns the peer identity inside the store which verifies the signature of a given message as valid.
static enum GNUNET_GenericReturnValue iterate_update_member_sessions(void *cls, const struct GNUNET_CRYPTO_BlindablePublicKey *public_key, struct GNUNET_MESSENGER_SrvMemberSession *session)
struct GNUNET_MESSENGER_PeerStore * get_srv_room_peer_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used peer store of a given room.
static void remove_room_member_session(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvMemberSession *session)
static void handle_room_messages(struct GNUNET_MESSENGER_SrvRoom *room)
struct GNUNET_MESSENGER_MemberStore * get_srv_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...
struct GNUNET_MESSENGER_ListMessage * head
const struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_SrvMemberSession * session
struct GNUNET_MESSENGER_ListMessages handling

References add_to_list_messages(), get_member_session_of(), get_srv_room_member_store(), get_srv_room_peer_store(), get_store_member_of(), get_store_peer_of(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_MESSENGER_KIND_CONNECTION, GNUNET_MESSENGER_KIND_DELETION, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_SUBSCRIBTION, GNUNET_NO, GNUNET_YES, handle_message_connection(), handle_message_delete(), handle_message_id(), handle_message_join(), handle_message_key(), handle_message_leave(), handle_message_miss(), handle_message_peer(), handle_message_subscribe(), handle_room_messages(), GNUNET_MESSENGER_SrvRoom::handling, GNUNET_MESSENGER_MemberUpdate::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_MemberUpdate::head, GNUNET_MESSENGER_Message::header, is_peer_message(), iterate_store_members(), iterate_update_member_sessions(), GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_SenderSession::member, GNUNET_MESSENGER_MemberUpdate::message, GNUNET_MESSENGER_SenderSession::peer, remove_room_member_session(), GNUNET_MESSENGER_SrvMemberSessionCompletion::session, and GNUNET_MESSENGER_MemberUpdate::tail.

Referenced by callback_srv_room_message_signed(), and handle_tunnel_message().

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

◆ update_tunnel_last_message()

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

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

294{
295 struct GNUNET_MESSENGER_OperationStore *operation_store;
296 enum GNUNET_GenericReturnValue requested;
297
298 GNUNET_assert ((tunnel) && (hash));
299
300 operation_store = get_srv_room_operation_store (tunnel->room);
301
302 requested = (GNUNET_MESSENGER_OP_REQUEST ==
303 get_store_operation_type (operation_store, hash)?
305
306 {
307 struct GNUNET_MESSENGER_MessageStore *message_store;
308 const struct GNUNET_MESSENGER_Message *message;
309
310 message_store = get_srv_room_message_store (tunnel->room);
311 message = get_store_message (message_store, hash);
312
313 if (! message)
314 return;
315
316 update_message_state (&(tunnel->state), requested, message, hash);
317 }
318}

References get_srv_room_message_store(), get_srv_room_operation_store(), get_store_message(), get_store_operation_type(), GNUNET_assert, GNUNET_MESSENGER_OP_REQUEST, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvTunnel::state, and update_message_state().

Referenced by callback_tunnel_sent(), and handle_tunnel_message().

Here is the call graph for this function:
Here is the caller 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 322 of file gnunet-service-messenger_tunnel.c.

323{
324 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
325 struct GNUNET_MESSENGER_Message message;
326 struct GNUNET_HashCode hash;
327 uint16_t length;
328 const char *buffer;
329
330 GNUNET_assert (header);
331
332 tunnel = cls;
333
334 if (! tunnel)
335 return;
336
337 length = ntohs (header->size) - sizeof(*header);
338 buffer = (const char*) &header[1];
339
340 {
341 uint16_t padding;
342 padding = 0;
343
344 decode_message (&message, length, buffer, GNUNET_YES, &padding);
345 hash_message (&message, length - padding, buffer, &hash);
346 }
347
348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n",
349 GNUNET_MESSENGER_name_of_kind (message.header.kind));
350
351 {
352 enum GNUNET_GenericReturnValue new_message;
353 new_message = update_room_message (tunnel->room,
354 copy_message (&message),
355 &hash);
356
357 if (GNUNET_YES != new_message)
358 goto receive_done;
359 }
360
361 update_tunnel_last_message (tunnel, &hash);
362
363 {
364 enum GNUNET_GenericReturnValue forward_message;
365 forward_message = GNUNET_YES;
366
367 switch (message.header.kind)
368 {
370 forward_message = recv_message_info (
371 tunnel->room,
372 tunnel,
373 &message,
374 &hash);
375 break;
377 forward_message = recv_message_peer (
378 tunnel->room,
379 tunnel,
380 &message,
381 &hash);
382 break;
384 forward_message = recv_message_miss (
385 tunnel->room,
386 tunnel,
387 &message,
388 &hash);
389 break;
391 forward_message = recv_message_request (
392 tunnel->room,
393 tunnel,
394 &message,
395 &hash);
396 break;
397 default:
398 break;
399 }
400
401 if (GNUNET_YES == forward_message)
402 {
403 struct GNUNET_MQ_Envelope *envelope;
404
405 envelope = pack_message (&message, NULL,
407
408 if (! envelope)
409 {
411 "Packing message into envelope failed: %s\n",
412 GNUNET_h2s (&hash));
413 goto receive_done;
414 }
415
416 send_srv_room_envelope (tunnel->room, tunnel, envelope, &hash);
417 callback_room_handle_message (tunnel->room, &message, &hash);
418 }
419 }
420
421receive_done:
422 cleanup_message (&message);
423
425 "# messages received",
426 1,
427 GNUNET_NO);
428
430}
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
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

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:

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

435{
436 const struct GNUNET_PeerIdentity *door;
439
440 GNUNET_assert (tunnel);
441
442 if (tunnel->channel)
443 return GNUNET_NO;
444
445 door = GNUNET_PEER_resolve2 (tunnel->peer);
446 cadet = get_srv_room_cadet (tunnel->room);
447
449 &(key.hash),
450 get_srv_room_key (tunnel->room),
451 sizeof (key.hash));
452
453 if ((key.code.feed_bit) && (! key.code.group_bit))
454 {
456 "Tunnel to personal room containing private feeds failed!");
457 return GNUNET_NO;
458 }
459
460 {
461 struct GNUNET_HashCode port;
463 tunnel_message,
465 struct
467 ,
469
471 tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, &port,
472 NULL,
474 handlers);
475 }
476
477 if (! tunnel->channel)
478 return GNUNET_SYSERR;
479
481 "# tunnels connected",
482 1,
483 GNUNET_NO);
484
485 return GNUNET_YES;
486}
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 490 of file gnunet-service-messenger_tunnel.c.

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

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

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

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:

◆ callback_tunnel_sent()

static void callback_tunnel_sent ( void *  cls)
static

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

520{
521 struct GNUNET_MESSENGER_MessageSent *sent;
522
523 GNUNET_assert (cls);
524
525 sent = cls;
526
527 if (sent->tunnel)
528 {
529 update_tunnel_last_message (sent->tunnel, &(sent->hash));
530
532 "# messages sent",
533 1,
534 GNUNET_NO);
535 }
536
537 GNUNET_free (sent);
538}
struct GNUNET_MESSENGER_SrvTunnel * tunnel

References GNUNET_assert, GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_MESSENGER_MessageSent::hash, GNUNET_MESSENGER_SrvTunnel::room, GNUNET_MESSENGER_SrvRoom::service, GNUNET_MESSENGER_Service::statistics, GNUNET_MESSENGER_MessageSent::tunnel, and update_tunnel_last_message().

Referenced by send_tunnel_envelope().

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

◆ send_tunnel_envelope()

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

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

Parameters
[in,out]tunnelTunnel
[in,out]envEnvelope
[in]hashHash of message

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

545{
546 struct GNUNET_MQ_Handle *mq;
547 struct GNUNET_MESSENGER_MessageSent *sent;
548
549 GNUNET_assert ((tunnel) && (env) && (hash));
550
553
554 GNUNET_memcpy (&(sent->hash), hash, sizeof(struct GNUNET_HashCode));
555
556 sent->tunnel = tunnel;
557
560}
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:337
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:687
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
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:

◆ callback_tunnel_message_signed()

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 
)
static

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

570{
571 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
572
573 GNUNET_assert ((cls) && (message) && (envelope) && (hash));
574
575 tunnel = cls;
576
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending tunnel message: %s\n",
578 GNUNET_h2s (hash));
579
580 destroy_message (message);
581 send_tunnel_envelope (tunnel, envelope, hash);
582}
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.

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

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

589{
590 GNUNET_assert ((tunnel) && (tunnel->room));
591
592 if (! message)
593 return GNUNET_NO;
594
596 "Sending message from tunnel in room: %s (%s)\n",
597 GNUNET_h2s (&(tunnel->room->key)),
599
600 return sign_srv_room_message (tunnel->room, message,
602 tunnel);
603}
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)

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

610{
611 struct GNUNET_MESSENGER_Message *copy;
612 struct GNUNET_MQ_Envelope *envelope;
613
614 GNUNET_assert ((tunnel) && (message) && (hash));
615
616 copy = copy_message (message);
617 envelope = pack_message (copy, NULL,
619
620 destroy_message (copy);
621
622 if (! envelope)
623 return;
624
625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarding tunnel message: %s\n",
626 GNUNET_h2s (hash));
627
628 send_tunnel_envelope (tunnel, envelope, hash);
629}

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

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

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

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

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

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

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

663{
664 GNUNET_assert (tunnel);
665
666 if (version != GNUNET_MESSENGER_VERSION)
667 return GNUNET_SYSERR;
668
669 if (version > tunnel->messenger_version)
670 tunnel->messenger_version = version;
671
672 return GNUNET_OK;
673}
#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: