gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_testing_transport_lib.h (6461B)


      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 transport sub system.
     23  * @author t3sserakt
     24  */
     25 #ifndef GNUNET_TRANSPORT_TESTING_NG_LIB_H
     26 #define GNUNET_TRANSPORT_TESTING_NG_LIB_H
     27 
     28 
     29 #include "gnunet_util_lib.h"
     30 #include "gnunet_testing_lib.h"
     31 
     32 /**
     33  * Application handle; FIXME: what exactly is this?
     34  */
     35 struct GNUNET_TRANSPORT_ApplicationHandle;
     36 
     37 
     38 // FIXME: breaks naming conventions
     39 typedef void *
     40 (*GNUNET_TESTING_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is,
     41                                      const struct GNUNET_PeerIdentity *peer);
     42 
     43 
     44 // FIXME: breaks naming conventions! Needed public?
     45 struct GNUNET_TESTING_StartPeerState
     46 {
     47   /**
     48    * Context for our asynchronous completion.
     49    */
     50   struct GNUNET_TESTING_AsyncContext ac;
     51 
     52   /**
     53    * The ip of a node.
     54    */
     55   char *node_ip;
     56 
     57   /**
     58    * Receive callback
     59    */
     60   struct GNUNET_MQ_MessageHandler *handlers;
     61 
     62   /**
     63    * GNUnet configuration file used to start a peer.
     64    */
     65   char *cfgname;
     66 
     67   /**
     68    * Peer's configuration
     69    */
     70   struct GNUNET_CONFIGURATION_Handle *cfg;
     71 
     72   /**
     73    * struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure.
     74    */
     75   struct GNUNET_TESTING_Peer *peer;
     76 
     77   /**
     78    * Peer identity
     79    */
     80   struct GNUNET_PeerIdentity id;
     81 
     82   /**
     83    * Peer's transport service handle
     84    */
     85   struct GNUNET_TRANSPORT_CoreHandle *th;
     86 
     87   /**
     88    * Application handle
     89    */
     90   struct GNUNET_TRANSPORT_ApplicationHandle *ah;
     91 
     92   /**
     93    * Peer's PEERSTORE Handle
     94    */
     95   struct GNUNET_PEERSTORE_Handle *ph;
     96 
     97   /**
     98    * Hello get task
     99    */
    100   struct GNUNET_SCHEDULER_Task *rh_task;
    101 
    102   /**
    103    * Peer's transport get hello handle to retrieve peer's HELLO message
    104    */
    105   struct GNUNET_PEERSTORE_IterateContext *pic;
    106 
    107   /**
    108    * Task to search for log entry indicating the communicators started.
    109    */
    110   struct GNUNET_SCHEDULER_Task *log_task;
    111 
    112   /**
    113    * Task to start the request for the list of services.
    114    */
    115   struct GNUNET_SCHEDULER_Task *request_task;
    116 
    117   /**
    118    * Arm operation to get a list of the services, to check if all started.
    119    */
    120   struct GNUNET_ARM_Operation *op;
    121 
    122   /**
    123    * Handle for the arm service.
    124    */
    125   struct GNUNET_ARM_Handle *h;
    126 
    127   /**
    128    * Stream to read log file lines.
    129    */
    130   FILE *stream;
    131 
    132   /**
    133    * File handle for log file.
    134    */
    135   struct GNUNET_DISK_FileHandle *fh;
    136   
    137   /**
    138    * Flag indicating, if there are services not started completely.
    139    */
    140   enum GNUNET_GenericReturnValue not_all_started;
    141 
    142   /**
    143    * Flag indicating if all (udp and tcp) communicators connected to transport service.
    144    */
    145   enum GNUNET_GenericReturnValue coms_started;
    146 
    147   /**
    148    * Number of communicators connecteds with transport service.
    149    */
    150   unsigned int num_coms_started;
    151   
    152   /**
    153    * Hello
    154    */
    155   char *hello;
    156 
    157   /**
    158    * Hello size
    159    */
    160   size_t hello_size;
    161 
    162   /**
    163    * The label of the command which was started by calling GNUNET_TESTING_cmd_system_create.
    164    */
    165   char *system_label;
    166 
    167   /**
    168    * An unique number to identify the peer
    169    */
    170   unsigned int no;
    171 
    172   /**
    173    * A map with struct GNUNET_MQ_Handle values for each peer this peer
    174    * is connected to.
    175    */
    176   struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
    177 
    178   /**
    179    * Test setup for this peer.
    180    */
    181   const struct GNUNET_TESTING_System *tl_system;
    182 
    183   /**
    184    * Callback which is called on neighbour connect events.
    185    */
    186   GNUNET_TESTING_notify_connect_cb notify_connect;
    187 
    188   /**
    189    * Flag indicating, if udp broadcast should be switched on.
    190    */
    191   enum GNUNET_GenericReturnValue broadcast;
    192 };
    193 
    194 
    195 /**
    196  * Create command.
    197  *
    198  * @param label name for command.
    199  * @param system_label Label of the cmd to setup a test environment.
    200  * @param no Decimal number representing the last byte of the IP address of this peer.
    201  * @param node_ip The IP address of this node.
    202  * @param cfgname Configuration file name for this peer.
    203  * @param broadcast Flag indicating, if broadcast should be switched on.
    204  * @return command.
    205  */
    206 struct GNUNET_TESTING_Command
    207 GNUNET_TESTING_cmd_start_peer (const char *label,
    208                                const char *system_label,
    209                                uint32_t no,
    210                                const char *node_ip,
    211                                const char *cfgname,
    212                                unsigned int broadcast);
    213 
    214 
    215 struct GNUNET_TESTING_Command
    216 GNUNET_TESTING_cmd_stop_peer (const char *label,
    217                               const char *start_label);
    218 
    219 
    220 /**
    221  * Retrieve peer identity from the test system with the unique node id.
    222  *
    223  * @param num The unique node id.
    224  * @param tl_system The test system.
    225  * @return The peer identity wrapping the public key.
    226  */
    227 struct GNUNET_PeerIdentity *
    228 GNUNET_TESTING_get_peer (unsigned int num,
    229                          const struct GNUNET_TESTING_System *tl_system);
    230 
    231 
    232 /**
    233  * Call #op on all simple traits.
    234  */
    235 #define GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS(op, prefix)                         \
    236         op (prefix, connected_peers_map, const struct \
    237             GNUNET_CONTAINER_MultiShortmap)    \
    238         op (prefix, peer_id, const struct GNUNET_PeerIdentity)                           \
    239         op (prefix, hello_size, const size_t)                                            \
    240         op (prefix, hello, const char)                                                   \
    241         op (prefix, application_handle, const struct \
    242             GNUNET_TRANSPORT_ApplicationHandle) \
    243         op (prefix, state, const struct GNUNET_TESTING_StartPeerState)                   \
    244         op (prefix, broadcast, const enum GNUNET_GenericReturnValue)
    245 
    246 
    247 GNUNET_TRANSPORT_TESTING_SIMPLE_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT,
    248                                         GNUNET_TRANSPORT_TESTING)
    249 
    250 #endif