GNUnet debian-0.24.3-24-gfea921bd2
gnunet-service-messenger_tunnel.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2025 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27
35
36#include "gnunet_common.h"
38#include "messenger_api_util.h"
39
42 const struct GNUNET_PeerIdentity *door)
43{
44 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
45
46 GNUNET_assert ((room) && (door));
47
48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new tunnel: %s\n",
49 GNUNET_i2s (door));
50
51 tunnel = GNUNET_new (struct GNUNET_MESSENGER_SrvTunnel);
52
53 tunnel->room = room;
54 tunnel->channel = NULL;
55
56 tunnel->peer = GNUNET_PEER_intern (door);
57
58 tunnel->messenger_version = 0;
59
60 tunnel->peer_message = NULL;
61
62 init_message_state (&(tunnel->state));
63
64 return tunnel;
65}
66
67
68void
70{
71 GNUNET_assert (tunnel);
72
73 if (tunnel->channel)
75
76 GNUNET_PEER_change_rc (tunnel->peer, -1);
77
78 if (tunnel->peer_message)
79 GNUNET_free (tunnel->peer_message);
80
81 clear_message_state (&(tunnel->state));
82
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free tunnel!\n");
84
85 GNUNET_free (tunnel);
86}
87
88
89void
92{
93 GNUNET_assert (tunnel);
94
95 if (tunnel->channel)
97
98 tunnel->channel = channel;
99}
100
101
102void
104 const struct GNUNET_CADET_Channel *channel)
105{
106 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
107 struct GNUNET_MESSENGER_SrvRoom *room;
109
110 tunnel = cls;
111
112 if (! tunnel)
113 return;
114
115 GNUNET_assert (tunnel->room);
116
117 room = tunnel->room;
118
120
122 "Connection dropped to room (%s) from peer: %s\n",
124
125 tunnel->channel = NULL;
126
127 if (! room->host)
128 return;
129
131 &identity,
132 tunnel)) ||
134 &identity)))
135 return;
136
138 "# tunnels connected",
139 -1,
140 GNUNET_NO);
141
143 {
144 struct GNUNET_MESSENGER_Message *message;
145
146 message = create_message_miss (&identity);
147
148 if (! message)
150 "Sending miss message about tunnel failed: %s\n",
151 GNUNET_h2s (&(room->key)));
152 else
153 send_srv_room_message (room, room->host, message);
154 }
155
158 return;
159
161 "Search for alternate tunnel for room: %s\n",
163
164 {
165 struct GNUNET_MESSENGER_ListTunnel *element;
166 element = find_list_tunnels_alternate (&(room->basement), &identity);
167
168 if (! element)
169 {
171 "No alternative tunnel was found!\n");
172 return;
173 }
174
175 GNUNET_PEER_resolve (element->peer, &identity);
176 }
177
178 enter_srv_room_at (room, room->host, &identity);
179}
180
181
184 struct GNUNET_MESSENGER_Message *message,
185 struct GNUNET_HashCode *hash)
186{
187 const struct GNUNET_MESSENGER_Message *previous;
188
189 GNUNET_assert ((room) && (message));
190
192 {
194 "Message error: Kind is unknown! (%d)\n", message->header.kind);
195 return GNUNET_SYSERR;
196 }
197
198 {
199 struct GNUNET_MESSENGER_MessageStore *message_store;
200
201 message_store = get_srv_room_message_store (room);
202
203 previous = get_store_message (
204 message_store, &(message->header.previous));
205 }
206
207 if (! previous)
208 goto skip_time_comparison;
209
210 {
212 struct GNUNET_TIME_Absolute last;
213
215 last = GNUNET_TIME_absolute_ntoh (previous->header.timestamp);
216
217 if (GNUNET_TIME_relative_get_zero_ ().rel_value_us !=
219 {
221 "Message warning: Timestamp does not check out!\n");
222 }
223 }
224
225skip_time_comparison:
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message of kind: %s!\n",
228
229 return GNUNET_OK;
230}
231
232
235 const struct GNUNET_MessageHeader *header)
236{
237 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
238 struct GNUNET_MESSENGER_Message message;
239 struct GNUNET_HashCode hash;
240 uint16_t length;
241 const char *buffer;
242
243 GNUNET_assert (header);
244
245 tunnel = cls;
246
247 if (! tunnel)
248 return GNUNET_SYSERR;
249
250 length = ntohs (header->size) - sizeof(*header);
251 buffer = (const char*) &header[1];
252
254 GNUNET_YES))
255 {
257 "Tunnel error: Message too short! (%d)\n", length);
258 return GNUNET_SYSERR;
259 }
260
261 {
262 uint16_t padding;
263 padding = 0;
264
265 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES,
266 &padding))
267 {
269 "Tunnel error: Decoding failed!\n");
270 return GNUNET_SYSERR;
271 }
272
273 hash_message (&message, length - padding, buffer, &hash);
274 }
275
276 return verify_tunnel_message (tunnel->room, &message, &hash);
277}
278
279
282 struct GNUNET_MESSENGER_Message *message,
283 const struct GNUNET_HashCode *hash);
284
285extern void
287 const struct GNUNET_MESSENGER_Message *message,
288 const struct GNUNET_HashCode *hash);
289
290static void
292 const struct GNUNET_HashCode *hash)
293{
294 struct GNUNET_MESSENGER_OperationStore *operation_store;
295 enum GNUNET_GenericReturnValue requested;
296
297 GNUNET_assert ((tunnel) && (hash));
298
299 operation_store = get_srv_room_operation_store (tunnel->room);
300
301 requested = (GNUNET_MESSENGER_OP_REQUEST ==
302 get_store_operation_type (operation_store, hash)?
304
305 {
306 struct GNUNET_MESSENGER_MessageStore *message_store;
307 const struct GNUNET_MESSENGER_Message *message;
308
309 message_store = get_srv_room_message_store (tunnel->room);
310 message = get_store_message (message_store, hash);
311
312 if (! message)
313 return;
314
315 update_message_state (&(tunnel->state), requested, message, hash);
316 }
317}
318
319
320void
322{
323 struct GNUNET_MESSENGER_SrvTunnel *tunnel;
324 struct GNUNET_MESSENGER_Message message;
325 struct GNUNET_HashCode hash;
326 uint16_t length;
327 const char *buffer;
328
329 GNUNET_assert (header);
330
331 tunnel = cls;
332
333 if (! tunnel)
334 return;
335
336 length = ntohs (header->size) - sizeof(*header);
337 buffer = (const char*) &header[1];
338
339 {
340 uint16_t padding;
341 padding = 0;
342
343 decode_message (&message, length, buffer, GNUNET_YES, &padding);
344 hash_message (&message, length - padding, buffer, &hash);
345 }
346
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n",
349
350 {
351 enum GNUNET_GenericReturnValue new_message;
352 new_message = update_room_message (tunnel->room,
353 copy_message (&message),
354 &hash);
355
356 if (GNUNET_YES != new_message)
357 goto receive_done;
358 }
359
360 update_tunnel_last_message (tunnel, &hash);
361
362 {
363 enum GNUNET_GenericReturnValue forward_message;
364 forward_message = GNUNET_YES;
365
366 switch (message.header.kind)
367 {
369 forward_message = recv_message_info (
370 tunnel->room,
371 tunnel,
372 &message,
373 &hash);
374 break;
376 forward_message = recv_message_peer (
377 tunnel->room,
378 tunnel,
379 &message,
380 &hash);
381 break;
383 forward_message = recv_message_miss (
384 tunnel->room,
385 tunnel,
386 &message,
387 &hash);
388 break;
390 forward_message = recv_message_request (
391 tunnel->room,
392 tunnel,
393 &message,
394 &hash);
395 break;
396 default:
397 break;
398 }
399
400 if (GNUNET_YES == forward_message)
401 {
402 forward_srv_room_message (tunnel->room, tunnel, &message, &hash);
403 callback_room_handle_message (tunnel->room, &message, &hash);
404 }
405 }
406
407receive_done:
408 cleanup_message (&message);
409
411 "# messages received",
412 1,
413 GNUNET_NO);
414
416}
417
418
421{
422 const struct GNUNET_PeerIdentity *door;
425
426 GNUNET_assert (tunnel);
427
428 if (tunnel->channel)
429 return GNUNET_NO;
430
431 door = GNUNET_PEER_resolve2 (tunnel->peer);
432 cadet = get_srv_room_cadet (tunnel->room);
433
435 &(key.hash),
436 get_srv_room_key (tunnel->room),
437 sizeof (key.hash));
438
439 if ((key.code.feed_bit) && (! key.code.group_bit))
440 {
442 "Tunnel to personal room containing private feeds failed!");
443 return GNUNET_SYSERR;
444 }
445
446 {
447 struct GNUNET_HashCode port;
449 tunnel_message,
451 struct
453 ,
455
457 tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, &port,
458 NULL,
460 handlers);
461 }
462
463 if (! tunnel->channel)
464 return GNUNET_SYSERR;
465
467 "# tunnels connected",
468 1,
469 GNUNET_NO);
470
471 return GNUNET_YES;
472}
473
474
475void
477{
478 GNUNET_assert (tunnel);
479
480 if (tunnel->channel)
481 {
483
484 tunnel->channel = NULL;
485 }
486}
487
488
491{
492 GNUNET_assert (tunnel);
493
494 return (tunnel->channel ? GNUNET_YES : GNUNET_NO);
495}
496
497
499{
502};
503
504static void
506{
507 struct GNUNET_MESSENGER_MessageSent *sent;
508
509 GNUNET_assert (cls);
510
511 sent = cls;
512
513 if (sent->tunnel)
514 {
515 update_tunnel_last_message (sent->tunnel, &(sent->hash));
516
518 "# messages sent",
519 1,
520 GNUNET_NO);
521 }
522
523 GNUNET_free (sent);
524}
525
526
527void
529 struct GNUNET_MQ_Envelope *env,
530 const struct GNUNET_HashCode *hash)
531{
532 struct GNUNET_MQ_Handle *mq;
533 struct GNUNET_MESSENGER_MessageSent *sent;
534
535 GNUNET_assert ((tunnel) && (env) && (hash));
536
539
540 GNUNET_memcpy (&(sent->hash), hash, sizeof(struct GNUNET_HashCode));
541
542 sent->tunnel = tunnel;
543
546}
547
548
551 GNUNET_UNUSED void *handle,
552 struct GNUNET_MESSENGER_Message *message)
553{
554 struct GNUNET_HashCode hash;
555 struct GNUNET_MQ_Envelope *env;
556
557 GNUNET_assert (tunnel);
558
559 if (! message)
560 return GNUNET_NO;
561
563 tunnel->room,
564 message,
565 &hash,
567
568 destroy_message (message);
569
570 if (! env)
571 return GNUNET_NO;
572
573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending tunnel message: %s\n",
574 GNUNET_h2s (&hash));
575
576 send_tunnel_envelope (tunnel, env, &hash);
577 return GNUNET_YES;
578}
579
580
581void
583 const struct GNUNET_MESSENGER_Message *message,
584 const struct GNUNET_HashCode *hash)
585{
586 struct GNUNET_MESSENGER_Message *copy;
587 struct GNUNET_MQ_Envelope *env;
588
589 GNUNET_assert ((tunnel) && (message) && (hash));
590
591 copy = copy_message (message);
593 NULL);
594
595 destroy_message (copy);
596
597 if (! env)
598 return;
599
600 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarding tunnel message: %s\n",
601 GNUNET_h2s (hash));
602
603 send_tunnel_envelope (tunnel, env, hash);
604}
605
606
607const struct GNUNET_HashCode*
609{
610 GNUNET_assert (tunnel);
611
612 return tunnel->peer_message;
613}
614
615
616void
618 struct GNUNET_PeerIdentity *peer)
619{
620 GNUNET_assert (tunnel);
621
622 GNUNET_PEER_resolve (tunnel->peer, peer);
623}
624
625
626uint32_t
628{
629 GNUNET_assert (tunnel);
630
631 return tunnel->messenger_version;
632}
633
634
637 uint32_t version)
638{
639 GNUNET_assert (tunnel);
640
641 if (version != GNUNET_MESSENGER_VERSION)
642 return GNUNET_SYSERR;
643
644 if (version > tunnel->messenger_version)
645 tunnel->messenger_version = version;
646
647 return GNUNET_OK;
648}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
static uint64_t timestamp(void)
Get current timestamp.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static struct GNUNET_CADET_Handle * cadet
Handle for cadet.
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 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 clear_message_state(struct GNUNET_MESSENGER_MessageState *state)
void init_message_state(struct GNUNET_MESSENGER_MessageState *state)
void update_message_state(struct GNUNET_MESSENGER_MessageState *state, enum GNUNET_GenericReturnValue requested, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
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.
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_MessageStore * get_srv_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
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...
void forward_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Forwards a message with a given hash to a specific tunnel inside of a room.
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.
struct GNUNET_MESSENGER_OperationStore * get_srv_room_operation_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used operation store of a given room.
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.
struct GNUNET_MQ_Envelope * pack_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, 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 forward_tunnel_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Forwards a given message with a known hash through a tunnel.
enum GNUNET_GenericReturnValue update_tunnel_messenger_version(struct GNUNET_MESSENGER_SrvTunnel *tunnel, uint32_t version)
Updates the messenger version of the tunnel to a given version if it is compatible to the running pee...
enum GNUNET_GenericReturnValue update_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
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.
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...
enum GNUNET_GenericReturnValue is_tunnel_connected(const struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Returns the status of a currently bound channel of a tunnel.
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 chann...
static void callback_tunnel_sent(void *cls)
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 necess...
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 ...
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 c...
void get_tunnel_peer_identity(const struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_PeerIdentity *peer)
Writes the peer identity of the peer connected via tunnel to this peer into the peer parameter.
void callback_room_handle_message(struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
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_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 disconnect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Disconnects and unbinds a channel from a tunnel.
static enum GNUNET_GenericReturnValue verify_tunnel_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash)
enum GNUNET_GenericReturnValue connect_tunnel(struct GNUNET_MESSENGER_SrvTunnel *tunnel)
Tries to connect a tunnel by creating a new CADET channel and binding it.
static void update_tunnel_last_message(struct GNUNET_MESSENGER_SrvTunnel *tunnel, 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.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
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
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:833
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
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
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.
#define GNUNET_log(kind,...)
#define GNUNET_UNUSED
gcc-ism to document unused arguments
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
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.
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
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:46
#define GNUNET_MESSENGER_VERSION
Version number of GNUnet Messenger API.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:655
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:192
const struct GNUNET_PeerIdentity * GNUNET_PEER_resolve2(GNUNET_PEER_Id id)
Convert an interned PID to a normal peer identity.
Definition: peer.c:234
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
GNUNET_PEER_Id GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
Intern an peer identity.
Definition: peer.c:108
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
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_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:741
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_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...
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
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.
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...
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
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 maximal length in bytes.
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
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...
void delayed_disconnect_channel(struct GNUNET_CADET_Channel *channel)
Starts an urgent task to close a CADET channel asynchronously.
Opaque handle to a channel.
Definition: cadet.h:116
Opaque handle to the service.
Definition: cadet_api.c:39
A 512-bit hashcode.
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_SrvTunnel * tunnel
struct GNUNET_MESSENGER_MessageHeader header
Header.
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
struct GNUNET_CADET_Channel * channel
struct GNUNET_MESSENGER_MessageState state
struct GNUNET_MESSENGER_SrvRoom * room
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.
A room key unifies a room key code and its 512bit hash representation.