GNUnet  0.10.x
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"
29 #include "gnunet_cadet_service.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 
76 
81 {
82 
87 
92 
97 
102  void *ctx;
103 
108 
113 
120 
125 
130 
135 
140 
144  unsigned int allow_send;
145 };
146 
147 
152 {
153 
158 
163 
167  void *cls;
168 
173 
178 
183 
188 
193 };
194 
195 
203 static struct GNUNET_CADET_Port *
205  const struct GNUNET_HashCode *hash)
206 {
207  return GNUNET_CONTAINER_multihashmap_get (h->ports, hash);
208 }
209 
210 
218 static struct GNUNET_CADET_Channel *
221 {
223  ntohl (ccn.channel_of_client));
224 }
225 
226 
234 static struct GNUNET_CADET_Channel *
236  const struct GNUNET_CADET_ClientChannelNumber *ccnp)
237 {
238  struct GNUNET_CADET_Channel *ch;
240 
241  ch = GNUNET_new (struct GNUNET_CADET_Channel);
242  ch->cadet = h;
243  if (NULL == ccnp)
244  {
245  while (NULL != find_channel (h, h->next_ccn))
248  (1 + ntohl (h->next_ccn.channel_of_client)));
249  ccn = h->next_ccn;
250  }
251  else
252  {
253  ccn = *ccnp;
254  }
255  ch->ccn = ccn;
258  h->channels,
259  ntohl (ch->ccn.channel_of_client),
260  ch,
262  return ch;
263 }
264 
265 
276 static void
278 {
279  struct GNUNET_CADET_Handle *h = ch->cadet;
280 
282  "Destroying channel %X of %p\n",
283  htonl (ch->ccn.channel_of_client),
284  h);
285  GNUNET_assert (
286  GNUNET_YES ==
288  ntohl (ch->ccn.channel_of_client),
289  ch));
290  if (NULL != ch->mq_cont)
291  {
293  ch->mq_cont = NULL;
294  }
295  /* signal channel destruction */
296  if (NULL != ch->disconnects)
297  ch->disconnects (ch->ctx, ch);
298  if (NULL != ch->pending_env)
300  GNUNET_MQ_destroy (ch->mq);
301  GNUNET_free (ch);
302 }
303 
304 
311 static void
313 
314 
324 static int
325 open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
326 {
327  struct GNUNET_CADET_Handle *h = cls;
328  struct GNUNET_CADET_Port *port = value;
330  struct GNUNET_MQ_Envelope *env;
331 
332  (void) id;
334  msg->port = port->id;
335  GNUNET_MQ_send (h->mq, env);
336  return GNUNET_OK;
337 }
338 
339 
346 static void
347 reconnect_cbk (void *cls)
348 {
349  struct GNUNET_CADET_Handle *h = cls;
350 
351  h->reconnect_task = NULL;
353  reconnect (h);
355 }
356 
357 
363 static void
365 {
366  if (NULL != ch->window_changes)
367  ch->window_changes (ch->ctx,
368  ch, /* FIXME: remove 'ch'? */
369  ch->allow_send);
370 }
371 
372 
378 static void
379 cadet_mq_send_now (void *cls)
380 {
381  struct GNUNET_CADET_Channel *ch = cls;
382  struct GNUNET_MQ_Envelope *env = ch->pending_env;
383 
384  ch->mq_cont = NULL;
385  if (0 == ch->allow_send)
386  {
387  /* how did we get here? */
388  GNUNET_break (0);
389  return;
390  }
391  if (NULL == env)
392  {
393  /* how did we get here? */
394  GNUNET_break (0);
395  return;
396  }
397  ch->allow_send--;
398  ch->pending_env = NULL;
400  "Sending message on channel %s to CADET, new window size is %u\n",
401  GNUNET_i2s (&ch->peer),
402  ch->allow_send);
403  GNUNET_MQ_send (ch->cadet->mq, env);
405 }
406 
407 
420 static void
422  const struct GNUNET_MessageHeader *msg,
423  void *impl_state)
424 {
425  struct GNUNET_CADET_Channel *ch = impl_state;
426  struct GNUNET_CADET_Handle *h = ch->cadet;
427  uint16_t msize;
428  struct GNUNET_MQ_Envelope *orig_env;
429  struct GNUNET_MQ_Envelope *env;
430  struct GNUNET_CADET_LocalData *cadet_msg;
432 
433  if (NULL == h->mq)
434  {
435  /* We're currently reconnecting, pretend this worked */
437  return;
438  }
439  orig_env = GNUNET_MQ_get_current_envelope (mq);
440  pp = GNUNET_MQ_env_get_options (orig_env);
441 
442  /* check message size for sanity */
443  msize = ntohs (msg->size);
445  {
446  GNUNET_break (0);
448  return;
449  }
450  env = GNUNET_MQ_msg_nested_mh (cadet_msg,
452  msg);
453  cadet_msg->ccn = ch->ccn;
454  cadet_msg->pp = htonl ((uint32_t) pp);
455  GNUNET_assert (NULL == ch->pending_env);
456  ch->pending_env = env;
457  if (0 < ch->allow_send)
459 }
460 
461 
469 static void
470 cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
471 {
472  struct GNUNET_CADET_Channel *ch = impl_state;
473 
474  GNUNET_assert (mq == ch->mq);
475  ch->mq = NULL;
476 }
477 
478 
487 static void
489 {
490  struct GNUNET_CADET_Channel *ch = cls;
491 
492  if (GNUNET_MQ_ERROR_NO_MATCH == error)
493  {
494  /* Got a message we did not understand, still try to continue! */
495  GNUNET_break_op (0);
497  }
498  else
499  {
501  "MQ error in communication with CADET: %d\n",
502  error);
503  if (NULL != ch->disconnects)
504  ch->disconnects (ch->ctx, ch);
506  }
507 }
508 
509 
517 static void
518 cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
519 {
520  struct GNUNET_CADET_Channel *ch = impl_state;
521 
522  (void) mq;
523  GNUNET_assert (NULL != ch->pending_env);
525  ch->pending_env = NULL;
526  if (NULL != ch->mq_cont)
527  {
529  ch->mq_cont = NULL;
530  }
531 }
532 
533 
540 static void
542  void *cls,
544 {
545  struct GNUNET_CADET_Handle *h = cls;
546  struct GNUNET_CADET_Channel *ch;
547  struct GNUNET_CADET_Port *port;
548  const struct GNUNET_HashCode *port_number;
550 
551  ccn = msg->ccn;
552  port_number = &msg->port;
553  if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
554  {
555  GNUNET_break (0);
556  return;
557  }
558  port = find_port (h, port_number);
559  if (NULL == port)
560  {
561  /* We could have closed the port but the service didn't know about it yet
562  * This is not an error.
563  */
565  struct GNUNET_MQ_Envelope *env;
566 
568  "No handler for incoming channel %X (on port %s, recently closed?)\n",
569  ntohl (ccn.channel_of_client),
570  GNUNET_h2s (port_number));
571  env =
573  d_msg->ccn = msg->ccn;
574  GNUNET_MQ_send (h->mq, env);
575  return;
576  }
577 
578  ch = create_channel (h, &ccn);
579  ch->peer = msg->peer;
580  ch->incoming_port = port;
581  ch->options = ntohl (msg->opt);
583  "Creating incoming channel %X [%s] %p\n",
584  ntohl (ccn.channel_of_client),
585  GNUNET_h2s (port_number),
586  ch);
587 
588  GNUNET_assert (NULL != port->connects);
589  ch->window_changes = port->window_changes;
590  ch->disconnects = port->disconnects;
594  ch,
595  port->handlers,
597  ch);
598  ch->ctx = port->connects (port->cls, ch, &msg->peer);
600 }
601 
602 
609 static void
611  void *cls,
613 {
614  struct GNUNET_CADET_Handle *h = cls;
615  struct GNUNET_CADET_Channel *ch;
616 
617  ch = find_channel (h, msg->ccn);
618  if (NULL == ch)
619  {
621  "Received channel destroy for unknown channel %X from CADET service (recently close?)\n",
622  ntohl (msg->ccn.channel_of_client));
623  return;
624  }
626  "Received channel destroy for channel %X from CADET service\n",
627  ntohl (msg->ccn.channel_of_client));
628  destroy_channel (ch);
629 }
630 
631 
640 static int
641 check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
642 {
643  uint16_t size;
644 
645  (void) cls;
646  size = ntohs (message->header.size);
647  if (sizeof (*message) + sizeof (struct GNUNET_MessageHeader) > size)
648  {
649  GNUNET_break (0);
650  return GNUNET_SYSERR;
651  }
652  return GNUNET_OK;
653 }
654 
655 
662 static void
663 handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
664 {
665  struct GNUNET_CADET_Handle *h = cls;
666  const struct GNUNET_MessageHeader *payload;
667  struct GNUNET_CADET_Channel *ch;
668  uint16_t type;
669  int fwd;
670 
671  ch = find_channel (h, message->ccn);
672  if (NULL == ch)
673  {
675  "Unknown channel %X for incoming data (recently closed?)\n",
676  ntohl (message->ccn.channel_of_client));
677  return;
678  }
679 
680  payload = (const struct GNUNET_MessageHeader *) &message[1];
681  type = ntohs (payload->type);
684  "Got a %s data on channel %s [%X] of type %u\n",
685  fwd ? "FWD" : "BWD",
686  GNUNET_i2s (&ch->peer),
687  ntohl (message->ccn.channel_of_client),
688  type);
689  GNUNET_MQ_inject_message (ch->mq, payload);
690 }
691 
692 
700 static void
701 handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message)
702 {
703  struct GNUNET_CADET_Handle *h = cls;
704  struct GNUNET_CADET_Channel *ch;
705 
706  ch = find_channel (h, message->ccn);
707  if (NULL == ch)
708  {
710  "ACK on unknown channel %X\n",
711  ntohl (message->ccn.channel_of_client));
712  return;
713  }
714  ch->allow_send++;
716  "Got an ACK on mq channel %X (peer %s); new window size is %u!\n",
717  ntohl (ch->ccn.channel_of_client),
718  GNUNET_i2s (&ch->peer),
719  ch->allow_send);
720  if (NULL == ch->pending_env)
721  {
723  "Got an ACK on mq channel %X, allow send now %u!\n",
724  ntohl (ch->ccn.channel_of_client),
725  ch->allow_send);
726  notify_window_size (ch);
727  return;
728  }
729  if (NULL != ch->mq_cont)
730  return; /* already working on it! */
732 }
733 
734 
744 static int
745 destroy_channel_cb (void *cls, uint32_t cid, void *value)
746 {
747  /* struct GNUNET_CADET_Handle *handle = cls; */
748  struct GNUNET_CADET_Channel *ch = value;
749 
750  (void) cls;
751  (void) cid;
753  "Destroying channel due to GNUNET_CADET_disconnect()\n");
754  destroy_channel (ch);
755  return GNUNET_OK;
756 }
757 
758 
767 static void
768 handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
769 {
770  struct GNUNET_CADET_Handle *h = cls;
771 
772  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
774  GNUNET_MQ_destroy (h->mq);
775  h->mq = NULL;
776  GNUNET_assert (NULL == h->reconnect_task);
777  h->reconnect_task =
779 }
780 
781 
788 static void
790 {
791  struct GNUNET_MQ_MessageHandler handlers[] =
792  {GNUNET_MQ_hd_fixed_size (channel_created,
795  h),
799  h),
800  GNUNET_MQ_hd_var_size (local_data,
802  struct GNUNET_CADET_LocalData,
803  h),
804  GNUNET_MQ_hd_fixed_size (local_ack,
806  struct GNUNET_CADET_LocalAck,
807  h),
809 
810  GNUNET_assert (NULL == h->mq);
811  h->mq =
812  GNUNET_CLIENT_connect (h->cfg, "cadet", handlers, &handle_mq_error, h);
813 }
814 
815 
825 static int
826 destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
827 {
828  /* struct GNUNET_CADET_Handle *handle = cls; */
829  struct GNUNET_CADET_Port *port = value;
830 
831  (void) cls;
832  (void) id;
833  /* This is a warning, the app should have cleanly closed all open ports */
834  GNUNET_break (0);
836  return GNUNET_OK;
837 }
838 
839 
848 void
850 {
853  handle);
855  handle->ports = NULL;
858  handle);
860  handle->channels = NULL;
861  if (NULL != handle->mq)
862  {
863  GNUNET_MQ_destroy (handle->mq);
864  handle->mq = NULL;
865  }
866  if (NULL != handle->reconnect_task)
867  {
869  handle->reconnect_task = NULL;
870  }
871  GNUNET_free (handle);
872 }
873 
874 
881 void
883 {
884  GNUNET_assert (
885  GNUNET_YES ==
887  if (NULL != p->cadet->mq)
888  {
890  struct GNUNET_MQ_Envelope *env;
891 
893  msg->port = p->id;
894  GNUNET_MQ_send (p->cadet->mq, env);
895  }
897  GNUNET_free (p);
898 }
899 
900 
910 void
912 {
913  struct GNUNET_CADET_Handle *h = channel->cadet;
915  struct GNUNET_MQ_Envelope *env;
916 
917  if (NULL != h->mq)
918  {
920  msg->ccn = channel->ccn;
921  GNUNET_MQ_send (h->mq, env);
922  }
924  "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
925  channel->disconnects = NULL;
926  destroy_channel (channel);
927 }
928 
929 
939 const union GNUNET_CADET_ChannelInfo *
942  ...)
943 {
944  static int bool_flag;
945 
946  switch (option)
947  {
951  if (0 != (option & channel->options))
952  bool_flag = GNUNET_YES;
953  else
954  bool_flag = GNUNET_NO;
955  return (const union GNUNET_CADET_ChannelInfo *) &bool_flag;
956  break;
958  return (const union GNUNET_CADET_ChannelInfo *) &channel->peer;
959  break;
960  default:
961  GNUNET_break (0);
962  return NULL;
963  }
964 }
965 
966 
972 void
974 {
975  struct GNUNET_CADET_LocalAck *msg;
976  struct GNUNET_MQ_Envelope *env;
977 
980  "Sending ACK on channel %X\n",
981  ntohl (channel->ccn.channel_of_client));
982  msg->ccn = channel->ccn;
983  GNUNET_MQ_send (channel->cadet->mq, env);
984 }
985 
986 
994 struct GNUNET_CADET_Handle *
996 {
997  struct GNUNET_CADET_Handle *h;
998 
999  LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n");
1000  h = GNUNET_new (struct GNUNET_CADET_Handle);
1001  h->cfg = cfg;
1004  reconnect (h);
1005  if (NULL == h->mq)
1006  {
1007  GNUNET_break (0);
1009  return NULL;
1010  }
1012  return h;
1013 }
1014 
1015 
1028 struct GNUNET_CADET_Port *
1030  const struct GNUNET_HashCode *port,
1032  void *connects_cls,
1035  const struct GNUNET_MQ_MessageHandler *handlers)
1036 {
1037  struct GNUNET_CADET_Port *p;
1038 
1039  GNUNET_assert (NULL != connects);
1040  GNUNET_assert (NULL != disconnects);
1042  "Listening to CADET port %s\n",
1043  GNUNET_h2s (port));
1044 
1045  p = GNUNET_new (struct GNUNET_CADET_Port);
1046  p->cadet = h;
1047  p->id = *port;
1049  h->ports,
1050  &p->id,
1051  p,
1053  {
1054  GNUNET_free (p);
1055  return NULL;
1056  }
1057  p->connects = connects;
1058  p->cls = connects_cls;
1060  p->disconnects = disconnects;
1061  p->handlers = GNUNET_MQ_copy_handlers (handlers);
1062 
1063  GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p));
1064  return p;
1065 }
1066 
1067 
1087 struct GNUNET_CADET_Channel *
1089  void *channel_cls,
1090  const struct GNUNET_PeerIdentity *destination,
1091  const struct GNUNET_HashCode *port,
1095  const struct GNUNET_MQ_MessageHandler *handlers)
1096 {
1097  struct GNUNET_CADET_Channel *ch;
1099  struct GNUNET_MQ_Envelope *env;
1100 
1101  GNUNET_assert (NULL != disconnects);
1103  "Creating channel to peer %s at port %s\n",
1104  GNUNET_i2s (destination),
1105  GNUNET_h2s (port));
1106  ch = create_channel (h, NULL);
1107  ch->ctx = channel_cls;
1108  ch->peer = *destination;
1109  ch->options = options;
1110  ch->window_changes = window_changes;
1111  ch->disconnects = disconnects;
1112 
1113  /* Create MQ for channel */
1117  ch,
1118  handlers,
1120  ch);
1121  GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls);
1122 
1123  /* Request channel creation to service */
1125  msg->ccn = ch->ccn;
1126  msg->port = *port;
1127  msg->peer = *destination;
1128  msg->opt = htonl (options);
1129  GNUNET_MQ_send (h->mq, env);
1130  return ch;
1131 }
1132 
1133 
1141 struct GNUNET_MQ_Handle *
1143 {
1144  return channel->mq;
1145 }
1146 
1147 /* end of cadet_api.c */
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration given by the client, in case of reconnection.
Definition: cadet_api.c:63
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
GNUNET_CADET_DisconnectEventHandler disconnects
Handler called when an incoming channel is destroyed.
Definition: cadet_api.c:187
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:849
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:150
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Message to allow the client send more data to the service (always service -> client).
Definition: cadet.h:217
static void channel_destroy(struct CadetChannel *ch)
Destroy the given channel.
GNUNET_CADET_DisconnectEventHandler disconnects
Disconnect handler.
Definition: cadet_api.c:129
uint32_t channel_of_client
Values for channel numbering.
Definition: cadet.h:111
Message for or to a client to destroy tunnel.
Definition: cadet.h:172
Who is the peer at the other end of the channel.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
Tell client that a channel was destroyed.
GNUNET_CADET_WindowSizeEventHandler window_changes
Window size change handler.
Definition: cadet_api.c:182
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
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:901
Opaque handle to the service.
Definition: cadet_api.c:38
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct...
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.
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:325
static void reconnect_cbk(void *cls)
Reconnect callback: tries to reconnect again after a failer previous reconnecttion.
Definition: cadet_api.c:347
GNUNET_MQ_Error
Error codes for the queue.
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:610
We received a message for which we have no matching handler.
Message for a client to create and destroy channels.
Definition: cadet.h:118
void(* GNUNET_CADET_WindowSizeEventHandler)(void *cls, const struct GNUNET_CADET_Channel *channel, int window_size)
Function called whenever an MQ-channel&#39;s transmission window size changes.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_HashCode id
Port "number".
Definition: cadet_api.c:157
static void cadet_mq_send_now(void *cls)
Transmit the next message from our queue.
Definition: cadet_api.c:379
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1193
Enable channel reliability, lost messages will be retransmitted.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
static void cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
Definition: cadet_api.c:470
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_HashMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_PeerIdentity peer
Other end of the channel.
Definition: cadet_api.c:86
#define GNUNET_NO
Definition: gnunet_common.h:81
Opaque handle to a channel.
Definition: cadet_api.c:80
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
unsigned int allow_send
How many messages are we allowed to send to the service right now?
Definition: cadet_api.c:144
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:364
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
Ask the cadet service to create a new channel.
GNUNET_CADET_ConnectEventHandler connects
Handler for incoming channels on this port.
Definition: cadet_api.c:172
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:541
int 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.
struct GNUNET_CADET_ClientChannelNumber next_ccn
child of the next channel to create (to avoid reusing IDs often)
Definition: cadet_api.c:58
Internal representation of the hash map.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
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:768
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:995
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_SCHEDULER_Task * mq_cont
Task to allow mq to send more traffic.
Definition: cadet_api.c:112
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition: mq.c:1020
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:583
struct GNUNET_CADET_ClientChannelNumber ccn
Local ID of the channel, GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
Definition: cadet_api.c:134
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:701
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:1246
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
Local ACK for data.
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:552
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 incomming MQ-based channels.
Definition: cadet_api.c:1029
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
int GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
void * cls
Closure for mv and cb.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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:219
struct GNUNET_CONTAINER_MultiHashMap * ports
Ports open.
Definition: cadet_api.c:48
static char * value
Value of the record to add/remove.
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:235
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.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ctx
Any data the caller wants to put in here, used for the various callbacks (disconnects, window_changes, handlers).
Definition: cadet_api.c:102
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: cadet_api.c:43
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:1273
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
Start listening on a port.
static char * option
Name of the option.
Definition: gnunet-config.c:38
int 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.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Number uniquely identifying a channel of a client.
Definition: cadet.h:102
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:202
#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI
Minimum value for channel IDs of local clients.
Definition: cadet.h:71
#define LOG(kind,...)
Definition: cadet_api.c:33
Internal representation of the hash map.
Enable out of order delivery of messages.
static void reconnect(struct GNUNET_CADET_Handle *h)
Reconnect to the service, retransmit all infomation to try to restore the original state...
Definition: cadet_api.c:789
A 512-bit hashcode.
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel.
Definition: cadet.h:199
Union to retrieve info about a channel.
Message handler for a specific message type.
void * connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Definition: 010.c:2
#define GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE
Maximum message size that can be sent on CADET.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
struct GNUNET_TIME_Relative reconnect_time
Time to the next reconnect in case one reconnect fails.
Definition: cadet_api.c:73
void * cls
Closure for handler.
Definition: cadet_api.c:167
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
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:421
void disconnects(void *cls, const struct GNUNET_PeerIdentity *peer)
Definition: 011.c:2
There must only be one value per key; storing a value should fail if a value under the same key alrea...
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:518
struct GNUNET_HashCode port
Port to open/close.
Definition: cadet.h:131
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void destroy_channel(struct GNUNET_CADET_Channel *ch)
Destroy the specified channel.
Definition: cadet_api.c:277
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet_api.c:107
Message for a client to create channels.
Definition: cadet.h:138
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:745
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_CADET_Handle * cadet
Handle to the CADET session this port belongs to.
Definition: cadet_api.c:162
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel allowed to send more data.
Definition: cadet.h:227
struct GNUNET_CADET_Handle * cadet
Handle to the cadet this channel belongs to.
Definition: cadet_api.c:91
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
int 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.
static unsigned long long payload
How much data are we currently storing in the database?
void * connects_cls
Closure for connects.
Definition: cadet_api.c:177
P2P messages used by CADET.
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:663
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_HashMapIterator32 it, void *it_cls)
Iterate over all entries in the map.
const union GNUNET_CADET_ChannelInfo * GNUNET_CADET_channel_get_info(struct GNUNET_CADET_Channel *channel, enum GNUNET_CADET_ChannelOption option,...)
Get information about a channel.
Definition: cadet_api.c:940
Handle to a message queue.
Definition: mq.c:85
The identity of the host (wraps the signing key of the peer).
enum GNUNET_CADET_ChannelOption options
Channel options: reliability, etc.
Definition: cadet_api.c:139
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:973
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:182
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:826
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
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_api.c:119
configuration data
Definition: configuration.c:85
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
Stop listening on a port.
struct GNUNET_MQ_MessageHandler * handlers
Payload handlers for incoming channels.
Definition: cadet_api.c:192
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
Payload client <-> service.
GNUNET_CADET_WindowSizeEventHandler window_changes
Window change handler.
Definition: cadet_api.c:124
struct GNUNET_CADET_Port * incoming_port
Channel&#39;s port, if incoming.
Definition: cadet_api.c:96
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
Opaque handle to a port.
Definition: cadet_api.c:151
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
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:204
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:641
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
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:974
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA.
Definition: cadet.h:194
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Definition: cadet_api.c:882
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:80
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:488
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:353
Message for cadet data traffic.
Definition: cadet.h:189
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...
uint32_t pp
Priority and preferences (an enum GNUNET_MQ_PriorityPreferences) of the message in NBO...
Definition: cadet.h:205
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for trying to reconnect.
Definition: cadet_api.c:68
GNUNET_CADET_ChannelOption
Channel options.
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels open.
Definition: cadet_api.c:53
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:486
struct GNUNET_PeerIdentity peer
Channel&#39;s peer.
Definition: cadet.h:155
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:911
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_HashCode port
Port of the channel.
Definition: cadet.h:160
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
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, enum GNUNET_CADET_ChannelOption options, 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:1088
Disable buffering on intermediate nodes (for minimum latency).
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:1142
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965