GNUnet 0.22.2
cadet_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011, 2017 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 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_constants.h"
30#include "cadet.h"
31#include "cadet_protocol.h"
32
33#define LOG(kind, ...) GNUNET_log_from (kind, "cadet-api", __VA_ARGS__)
34
39{
44
49
54
59
64
69
74};
75
80{
85
90
94 void *cls;
95
100
105
110
115
120};
121
122
130static struct GNUNET_CADET_Port *
132 const struct GNUNET_HashCode *hash)
133{
134 return GNUNET_CONTAINER_multihashmap_get (h->ports, hash);
135}
136
137
145static struct GNUNET_CADET_Channel *
148{
149 return GNUNET_CONTAINER_multihashmap32_get (h->channels,
150 ntohl (ccn.channel_of_client));
151}
152
153
161static struct GNUNET_CADET_Channel *
163 const struct GNUNET_CADET_ClientChannelNumber *ccnp)
164{
165 struct GNUNET_CADET_Channel *ch;
167
169 ch->cadet = h;
170 if (NULL == ccnp)
171 {
172 while (NULL != find_channel (h, h->next_ccn))
173 h->next_ccn.channel_of_client =
175 | (1 + ntohl (h->next_ccn.channel_of_client)));
176 ccn = h->next_ccn;
177 }
178 else
179 {
180 ccn = *ccnp;
181 }
182 ch->ccn = ccn;
185 h->channels,
186 ntohl (ch->ccn.channel_of_client),
187 ch,
189 return ch;
190}
191
192
202static void
204{
205 struct GNUNET_CADET_Handle *h = ch->cadet;
206
208 "Destroying channel %X of %p\n",
209 htonl (ch->ccn.channel_of_client),
210 h);
212 GNUNET_YES ==
214 ntohl (ch->ccn.channel_of_client),
215 ch));
216 if (NULL != ch->mq_cont)
217 {
219 ch->mq_cont = NULL;
220 }
221 /* signal channel destruction */
222 if (NULL != ch->disconnects)
223 ch->disconnects (ch->ctx, ch);
224 if (NULL != ch->pending_env)
227 GNUNET_free (ch);
228}
229
230
237static void
239
240
250static int
251open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
252{
253 struct GNUNET_CADET_Handle *h = cls;
254 struct GNUNET_CADET_Port *port = value;
256 struct GNUNET_MQ_Envelope *env;
257
258 (void) id;
260 msg->port = port->id;
262 return GNUNET_OK;
263}
264
265
272static void
273reconnect_cbk (void *cls)
274{
275 struct GNUNET_CADET_Handle *h = cls;
276
277 h->reconnect_task = NULL;
278 h->reconnect_time = GNUNET_TIME_STD_BACKOFF (h->reconnect_time);
279 reconnect (h);
281}
282
283
289static void
291{
292 if (NULL != ch->window_changes)
294 ch, /* FIXME: remove 'ch'? */
295 ch->allow_send);
296}
297
298
304static void
306{
307 struct GNUNET_CADET_Channel *ch = cls;
309
310 ch->mq_cont = NULL;
311 if (0 == ch->allow_send)
312 {
313 /* how did we get here? */
314 GNUNET_break (0);
315 return;
316 }
317 if (NULL == env)
318 {
319 /* how did we get here? */
320 GNUNET_break (0);
321 return;
322 }
323 ch->allow_send--;
324 ch->pending_env = NULL;
326 "Sending message on channel %s to CADET, new window size is %u\n",
327 GNUNET_i2s (&ch->peer),
328 ch->allow_send);
331}
332
333
346static void
348 const struct GNUNET_MessageHeader *msg,
349 void *impl_state)
350{
351 struct GNUNET_CADET_Channel *ch = impl_state;
352 struct GNUNET_CADET_Handle *h = ch->cadet;
353 uint16_t msize;
354 struct GNUNET_MQ_Envelope *orig_env;
355 struct GNUNET_MQ_Envelope *env;
356 struct GNUNET_CADET_LocalData *cadet_msg;
358
359 if (NULL == h->mq)
360 {
361 /* We're currently reconnecting, pretend this worked */
363 return;
364 }
366 pp = GNUNET_MQ_env_get_options (orig_env);
367
368 /* check message size for sanity */
369 msize = ntohs (msg->size);
371 {
372 GNUNET_break (0);
374 return;
375 }
376 env = GNUNET_MQ_msg_nested_mh (cadet_msg,
378 msg);
379 cadet_msg->ccn = ch->ccn;
380 cadet_msg->pp = htonl ((uint32_t) pp);
381 GNUNET_assert (NULL == ch->pending_env);
382 ch->pending_env = env;
383 if (0 < ch->allow_send)
385}
386
387
395static void
396cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
397{
398 struct GNUNET_CADET_Channel *ch = impl_state;
399
400 GNUNET_assert (mq == ch->mq);
401 ch->mq = NULL;
402}
403
404
413static void
415{
416 struct GNUNET_CADET_Channel *ch = cls;
417
418 if (GNUNET_MQ_ERROR_NO_MATCH == error)
419 {
420 /* Got a message we did not understand, still try to continue! */
421 GNUNET_break_op (0);
423 }
424 else
425 {
427 "MQ error in communication with CADET: %d\n",
428 error);
429 if (NULL != ch->disconnects)
430 ch->disconnects (ch->ctx, ch);
432 }
433}
434
435
443static void
444cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
445{
446 struct GNUNET_CADET_Channel *ch = impl_state;
447
448 (void) mq;
449 GNUNET_assert (NULL != ch->pending_env);
451 ch->pending_env = NULL;
452 if (NULL != ch->mq_cont)
453 {
455 ch->mq_cont = NULL;
456 }
457}
458
459
466static void
468 void *cls,
470{
471 struct GNUNET_CADET_Handle *h = cls;
472 struct GNUNET_CADET_Channel *ch;
473 struct GNUNET_CADET_Port *port;
474 const struct GNUNET_HashCode *port_number;
476
477 ccn = msg->ccn;
478 port_number = &msg->port;
480 {
481 GNUNET_break (0);
482 return;
483 }
484 port = find_port (h, port_number);
485 if (NULL == port)
486 {
487 /* We could have closed the port but the service didn't know about it yet
488 * This is not an error.
489 */
491 struct GNUNET_MQ_Envelope *env;
492
494 "No handler for incoming channel %X (on port %s, recently closed?)\n",
495 ntohl (ccn.channel_of_client),
496 GNUNET_h2s (port_number));
497 env =
499 d_msg->ccn = msg->ccn;
501 return;
502 }
503
504 ch = create_channel (h, &ccn);
505 ch->peer = msg->peer;
508 "Creating incoming channel %X [%s] %p\n",
509 ntohl (ccn.channel_of_client),
510 GNUNET_h2s (port_number),
511 ch);
512
513 GNUNET_assert (NULL != port->connects);
514 ch->window_changes = port->window_changes;
515 ch->disconnects = port->disconnects;
519 ch,
520 port->handlers,
522 ch);
523 ch->ctx = port->connects (port->cls, ch, &msg->peer);
525}
526
527
534static void
536 void *cls,
538{
539 struct GNUNET_CADET_Handle *h = cls;
540 struct GNUNET_CADET_Channel *ch;
541
542 ch = find_channel (h, msg->ccn);
543 if (NULL == ch)
544 {
546 "Received channel destroy for unknown channel %X from CADET service (recently close?)\n",
547 ntohl (msg->ccn.channel_of_client));
548 return;
549 }
551 "Received channel destroy for channel %X from CADET service\n",
552 ntohl (msg->ccn.channel_of_client));
554}
555
556
565static int
567 const struct GNUNET_CADET_LocalData *message)
568{
569 uint16_t size;
570
571 (void) cls;
572 size = ntohs (message->header.size);
573 if (sizeof(*message) + sizeof(struct GNUNET_MessageHeader) > size)
574 {
575 GNUNET_break (0);
576 return GNUNET_SYSERR;
577 }
578 return GNUNET_OK;
579}
580
581
588static void
590 const struct GNUNET_CADET_LocalData *message)
591{
592 struct GNUNET_CADET_Handle *h = cls;
593 const struct GNUNET_MessageHeader *payload;
594 struct GNUNET_CADET_Channel *ch;
595 uint16_t type;
596 int fwd;
597
598 ch = find_channel (h, message->ccn);
599 if (NULL == ch)
600 {
602 "Unknown channel %X for incoming data (recently closed?)\n",
603 ntohl (message->ccn.channel_of_client));
604 return;
605 }
606
607 payload = (const struct GNUNET_MessageHeader *) &message[1];
608 type = ntohs (payload->type);
611 "Got a %s data on channel %s [%X] of type %u\n",
612 fwd ? "FWD" : "BWD",
613 GNUNET_i2s (&ch->peer),
614 ntohl (message->ccn.channel_of_client),
615 type);
617}
618
619
627static void
629 const struct GNUNET_CADET_LocalAck *message)
630{
631 struct GNUNET_CADET_Handle *h = cls;
632 struct GNUNET_CADET_Channel *ch;
633
634 ch = find_channel (h, message->ccn);
635 if (NULL == ch)
636 {
638 "ACK on unknown channel %X\n",
639 ntohl (message->ccn.channel_of_client));
640 return;
641 }
642 ch->allow_send++;
644 "Got an ACK on mq channel %X (peer %s); new window size is %u!\n",
645 ntohl (ch->ccn.channel_of_client),
646 GNUNET_i2s (&ch->peer),
647 ch->allow_send);
648 if (NULL == ch->pending_env)
649 {
651 "Got an ACK on mq channel %X, allow send now %u!\n",
652 ntohl (ch->ccn.channel_of_client),
653 ch->allow_send);
655 return;
656 }
657 if (NULL != ch->mq_cont)
658 return; /* already working on it! */
660}
661
662
672static int
673destroy_channel_cb (void *cls, uint32_t cid, void *value)
674{
675 /* struct GNUNET_CADET_Handle *handle = cls; */
676 struct GNUNET_CADET_Channel *ch = value;
677
678 (void) cls;
679 (void) cid;
681 "Destroying channel due to GNUNET_CADET_disconnect()\n");
683 return GNUNET_OK;
684}
685
686
695static void
696handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
697{
698 struct GNUNET_CADET_Handle *h = cls;
699
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
703 h->mq = NULL;
704 GNUNET_assert (NULL == h->reconnect_task);
706 GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
707}
708
709
716static void
718{
720 { GNUNET_MQ_hd_fixed_size (channel_created,
723 h),
727 h),
728 GNUNET_MQ_hd_var_size (local_data,
731 h),
732 GNUNET_MQ_hd_fixed_size (local_ack,
735 h),
737
738 GNUNET_assert (NULL == h->mq);
739 h->mq =
741}
742
743
753static int
754destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
755{
756 /* struct GNUNET_CADET_Handle *handle = cls; */
757 struct GNUNET_CADET_Port *port = value;
758
759 (void) cls;
760 (void) id;
761 /* This is a warning, the app should have cleanly closed all open ports */
762 GNUNET_break (0);
764 return GNUNET_OK;
765}
766
767
776void
778{
781 handle);
783 handle->ports = NULL;
786 handle);
788 handle->channels = NULL;
789 if (NULL != handle->mq)
790 {
792 handle->mq = NULL;
793 }
794 if (NULL != handle->reconnect_task)
795 {
796 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
797 handle->reconnect_task = NULL;
798 }
800}
801
802
803void
805{
807 GNUNET_YES ==
808 GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports, &p->id, p));
809 if (NULL != p->cadet->mq)
810 {
812 struct GNUNET_MQ_Envelope *env;
813
815 msg->port = p->id;
816 GNUNET_MQ_send (p->cadet->mq, env);
817 }
818 GNUNET_free (p->handlers);
819 GNUNET_free (p);
820}
821
822
832void
834{
835 struct GNUNET_CADET_Handle *h = channel->cadet;
837 struct GNUNET_MQ_Envelope *env;
838
839 if (NULL != h->mq)
840 {
842 msg->ccn = channel->ccn;
844 }
846 "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
847 channel->disconnects = NULL;
848 destroy_channel (channel);
849}
850
851
852const union GNUNET_CADET_ChannelInfo *
855 ...)
856{
857 switch (option)
858 {
860 return (const union GNUNET_CADET_ChannelInfo *) &channel->peer;
861
862 default:
863 GNUNET_break (0);
864 return NULL;
865 }
866}
867
868
874void
876{
878 struct GNUNET_MQ_Envelope *env;
879
882 "Sending ACK on channel %X\n",
883 ntohl (channel->ccn.channel_of_client));
884 msg->ccn = channel->ccn;
885 GNUNET_MQ_send (channel->cadet->mq, env);
886}
887
888
896struct GNUNET_CADET_Handle *
898{
899 struct GNUNET_CADET_Handle *h;
900
901 LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n");
903 h->cfg = cfg;
906 reconnect (h);
907 if (NULL == h->mq)
908 {
909 GNUNET_break (0);
911 return NULL;
912 }
913 h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
914 return h;
915}
916
917
924static void
925return_agpl (void *cls,
926 const struct GNUNET_MessageHeader *msg)
927{
928 struct GNUNET_SERVICE_Client *client = cls;
929 struct GNUNET_MQ_Handle *mq;
930 struct GNUNET_MQ_Envelope *env;
932 size_t slen;
933 /* FIXME: this is a bug, uses always GNUnet PD while we would
934 actually WANT to use the PD of the CADET application here! */
935 const struct GNUNET_OS_ProjectData *pd =
937
938 (void) msg;
939 slen = strlen (pd->agpl_url) + 1;
942 slen);
943 memcpy (&res[1],
944 pd->agpl_url,
945 slen);
948 env);
950}
951
952
965struct GNUNET_CADET_Port *
967 const struct GNUNET_HashCode *port,
969 void *connects_cls,
973{
974 struct GNUNET_CADET_Port *p;
975 /* FIXME: this is a bug, uses always GNUnet PD while we would
976 actually WANT to use the PD of the CADET application here! */
977 const struct GNUNET_OS_ProjectData *pd =
979
980 GNUNET_assert (NULL != connects);
981 GNUNET_assert (NULL != disconnects);
983 "Listening to CADET port %s\n",
984 GNUNET_h2s (port));
985
986 p = GNUNET_new (struct GNUNET_CADET_Port);
987 p->cadet = h;
988 p->id = *port;
990 h->ports,
991 &p->id,
992 p,
994 {
995 GNUNET_free (p);
996 return NULL;
997 }
998 p->connects = connects;
999 p->cls = connects_cls;
1000 p->window_changes = window_changes;
1001 p->disconnects = disconnects;
1002 p->handlers = (NULL == pd->agpl_url)
1005
1006 GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p));
1007 return p;
1008}
1009
1010
1029struct GNUNET_CADET_Channel *
1031 void *channel_cls,
1032 const struct GNUNET_PeerIdentity *destination,
1033 const struct GNUNET_HashCode *port,
1036 const struct GNUNET_MQ_MessageHandler *handlers)
1037{
1038 struct GNUNET_CADET_Channel *ch;
1040 struct GNUNET_MQ_Envelope *env;
1041
1042 GNUNET_assert (NULL != disconnects);
1044 "Creating channel to peer %s at port %s\n",
1045 GNUNET_i2s (destination),
1046 GNUNET_h2s (port));
1047 ch = create_channel (h, NULL);
1048 ch->ctx = channel_cls;
1049 ch->peer = *destination;
1050 ch->window_changes = window_changes;
1052
1053 /* Create MQ for channel */
1057 ch,
1058 handlers,
1060 ch);
1061 GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls);
1062
1063 /* Request channel creation to service */
1065 msg->ccn = ch->ccn;
1066 msg->port = *port;
1067 msg->peer = *destination;
1068 GNUNET_MQ_send (h->mq, env);
1069 return ch;
1070}
1071
1072
1080struct GNUNET_MQ_Handle *
1082{
1083 return channel->mq;
1084}
1085
1086
1087/* end of cadet_api.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void * connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Definition: 010.c:2
void disconnects(void *cls, const struct GNUNET_PeerIdentity *peer)
Definition: 011.c:2
#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI
Minimum value for channel IDs of local clients.
Definition: cadet.h:70
static void notify_window_size(struct GNUNET_CADET_Channel *ch)
Notify the application about a change in the window size (if needed).
Definition: cadet_api.c:290
static void reconnect_cbk(void *cls)
Reconnect callback: tries to reconnect again after a failed previous connection.
Definition: cadet_api.c:273
static void cadet_mq_send_impl(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Implement sending functionality of a message queue for us sending messages to a peer.
Definition: cadet_api.c:347
static void handle_channel_destroy(void *cls, const struct GNUNET_CADET_LocalChannelDestroyMessage *msg)
Process the channel destroy notification and free associated resources.
Definition: cadet_api.c:535
static void return_agpl(void *cls, const struct GNUNET_MessageHeader *msg)
Function to return link to AGPL source upon request.
Definition: cadet_api.c:925
static void cadet_mq_send_now(void *cls)
Transmit the next message from our queue.
Definition: cadet_api.c:305
static void cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
Definition: cadet_api.c:396
static void destroy_channel(struct GNUNET_CADET_Channel *ch)
Destroy the specified channel.
Definition: cadet_api.c:203
static void cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
Definition: cadet_api.c:444
static void handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
Process the incoming data packets, call appropriate handlers.
Definition: cadet_api.c:589
static void cadet_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We had an error processing a message we forwarded from a peer to the CADET service.
Definition: cadet_api.c:414
static int destroy_channel_cb(void *cls, uint32_t cid, void *value)
Function called during GNUNET_CADET_disconnect() to destroy all channels that are still open.
Definition: cadet_api.c:673
static void handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message)
Process a local ACK message, enabling the client to send more data to the service.
Definition: cadet_api.c:628
static struct GNUNET_CADET_Channel * create_channel(struct GNUNET_CADET_Handle *h, const struct GNUNET_CADET_ClientChannelNumber *ccnp)
Create a new channel and insert it in the channel list of the cadet handle.
Definition: cadet_api.c:162
static struct GNUNET_CADET_Port * find_port(const struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *hash)
Find the Port struct for a hash.
Definition: cadet_api.c:131
static void reconnect(struct GNUNET_CADET_Handle *h)
Reconnect to the service, retransmit all information to try to restore the original state.
Definition: cadet_api.c:717
#define LOG(kind,...)
Definition: cadet_api.c:33
static int check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
Check that message received from CADET service is well-formed.
Definition: cadet_api.c:566
static int open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
Function called during reconnect_cbk() to (re)open all ports that are still open.
Definition: cadet_api.c:251
static void handle_channel_created(void *cls, const struct GNUNET_CADET_LocalChannelCreateMessage *msg)
Process the new channel notification and add it to the channels in the handle.
Definition: cadet_api.c:467
static struct GNUNET_CADET_Channel * find_channel(struct GNUNET_CADET_Handle *h, struct GNUNET_CADET_ClientChannelNumber ccn)
Get the channel handler for the channel specified by id from the given handle.
Definition: cadet_api.c:146
static int destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
Function called during GNUNET_CADET_disconnect() to destroy all ports that are still open.
Definition: cadet_api.c:754
static void handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: cadet_api.c:696
P2P messages used by CADET.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static char * res
Currently read line or NULL on EOF.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static void channel_destroy(struct CadetChannel *ch)
Destroy the given channel.
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
CADET service; establish channels to distant peers.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:897
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
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 peer.
Definition: cadet_api.c:1081
void(* GNUNET_CADET_DisconnectEventHandler)(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever an MQ-channel is destroyed, unless the destruction was requested by GNUNET_C...
GNUNET_CADET_ChannelInfoOption
struct GNUNET_CADET_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incoming MQ-based channels.
Definition: cadet_api.c:966
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:777
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port.
Definition: cadet_api.c:804
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
const union GNUNET_CADET_ChannelInfo * GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel, enum GNUNET_CADET_ChannelInfoOption option,...)
Get information about a channel.
Definition: cadet_api.c:853
void *(* GNUNET_CADET_ConnectEventHandler)(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source)
Method called whenever a peer connects to a port in MQ-based CADET.
void(* GNUNET_CADET_WindowSizeEventHandler)(void *cls, const struct GNUNET_CADET_Channel *channel, int window_size)
Function called whenever an MQ-channel's transmission window size changes.
@ GNUNET_CADET_OPTION_PEER
Who is the peer at the other end of the channel.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
#define GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE
Maximum message size that can be sent on CADET.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
void * GNUNET_CONTAINER_multihashmap32_get(const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MultiHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
void * cls
Closure for mv and cb.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:482
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.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers2(const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_MessageCallback agpl_handler, void *agpl_cls)
Copy an array of handlers, appending AGPL handler.
Definition: mq.c:992
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:974
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:437
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
Definition: mq.c:187
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition: mq.c:856
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq, void *handlers_cls)
Change the closure argument in all of the handlers of the mq.
Definition: mq.c:506
struct GNUNET_MQ_Envelope * GNUNET_MQ_get_current_envelope(struct GNUNET_MQ_Handle *mq)
Function to obtain the current envelope from within GNUNET_MQ_SendImpl implementations.
Definition: mq.c:830
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
@ GNUNET_MQ_ERROR_NO_MATCH
We received a message for which we have no matching handler.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
Ask the cadet service to create a new channel.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
Local ACK for data.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
Stop listening on a port.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
Start listening on a port.
#define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL
Source code link.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
Payload client <-> service.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
Tell client that a channel was destroyed.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2500
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2389
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static unsigned int size
Size of the "table".
Definition: peer.c:68
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
Opaque handle to a channel.
Definition: cadet.h:116
void * ctx
Any data the caller wants to put in here, used for the various callbacks (disconnects,...
Definition: cadet.h:137
struct GNUNET_CADET_Handle * cadet
Handle to the cadet this channel belongs to.
Definition: cadet.h:126
unsigned int allow_send
How many messages are we allowed to send to the service right now?
Definition: cadet.h:174
struct GNUNET_SCHEDULER_Task * mq_cont
Task to allow mq to send more traffic.
Definition: cadet.h:147
struct GNUNET_PeerIdentity peer
Other end of the channel.
Definition: cadet.h:121
GNUNET_CADET_WindowSizeEventHandler window_changes
Window change handler.
Definition: cadet.h:159
struct GNUNET_CADET_ClientChannelNumber ccn
Local ID of the channel, GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
Definition: cadet.h:169
GNUNET_CADET_DisconnectEventHandler disconnects
Disconnect handler.
Definition: cadet.h:164
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet.h:142
struct GNUNET_MQ_Envelope * pending_env
Pending envelope with a message to be transmitted to the service as soon as we are allowed to.
Definition: cadet.h:154
struct GNUNET_CADET_Port * incoming_port
Channel's port, if incoming.
Definition: cadet.h:131
Number uniquely identifying a channel of a client.
Definition: cadet.h:101
uint32_t channel_of_client
Values for channel numbering.
Definition: cadet.h:109
Opaque handle to the service.
Definition: cadet_api.c:39
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for trying to reconnect.
Definition: cadet_api.c:68
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration given by the client, in case of reconnection.
Definition: cadet_api.c:63
struct GNUNET_CADET_ClientChannelNumber next_ccn
child of the next channel to create (to avoid reusing IDs often)
Definition: cadet_api.c:58
struct GNUNET_CONTAINER_MultiHashMap * ports
Ports open.
Definition: cadet_api.c:48
struct GNUNET_TIME_Relative reconnect_time
Time to the next reconnect in case one reconnect fails.
Definition: cadet_api.c:73
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: cadet_api.c:43
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels open.
Definition: cadet_api.c:53
Message to allow the client send more data to the service (always service -> client).
Definition: cadet.h:280
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel allowed to send more data.
Definition: cadet.h:289
Message for a client to create channels.
Definition: cadet.h:201
Message for or to a client to destroy tunnel.
Definition: cadet.h:235
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:244
Message for cadet data traffic.
Definition: cadet.h:252
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel.
Definition: cadet.h:261
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA.
Definition: cadet.h:256
uint32_t pp
Priority and preferences (an enum GNUNET_MQ_PriorityPreferences) of the message in NBO.
Definition: cadet.h:267
Message for a client to create and destroy channels.
Definition: cadet.h:181
Opaque handle to a port.
Definition: cadet_api.c:80
GNUNET_CADET_DisconnectEventHandler disconnects
Handler called when an incoming channel is destroyed.
Definition: cadet_api.c:114
void * cls
Closure for handler.
Definition: cadet_api.c:94
struct GNUNET_MQ_MessageHandler * handlers
Payload handlers for incoming channels.
Definition: cadet_api.c:119
struct GNUNET_HashCode id
Port "number".
Definition: cadet_api.c:84
GNUNET_CADET_WindowSizeEventHandler window_changes
Window size change handler.
Definition: cadet_api.c:109
void * connects_cls
Closure for connects.
Definition: cadet_api.c:104
struct GNUNET_CADET_Handle * cadet
Handle to the CADET session this port belongs to.
Definition: cadet_api.c:89
GNUNET_CADET_ConnectEventHandler connects
Handler for incoming channels on this port.
Definition: cadet_api.c:99
Internal representation of the hash map.
Internal representation of the hash map.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
Project-specific data used to help the OS subsystem find installation paths.
const char * agpl_url
URL pointing to the source code of the application.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:136
Handle to a client that is connected to a service.
Definition: service.c:249
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44
Union to retrieve info about a channel.