GNUnet  0.11.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 {
86 
91 
96 
101  void *ctx;
102 
107 
112 
119 
124 
129 
134 
138  unsigned int allow_send;
139 };
140 
141 
146 {
151 
156 
160  void *cls;
161 
166 
171 
176 
181 
186 };
187 
188 
196 static struct GNUNET_CADET_Port *
198  const struct GNUNET_HashCode *hash)
199 {
200  return GNUNET_CONTAINER_multihashmap_get (h->ports, hash);
201 }
202 
203 
211 static struct GNUNET_CADET_Channel *
214 {
216  ntohl (ccn.channel_of_client));
217 }
218 
219 
227 static struct GNUNET_CADET_Channel *
229  const struct GNUNET_CADET_ClientChannelNumber *ccnp)
230 {
231  struct GNUNET_CADET_Channel *ch;
233 
234  ch = GNUNET_new (struct GNUNET_CADET_Channel);
235  ch->cadet = h;
236  if (NULL == ccnp)
237  {
238  while (NULL != find_channel (h, h->next_ccn))
241  | (1 + ntohl (h->next_ccn.channel_of_client)));
242  ccn = h->next_ccn;
243  }
244  else
245  {
246  ccn = *ccnp;
247  }
248  ch->ccn = ccn;
251  h->channels,
252  ntohl (ch->ccn.channel_of_client),
253  ch,
255  return ch;
256 }
257 
258 
269 static void
271 {
272  struct GNUNET_CADET_Handle *h = ch->cadet;
273 
275  "Destroying channel %X of %p\n",
276  htonl (ch->ccn.channel_of_client),
277  h);
278  GNUNET_assert (
279  GNUNET_YES ==
281  ntohl (ch->ccn.channel_of_client),
282  ch));
283  if (NULL != ch->mq_cont)
284  {
286  ch->mq_cont = NULL;
287  }
288  /* signal channel destruction */
289  if (NULL != ch->disconnects)
290  ch->disconnects (ch->ctx, ch);
291  if (NULL != ch->pending_env)
293  GNUNET_MQ_destroy (ch->mq);
294  GNUNET_free (ch);
295 }
296 
297 
304 static void
306 
307 
317 static int
318 open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
319 {
320  struct GNUNET_CADET_Handle *h = cls;
321  struct GNUNET_CADET_Port *port = value;
323  struct GNUNET_MQ_Envelope *env;
324 
325  (void) id;
327  msg->port = port->id;
328  GNUNET_MQ_send (h->mq, env);
329  return GNUNET_OK;
330 }
331 
332 
339 static void
340 reconnect_cbk (void *cls)
341 {
342  struct GNUNET_CADET_Handle *h = cls;
343 
344  h->reconnect_task = NULL;
346  reconnect (h);
348 }
349 
350 
356 static void
358 {
359  if (NULL != ch->window_changes)
360  ch->window_changes (ch->ctx,
361  ch, /* FIXME: remove 'ch'? */
362  ch->allow_send);
363 }
364 
365 
371 static void
372 cadet_mq_send_now (void *cls)
373 {
374  struct GNUNET_CADET_Channel *ch = cls;
375  struct GNUNET_MQ_Envelope *env = ch->pending_env;
376 
377  ch->mq_cont = NULL;
378  if (0 == ch->allow_send)
379  {
380  /* how did we get here? */
381  GNUNET_break (0);
382  return;
383  }
384  if (NULL == env)
385  {
386  /* how did we get here? */
387  GNUNET_break (0);
388  return;
389  }
390  ch->allow_send--;
391  ch->pending_env = NULL;
393  "Sending message on channel %s to CADET, new window size is %u\n",
394  GNUNET_i2s (&ch->peer),
395  ch->allow_send);
396  GNUNET_MQ_send (ch->cadet->mq, env);
398 }
399 
400 
413 static void
415  const struct GNUNET_MessageHeader *msg,
416  void *impl_state)
417 {
418  struct GNUNET_CADET_Channel *ch = impl_state;
419  struct GNUNET_CADET_Handle *h = ch->cadet;
420  uint16_t msize;
421  struct GNUNET_MQ_Envelope *orig_env;
422  struct GNUNET_MQ_Envelope *env;
423  struct GNUNET_CADET_LocalData *cadet_msg;
425 
426  if (NULL == h->mq)
427  {
428  /* We're currently reconnecting, pretend this worked */
430  return;
431  }
432  orig_env = GNUNET_MQ_get_current_envelope (mq);
433  pp = GNUNET_MQ_env_get_options (orig_env);
434 
435  /* check message size for sanity */
436  msize = ntohs (msg->size);
438  {
439  GNUNET_break (0);
441  return;
442  }
443  env = GNUNET_MQ_msg_nested_mh (cadet_msg,
445  msg);
446  cadet_msg->ccn = ch->ccn;
447  cadet_msg->pp = htonl ((uint32_t) pp);
448  GNUNET_assert (NULL == ch->pending_env);
449  ch->pending_env = env;
450  if (0 < ch->allow_send)
452 }
453 
454 
462 static void
463 cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
464 {
465  struct GNUNET_CADET_Channel *ch = impl_state;
466 
467  GNUNET_assert (mq == ch->mq);
468  ch->mq = NULL;
469 }
470 
471 
480 static void
482 {
483  struct GNUNET_CADET_Channel *ch = cls;
484 
485  if (GNUNET_MQ_ERROR_NO_MATCH == error)
486  {
487  /* Got a message we did not understand, still try to continue! */
488  GNUNET_break_op (0);
490  }
491  else
492  {
494  "MQ error in communication with CADET: %d\n",
495  error);
496  if (NULL != ch->disconnects)
497  ch->disconnects (ch->ctx, ch);
499  }
500 }
501 
502 
510 static void
511 cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
512 {
513  struct GNUNET_CADET_Channel *ch = impl_state;
514 
515  (void) mq;
516  GNUNET_assert (NULL != ch->pending_env);
518  ch->pending_env = NULL;
519  if (NULL != ch->mq_cont)
520  {
522  ch->mq_cont = NULL;
523  }
524 }
525 
526 
533 static void
535  void *cls,
537 {
538  struct GNUNET_CADET_Handle *h = cls;
539  struct GNUNET_CADET_Channel *ch;
540  struct GNUNET_CADET_Port *port;
541  const struct GNUNET_HashCode *port_number;
543 
544  ccn = msg->ccn;
545  port_number = &msg->port;
546  if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
547  {
548  GNUNET_break (0);
549  return;
550  }
551  port = find_port (h, port_number);
552  if (NULL == port)
553  {
554  /* We could have closed the port but the service didn't know about it yet
555  * This is not an error.
556  */
558  struct GNUNET_MQ_Envelope *env;
559 
561  "No handler for incoming channel %X (on port %s, recently closed?)\n",
562  ntohl (ccn.channel_of_client),
563  GNUNET_h2s (port_number));
564  env =
566  d_msg->ccn = msg->ccn;
567  GNUNET_MQ_send (h->mq, env);
568  return;
569  }
570 
571  ch = create_channel (h, &ccn);
572  ch->peer = msg->peer;
573  ch->incoming_port = port;
575  "Creating incoming channel %X [%s] %p\n",
576  ntohl (ccn.channel_of_client),
577  GNUNET_h2s (port_number),
578  ch);
579 
580  GNUNET_assert (NULL != port->connects);
581  ch->window_changes = port->window_changes;
582  ch->disconnects = port->disconnects;
586  ch,
587  port->handlers,
589  ch);
590  ch->ctx = port->connects (port->cls, ch, &msg->peer);
592 }
593 
594 
601 static void
603  void *cls,
605 {
606  struct GNUNET_CADET_Handle *h = cls;
607  struct GNUNET_CADET_Channel *ch;
608 
609  ch = find_channel (h, msg->ccn);
610  if (NULL == ch)
611  {
613  "Received channel destroy for unknown channel %X from CADET service (recently close?)\n",
614  ntohl (msg->ccn.channel_of_client));
615  return;
616  }
618  "Received channel destroy for channel %X from CADET service\n",
619  ntohl (msg->ccn.channel_of_client));
620  destroy_channel (ch);
621 }
622 
623 
632 static int
633 check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
634 {
635  uint16_t size;
636 
637  (void) cls;
638  size = ntohs (message->header.size);
639  if (sizeof(*message) + sizeof(struct GNUNET_MessageHeader) > size)
640  {
641  GNUNET_break (0);
642  return GNUNET_SYSERR;
643  }
644  return GNUNET_OK;
645 }
646 
647 
654 static void
655 handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message)
656 {
657  struct GNUNET_CADET_Handle *h = cls;
658  const struct GNUNET_MessageHeader *payload;
659  struct GNUNET_CADET_Channel *ch;
660  uint16_t type;
661  int fwd;
662 
663  ch = find_channel (h, message->ccn);
664  if (NULL == ch)
665  {
667  "Unknown channel %X for incoming data (recently closed?)\n",
668  ntohl (message->ccn.channel_of_client));
669  return;
670  }
671 
672  payload = (const struct GNUNET_MessageHeader *) &message[1];
673  type = ntohs (payload->type);
676  "Got a %s data on channel %s [%X] of type %u\n",
677  fwd ? "FWD" : "BWD",
678  GNUNET_i2s (&ch->peer),
679  ntohl (message->ccn.channel_of_client),
680  type);
681  GNUNET_MQ_inject_message (ch->mq, payload);
682 }
683 
684 
692 static void
693 handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message)
694 {
695  struct GNUNET_CADET_Handle *h = cls;
696  struct GNUNET_CADET_Channel *ch;
697 
698  ch = find_channel (h, message->ccn);
699  if (NULL == ch)
700  {
702  "ACK on unknown channel %X\n",
703  ntohl (message->ccn.channel_of_client));
704  return;
705  }
706  ch->allow_send++;
708  "Got an ACK on mq channel %X (peer %s); new window size is %u!\n",
709  ntohl (ch->ccn.channel_of_client),
710  GNUNET_i2s (&ch->peer),
711  ch->allow_send);
712  if (NULL == ch->pending_env)
713  {
715  "Got an ACK on mq channel %X, allow send now %u!\n",
716  ntohl (ch->ccn.channel_of_client),
717  ch->allow_send);
718  notify_window_size (ch);
719  return;
720  }
721  if (NULL != ch->mq_cont)
722  return; /* already working on it! */
724 }
725 
726 
736 static int
737 destroy_channel_cb (void *cls, uint32_t cid, void *value)
738 {
739  /* struct GNUNET_CADET_Handle *handle = cls; */
740  struct GNUNET_CADET_Channel *ch = value;
741 
742  (void) cls;
743  (void) cid;
745  "Destroying channel due to GNUNET_CADET_disconnect()\n");
746  destroy_channel (ch);
747  return GNUNET_OK;
748 }
749 
750 
759 static void
760 handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
761 {
762  struct GNUNET_CADET_Handle *h = cls;
763 
764  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
766  GNUNET_MQ_destroy (h->mq);
767  h->mq = NULL;
768  GNUNET_assert (NULL == h->reconnect_task);
769  h->reconnect_task =
771 }
772 
773 
780 static void
782 {
783  struct GNUNET_MQ_MessageHandler handlers[] =
784  { GNUNET_MQ_hd_fixed_size (channel_created,
787  h),
791  h),
792  GNUNET_MQ_hd_var_size (local_data,
794  struct GNUNET_CADET_LocalData,
795  h),
796  GNUNET_MQ_hd_fixed_size (local_ack,
798  struct GNUNET_CADET_LocalAck,
799  h),
801 
802  GNUNET_assert (NULL == h->mq);
803  h->mq =
804  GNUNET_CLIENT_connect (h->cfg, "cadet", handlers, &handle_mq_error, h);
805 }
806 
807 
817 static int
818 destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value)
819 {
820  /* struct GNUNET_CADET_Handle *handle = cls; */
821  struct GNUNET_CADET_Port *port = value;
822 
823  (void) cls;
824  (void) id;
825  /* This is a warning, the app should have cleanly closed all open ports */
826  GNUNET_break (0);
828  return GNUNET_OK;
829 }
830 
831 
840 void
842 {
845  handle);
847  handle->ports = NULL;
850  handle);
852  handle->channels = NULL;
853  if (NULL != handle->mq)
854  {
855  GNUNET_MQ_destroy (handle->mq);
856  handle->mq = NULL;
857  }
858  if (NULL != handle->reconnect_task)
859  {
861  handle->reconnect_task = NULL;
862  }
863  GNUNET_free (handle);
864 }
865 
866 
873 void
875 {
876  GNUNET_assert (
877  GNUNET_YES ==
879  if (NULL != p->cadet->mq)
880  {
882  struct GNUNET_MQ_Envelope *env;
883 
885  msg->port = p->id;
886  GNUNET_MQ_send (p->cadet->mq, env);
887  }
889  GNUNET_free (p);
890 }
891 
892 
902 void
904 {
905  struct GNUNET_CADET_Handle *h = channel->cadet;
907  struct GNUNET_MQ_Envelope *env;
908 
909  if (NULL != h->mq)
910  {
912  msg->ccn = channel->ccn;
913  GNUNET_MQ_send (h->mq, env);
914  }
916  "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
917  channel->disconnects = NULL;
918  destroy_channel (channel);
919 }
920 
921 
931 const union GNUNET_CADET_ChannelInfo *
934  ...)
935 {
936  switch (option)
937  {
939  return (const union GNUNET_CADET_ChannelInfo *) &channel->peer;
940 
941  default:
942  GNUNET_break (0);
943  return NULL;
944  }
945 }
946 
947 
953 void
955 {
956  struct GNUNET_CADET_LocalAck *msg;
957  struct GNUNET_MQ_Envelope *env;
958 
961  "Sending ACK on channel %X\n",
962  ntohl (channel->ccn.channel_of_client));
963  msg->ccn = channel->ccn;
964  GNUNET_MQ_send (channel->cadet->mq, env);
965 }
966 
967 
975 struct GNUNET_CADET_Handle *
977 {
978  struct GNUNET_CADET_Handle *h;
979 
980  LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n");
981  h = GNUNET_new (struct GNUNET_CADET_Handle);
982  h->cfg = cfg;
985  reconnect (h);
986  if (NULL == h->mq)
987  {
988  GNUNET_break (0);
990  return NULL;
991  }
993  return h;
994 }
995 
996 
1009 struct GNUNET_CADET_Port *
1011  const struct GNUNET_HashCode *port,
1013  void *connects_cls,
1016  const struct GNUNET_MQ_MessageHandler *handlers)
1017 {
1018  struct GNUNET_CADET_Port *p;
1019 
1020  GNUNET_assert (NULL != connects);
1021  GNUNET_assert (NULL != disconnects);
1023  "Listening to CADET port %s\n",
1024  GNUNET_h2s (port));
1025 
1026  p = GNUNET_new (struct GNUNET_CADET_Port);
1027  p->cadet = h;
1028  p->id = *port;
1030  h->ports,
1031  &p->id,
1032  p,
1034  {
1035  GNUNET_free (p);
1036  return NULL;
1037  }
1038  p->connects = connects;
1039  p->cls = connects_cls;
1041  p->disconnects = disconnects;
1042  p->handlers = GNUNET_MQ_copy_handlers (handlers);
1043 
1044  GNUNET_assert (GNUNET_OK == open_port_cb (h, &p->id, p));
1045  return p;
1046 }
1047 
1048 
1067 struct GNUNET_CADET_Channel *
1069  void *channel_cls,
1070  const struct GNUNET_PeerIdentity *destination,
1071  const struct GNUNET_HashCode *port,
1074  const struct GNUNET_MQ_MessageHandler *handlers)
1075 {
1076  struct GNUNET_CADET_Channel *ch;
1078  struct GNUNET_MQ_Envelope *env;
1079 
1080  GNUNET_assert (NULL != disconnects);
1082  "Creating channel to peer %s at port %s\n",
1083  GNUNET_i2s (destination),
1084  GNUNET_h2s (port));
1085  ch = create_channel (h, NULL);
1086  ch->ctx = channel_cls;
1087  ch->peer = *destination;
1088  ch->window_changes = window_changes;
1089  ch->disconnects = disconnects;
1090 
1091  /* Create MQ for channel */
1095  ch,
1096  handlers,
1098  ch);
1099  GNUNET_MQ_set_handlers_closure (ch->mq, channel_cls);
1100 
1101  /* Request channel creation to service */
1103  msg->ccn = ch->ccn;
1104  msg->port = *port;
1105  msg->peer = *destination;
1106  GNUNET_MQ_send (h->mq, env);
1107  return ch;
1108 }
1109 
1110 
1118 struct GNUNET_MQ_Handle *
1120 {
1121  return channel->mq;
1122 }
1123 
1124 
1125 /* 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:180
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:841
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:128
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
#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:175
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:1057
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.
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:932
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:318
static void reconnect_cbk(void *cls)
Reconnect callback: tries to reconnect again after a failer previous reconnecttion.
Definition: cadet_api.c:340
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:602
We received a message for which we have no matching handler.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
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:150
static void cadet_mq_send_now(void *cls)
Transmit the next message from our queue.
Definition: cadet_api.c:372
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1214
#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:463
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_PeerIdentity peer
Other end of the channel.
Definition: cadet_api.c:85
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:75
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:138
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:357
#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:165
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:534
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:99
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:760
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:976
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:111
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:133
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:693
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:1253
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:1010
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:212
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:228
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:101
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
GNUNET_CADET_ChannelInfoOption
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:1280
#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.
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:781
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:160
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:414
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:511
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:270
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:106
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:737
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:155
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:90
#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:170
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:655
Handle to a message queue.
Definition: mq.c:85
The identity of the host (wraps the signing key of the peer).
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:954
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:182
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:1068
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:818
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
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:118
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:185
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
Payload client <-> service.
GNUNET_CADET_WindowSizeEventHandler window_changes
Window change handler.
Definition: cadet_api.c:123
struct GNUNET_CADET_Port * incoming_port
Channel&#39;s port, if incoming.
Definition: cadet_api.c:95
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
Opaque handle to a port.
Definition: cadet_api.c:145
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:197
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:633
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:874
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:77
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:481
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...
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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
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:903
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.
Who is the peer at the other end of the channel.
Time for relative time used by GNUnet, in microseconds.
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:1119
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966