GNUnet  0.11.x
Data Structures | Macros | Functions
transport_api_cmd_connecting_peers_v2.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "gnunet_transport_application_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_transport_service.h"
#include "transport-testing-cmds.h"
Include dependency graph for transport_api_cmd_connecting_peers_v2.c:

Go to the source code of this file.

Data Structures

struct  ConnectPeersState
 Struct to store information needed in callbacks. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 Generic logging shortcut. More...
 
#define CONNECT_ADDRESS_TEMPLATE   "tcp-192.168.15.%u:60002"
 

Functions

static void connect_peers_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 The run method of this cmd will connect to peers. More...
 
static int connect_peers_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
 The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer. More...
 
static int connect_peers_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 Trait function of this cmd does nothing. More...
 
static void connect_peers_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label, const char *start_peer_label, const char *create_label, uint32_t num)
 Create command. More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Generic logging shortcut.

Definition at line 37 of file transport_api_cmd_connecting_peers_v2.c.

◆ CONNECT_ADDRESS_TEMPLATE

#define CONNECT_ADDRESS_TEMPLATE   "tcp-192.168.15.%u:60002"

Definition at line 39 of file transport_api_cmd_connecting_peers_v2.c.

Function Documentation

◆ connect_peers_run()

static void connect_peers_run ( void *  cls,
const struct GNUNET_TESTING_Command cmd,
struct GNUNET_TESTING_Interpreter is 
)
static

The run method of this cmd will connect to peers.

Definition at line 75 of file transport_api_cmd_connecting_peers_v2.c.

78 {
79  struct ConnectPeersState *cps = cls;
80  const struct GNUNET_TESTING_Command *system_cmd;
81  struct GNUNET_TESTING_System *tl_system;
82  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
84  struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
86  const struct GNUNET_TESTING_Command *peer1_cmd;
89  char *addr;
90  enum GNUNET_NetworkType nt = 0;
91  struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
92  uint32_t num;
93 
96  &ah);
97 
100  &tl_system);
101 
102  if (1 == cps->num)
103  {
104  num = 2;
105  // addr = "tcp-192.168.15.2:60002";
106  }
107  else
108  {
109  num = 1;
110  // addr = "tcp-192.168.15.1:60002";
111  }
112 
113  GNUNET_asprintf (&addr,
115  num);
116 
117  priv_key = GNUNET_TESTING_hostkey_get (tl_system,
118  num,
119  other);
120 
122  pub_key);
123 
124 
125  peer->public_key = *pub_key;
126 
128  "num: %u pub_key %s\n",
129  num,
131 
132  cps->id = peer;
133 
135  peer,
136  nt,
137  addr);
138 }
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:251
int GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_System **test_system)
Function to get the trait with struct GNUNET_TESTING_System.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
void GNUNET_TRANSPORT_application_validate(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
An application (or a communicator) has received a HELLO (or other address data of another peer) and w...
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:197
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:36
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:704
Struct to store information needed in callbacks.
const char * start_peer_label
Label of the cmd to start a peer.
uint32_t num
Number globally identifying the node.
struct GNUNET_PeerIdentity * id
The peer identity of this peer.
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
The identity of the host (wraps the signing key of the peer).
A command to be run by the interpreter.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:93
Handle to the TRANSPORT subsystem for application management.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int GNUNET_TRANSPORT_get_trait_application_handle_v2(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TRANSPORT_ApplicationHandle **ah)
Function to get the trait with the transport application handle.
#define LOG(kind,...)
Generic logging shortcut.
#define CONNECT_ADDRESS_TEMPLATE

References ah, CONNECT_ADDRESS_TEMPLATE, ConnectPeersState::create_label, GNUNET_asprintf(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_new, GNUNET_TESTING_get_trait_test_system(), GNUNET_TESTING_hostkey_get(), GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TRANSPORT_application_validate(), GNUNET_TRANSPORT_get_trait_application_handle_v2(), ConnectPeersState::id, LOG, nt, ConnectPeersState::num, peer, and ConnectPeersState::start_peer_label.

Here is the call graph for this function:

◆ connect_peers_finish()

static int connect_peers_finish ( void *  cls,
GNUNET_SCHEDULER_TaskCallback  cont,
void *  cont_cls 
)
static

The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer.

Definition at line 146 of file transport_api_cmd_connecting_peers_v2.c.

149 {
150  struct ConnectPeersState *cps = cls;
151  const struct GNUNET_TESTING_Command *peer1_cmd;
152  struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
153  unsigned int ret;
155  struct GNUNET_HashCode hc;
156  int node_number;
157 
160  &connected_peers_map);
161 
162  node_number = 1;
163  GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
164 
165  // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
166  memcpy (key,
167  &hc,
168  sizeof (*key));
169  ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
170  key);
171 
172  if (GNUNET_YES == ret)
173  {
174  cont (cont_cls);
175  }
176 
177  GNUNET_free (key);
178  return ret;
179 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_YES
Definition: gnunet_common.h:97
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
int GNUNET_CONTAINER_multishortmap_contains(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
#define GNUNET_free(ptr)
Wrapper around free.
Internal representation of the hash map.
A 512-bit hashcode.
A 256-bit hashcode.
int GNUNET_TRANSPORT_get_trait_connected_peers_map_v2(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_CONTAINER_MultiShortmap **connected_peers_map)
Function to get the trait with the map of connected peers.

References GNUNET_CONTAINER_multishortmap_contains(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_new, GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TRANSPORT_get_trait_connected_peers_map_v2(), GNUNET_YES, key, ret, and ConnectPeersState::start_peer_label.

Here is the call graph for this function:

◆ connect_peers_traits()

static int connect_peers_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

Trait function of this cmd does nothing.

Definition at line 187 of file transport_api_cmd_connecting_peers_v2.c.

191 {
192  return GNUNET_OK;
193 }
@ GNUNET_OK
Definition: gnunet_common.h:95

References GNUNET_OK.

◆ connect_peers_cleanup()

static void connect_peers_cleanup ( void *  cls,
const struct GNUNET_TESTING_Command cmd 
)
static

The cleanup function of this cmd frees resources the cmd allocated.

Definition at line 201 of file transport_api_cmd_connecting_peers_v2.c.

203 {
204  struct ConnectPeersState *cps = cls;
205 
206  GNUNET_free (cps->id);
207  GNUNET_free (cps);
208 }

References GNUNET_free, and ConnectPeersState::id.

◆ GNUNET_TRANSPORT_cmd_connect_peers_v2()

struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers_v2 ( const char *  label,
const char *  start_peer_label,
const char *  create_label,
uint32_t  num 
)

Create command.

Parameters
labelname for command.
start_peer_labelLabel of the cmd to start a peer.
Returns
command.

Definition at line 201 of file transport_api_cmd_connecting_peers_v2.c.

223 {
224  struct ConnectPeersState *cps;
225 
226  cps = GNUNET_new (struct ConnectPeersState);
228  cps->num = num;
229  cps->create_label = create_label;
230 
231 
232  struct GNUNET_TESTING_Command cmd = {
233  .cls = cps,
234  .label = label,
235  .run = &connect_peers_run,
236  .finish = &connect_peers_finish,
237  .cleanup = &connect_peers_cleanup,
238  .traits = &connect_peers_traits
239  };
240 
241  return cmd;
242 }
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
static void connect_peers_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
static int connect_peers_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
static int connect_peers_finish(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
The finish function of this cmd will check if the peer we are trying to connect to is in the connecte...
static void connect_peers_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will connect to peers.