GNUnet  0.11.x
Data Structures | Macros | Functions
transport_api_cmd_connecting_peers.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.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...
 

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 (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.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 73 of file transport_api_cmd_connecting_peers.c.

76 {
77  struct ConnectPeersState *cps = cls;
78  const struct GNUNET_TESTING_Command *system_cmd;
79  struct GNUNET_TESTING_System *tl_system;
80  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
82  struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
84  ;
85  const struct GNUNET_TESTING_Command *peer1_cmd;
86  // const struct GNUNET_TESTING_Command *peer2_cmd;
89  char *addr;
90  // struct GNUNET_TIME_Absolute t;
91  char *hello;
92  // size_t *hello_size;
93  enum GNUNET_NetworkType nt = 0;
94  char *peer_id;
95  struct GNUNET_PeerIdentity *id;
96  struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
97  uint32_t num;
98 
101  &ah);
102 
104  &hello);
105 
107  &id);
108 
111  &tl_system);
112 
113  if (2 == cps->num)
114  num = 1;
115  else
116  num = 2;
117 
118 
119 
120 
121  // if (strstr (hello, "60002") != NULL)
122  if (2 == num)
123  {
124  addr = "tcp-192.168.15.2:60002";
125  peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
126  }
127  else
128  {
129  addr = "tcp-192.168.15.1:60002";
130  peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
131  }
132 
133  priv_key = GNUNET_TESTING_hostkey_get (tl_system,
134  num,
135  other);
136 
138  pub_key);
139 
141  strlen (peer_id),
142  &peer->public_key);
143 
144  peer->public_key = *pub_key;
145 
147  "\nnum: %u\n peer_id: %s\n pub_key %s\n",
148  num,
149  peer_id,
151 
152  cps->id = peer;
153 
154  // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers.
155  // ---------------------------------------------
156  /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
157  GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd,
158  &id);
159  GNUNET_TRANSPORT_get_trait_hello (peer2_cmd,
160  &hello);
161  GNUNET_TRANSPORT_get_trait_hello_size (peer2_cmd,
162  &hello_size);
163 
164  addr = GNUNET_HELLO_extract_address (hello,
165  *hello_size,
166  id,
167  &nt,
168  &t);*/
169 
170  // ----------------------------------------------
171 
172 
174  peer,
175  nt,
176  addr);
177 }
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
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
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:357
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
#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_hello(const struct GNUNET_TESTING_Command *cmd, char **hello)
Function to get the trait with the hello.
int GNUNET_TRANSPORT_get_trait_peer_id(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_PeerIdentity **id)
Function to get the trait with the peer id.
int GNUNET_TRANSPORT_get_trait_application_handle(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.

References ah, ConnectPeersState::create_label, GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_public_key_from_string(), 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(), GNUNET_TRANSPORT_get_trait_hello(), GNUNET_TRANSPORT_get_trait_peer_id(), id, ConnectPeersState::id, LOG, nt, ConnectPeersState::num, peer, peer_id, 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 185 of file transport_api_cmd_connecting_peers.c.

188 {
189  struct ConnectPeersState *cps = cls;
190  const struct GNUNET_TESTING_Command *peer1_cmd;
191  struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
192  unsigned int ret;
194  struct GNUNET_HashCode hc;
195  int node_number;
196 
199  &connected_peers_map);
200 
201  node_number = 1;
202  GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
203 
204  // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
205  memcpy (key,
206  &hc,
207  sizeof (*key));
208  ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
209  key);
210 
211  if (GNUNET_YES == ret)
212  {
213  cont (cont_cls);
214  }
215 
216  GNUNET_free (key);
217  return ret;
218 }
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(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(), 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 226 of file transport_api_cmd_connecting_peers.c.

230 {
231  return GNUNET_OK;
232 }
@ 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 240 of file transport_api_cmd_connecting_peers.c.

242 {
243  struct ConnectPeersState *cps = cls;
244 
245  GNUNET_free (cps->id);
246  GNUNET_free (cps);
247 }

References GNUNET_free, and ConnectPeersState::id.

◆ GNUNET_TRANSPORT_cmd_connect_peers()

struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers ( 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 240 of file transport_api_cmd_connecting_peers.c.

262 {
263  struct ConnectPeersState *cps;
264 
265  cps = GNUNET_new (struct ConnectPeersState);
267  cps->num = num;
268  cps->create_label = create_label;
269 
270 
271  struct GNUNET_TESTING_Command cmd = {
272  .cls = cps,
273  .label = label,
274  .run = &connect_peers_run,
275  .finish = &connect_peers_finish,
276  .cleanup = &connect_peers_cleanup,
277  .traits = &connect_peers_traits
278  };
279 
280  return cmd;
281 }
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.