gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_testing_core_lib.h (6425B)


      1 /*
      2       This file is part of GNUnet
      3       Copyright (C) 2021-2023 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  */
     20 
     21 /**
     22  * @brief API for cmds working with core sub system provided by libgnunetcoretesting
     23  * @author t3sserakt
     24  */
     25 #ifndef GNUNET_TESTING_CORE_LIB_H
     26 #define GNUNET_TESTING_CORE_LIB_H
     27 
     28 
     29 #include "gnunet_util_lib.h"
     30 #include "gnunet_testing_lib.h"
     31 
     32 
     33 #define MTYPE 12345
     34 
     35 #define NODE_ID_LEN 16
     36 
     37 
     38 /**
     39  * Struct to store information needed in callbacks.
     40  */
     41 // FIXME: breaks naming conventions
     42 struct GNUNET_TESTING_ConnectPeersState
     43 {
     44   /**
     45    * Receive callback
     46    */
     47   struct GNUNET_MQ_MessageHandler *handlers;
     48 
     49   /**
     50    * A map with struct GNUNET_MQ_Handle values for each peer this peer
     51    * is connected to.
     52    */
     53   struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
     54 
     55   /**
     56    * Handle for transport.
     57    */
     58   struct GNUNET_TRANSPORT_ApplicationHandle *ah;
     59 
     60   /**
     61    * Core handle.
     62    */
     63   struct GNUNET_TRANSPORT_CoreHandle *th;
     64 
     65   /**
     66    * Context for our asynchronous completion.
     67    */
     68   struct GNUNET_TESTING_AsyncContext ac;
     69 
     70   /**
     71    * The testing system of this node.
     72    */
     73   const struct GNUNET_TESTBED_System *tl_system;
     74 
     75   // Label of the cmd which started the test system.
     76   const char *create_label;
     77 
     78   /**
     79    * Number globally identifying the node.
     80    *
     81    */
     82   uint32_t num;
     83 
     84   /**
     85    * Label of the cmd to start a peer.
     86    *
     87    */
     88   const char *start_peer_label;
     89 
     90   /**
     91    * The topology of the test setup.
     92    */
     93   struct GNUNET_TESTING_NetjailTopology *topology;
     94 
     95   /**
     96    * Connections to other peers.
     97    */
     98   struct GNUNET_TESTING_NodeConnection *node_connections_head;
     99 
    100   struct GNUNET_TESTING_Interpreter *is;
    101 
    102   /**
    103    * Number of connections.
    104    */
    105   unsigned int con_num;
    106 
    107   /**
    108    * Number of additional connects this cmd will wait for not triggered by this cmd.
    109    */
    110   unsigned int additional_connects;
    111 
    112   /**
    113  * Number of connections we already have a notification for.
    114  */
    115   unsigned int con_num_notified;
    116 
    117   /**
    118    * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for.
    119    */
    120   unsigned int additional_connects_notified;
    121 
    122   /**
    123    * Flag indicating, whether the command is waiting for peers to connect that are configured to connect.
    124    */
    125   unsigned int wait_for_connect;
    126 };
    127 
    128 
    129 struct GNUNET_TESTING_CORE_ConnectState;
    130 
    131 
    132 struct GNUNET_TESTING_CORE_Channel
    133 {
    134   struct GNUNET_TESTING_CORE_Channel *next;
    135   struct GNUNET_TESTING_CORE_Channel *prev;
    136   struct GNUNET_TESTING_CORE_ConnectState *connect_state;
    137   struct GNUNET_MQ_Handle *mq;
    138   struct GNUNET_PeerIdentity peer_id;
    139 };
    140 
    141 
    142 struct GNUNET_TESTING_CORE_Message
    143 {
    144   struct GNUNET_MessageHeader header;
    145   // The following will be used for debugging
    146   uint64_t id; // id of the message
    147   uint64_t batch; // first batch of that peer (for this test 0 or 1)
    148   // uint64_t peer; // number of sending peer (for this test 0 or 1)
    149   char node_id[NODE_ID_LEN];
    150 };
    151 
    152 
    153 typedef void *
    154 (*GNUNET_TESTING_CORE_connect_cb) (
    155   void *cls,
    156   const struct GNUNET_PeerIdentity *peer_id,
    157   struct GNUNET_MQ_Handle *mq);
    158 
    159 
    160 struct GNUNET_TESTING_CORE_ConnectCb
    161 {
    162   GNUNET_TESTING_CORE_connect_cb callback;
    163   void *cls;
    164 };
    165 
    166 
    167 typedef void
    168 (*GNUNET_TESTING_CORE_handle_msg)(
    169   void *cls,
    170   struct GNUNET_TESTING_CORE_Channel *channel,
    171   const struct GNUNET_TESTING_CORE_Message *msg);
    172 
    173 
    174 struct GNUNET_TESTING_CORE_ConnectState
    175 {
    176   struct GNUNET_CORE_Handle *h;
    177 
    178   // FIXME why is this const? Borrowed pointer?!
    179   const char*node_id;
    180   struct GNUNET_PeerIdentity peer_id;
    181   char *arm_service_label;
    182   const struct GNUNET_CONFIGURATION_Handle *cfg;
    183   enum GNUNET_GenericReturnValue finished;
    184 
    185   /**
    186    * Receive callback
    187    */
    188   GNUNET_TESTING_CORE_handle_msg *recv_handlers;
    189   uint32_t recv_handlers_len;
    190   void *recv_handlers_cls;
    191 
    192   /**
    193    * Connect callback
    194    * TODO we probably only need a single one.
    195    */
    196   struct GNUNET_TESTING_CORE_ConnectCb *connect_cbs;
    197   uint32_t connect_cbs_len;
    198 
    199   struct GNUNET_TESTING_CORE_Channel *channels_head;
    200   struct GNUNET_TESTING_CORE_Channel *channels_tail;
    201 
    202   struct GNUNET_TESTING_AsyncContext ac;
    203 };
    204 
    205 
    206 /**
    207  * FIXME: document properly!
    208  * Create command
    209  *
    210  * @param label name for command
    211  * @param start_peer_label Label of the cmd to start a peer.
    212  * @param create_label Label of the cmd which started the test system.
    213  * @param num Number globally identifying the node.
    214  * @param topology The topology for the test setup.
    215  * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd.
    216  * @return command.
    217  */
    218 struct GNUNET_TESTING_Command
    219 GNUNET_CORE_cmd_connect_peers (
    220   const char *label,
    221   const char *start_peer_label,
    222   const char *create_label,
    223   uint32_t num,
    224   struct GNUNET_TESTING_NetjailTopology *topology,
    225   unsigned int additional_connects,
    226   unsigned int wait_for_connect,
    227   struct GNUNET_MQ_MessageHandler *handlers);
    228 
    229 const struct GNUNET_TESTING_Command
    230 GNUNET_TESTING_CORE_cmd_connect (
    231   const char *label,
    232   const char*node_id,
    233   char *arm_service_label);
    234 
    235 
    236 const struct GNUNET_TESTING_Command
    237 GNUNET_TESTING_CORE_cmd_recv (
    238   const char *label,
    239   uint64_t num_messages);
    240 
    241 
    242 const struct GNUNET_TESTING_Command
    243 GNUNET_TESTING_CORE_cmd_send (
    244   const char *label,
    245   uint64_t num_messages,
    246   enum GNUNET_GenericReturnValue await_new_connection);
    247 
    248 
    249 /**
    250  * Call #op on all simple traits.
    251  */
    252 #define GNUNET_CORE_TESTING_SIMPLE_TRAITS(op, prefix)   \
    253         op (prefix, connect_peer_state, const struct \
    254             GNUNET_TESTING_ConnectPeersState) \
    255         op (prefix, connect, struct \
    256             GNUNET_TESTING_CORE_ConnectState)
    257 
    258 GNUNET_CORE_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
    259                                    GNUNET_CORE_TESTING)
    260 
    261 
    262 #endif