GNUnet  0.11.x
Data Structures | Functions
transport_api_cmd_send_simple_v2.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
#include "transport-testing2.h"
#include "transport-testing-cmds.h"
Include dependency graph for transport_api_cmd_send_simple_v2.c:

Go to the source code of this file.

Data Structures

struct  SendSimpleState
 Struct to hold information for callbacks. More...
 

Functions

static int send_simple_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 Trait function of this cmd does nothing. More...
 
static void send_simple_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
static void send_simple_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 The run method of this cmd will send a simple message to the connected peer. More...
 
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label, const char *start_peer_label, uint32_t num)
 Create command. More...
 

Function Documentation

◆ send_simple_traits()

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

Trait function of this cmd does nothing.

Definition at line 57 of file transport_api_cmd_send_simple_v2.c.

61 {
62  return GNUNET_OK;
63 }
@ GNUNET_OK
Definition: gnunet_common.h:95

References GNUNET_OK.

◆ send_simple_cleanup()

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

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

Definition at line 71 of file transport_api_cmd_send_simple_v2.c.

73 {
74  struct SendSimpleState *sss = cls;
75 
76  GNUNET_free (sss);
77 }
#define GNUNET_free(ptr)
Wrapper around free.
Struct to hold information for callbacks.

References GNUNET_free.

◆ send_simple_run()

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

The run method of this cmd will send a simple message to the connected peer.

Definition at line 85 of file transport_api_cmd_send_simple_v2.c.

88 {
89  struct SendSimpleState *sss = cls;
90  struct GNUNET_MQ_Envelope *env;
92  struct GNUNET_MQ_Handle *mq;
93  struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
94  const struct GNUNET_TESTING_Command *peer1_cmd;
96  struct GNUNET_HashCode hc;
97  int node_number;
98 
101  &connected_peers_map);
102 
103  node_number = 1;
104  GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
105  memcpy (key,
106  &hc,
107  sizeof (*key));
108 
109  mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
110  key);
111 
112  env = GNUNET_MQ_msg_extra (test,
113  2600 - sizeof(*test),
115  test->num = htonl (sss->num);
116  memset (&test[1],
117  sss->num,
118  2600 - sizeof(*test));
120  env);
121  GNUNET_free (key);
122 
123 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_HashCode key
The key used in the DHT.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
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
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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:355
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:52
Internal representation of the hash map.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:86
A 256-bit hashcode.
A command to be run by the interpreter.
uint32_t num
Monotonically increasing counter throughout the test.
const char * start_peer_label
Label of the cmd to start a peer.
uint32_t num
Number globally identifying the node.
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.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().

References env, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TRANSPORT_get_trait_connected_peers_map(), GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, key, mq, GNUNET_TRANSPORT_TESTING_TestMessage::num, SendSimpleState::num, and SendSimpleState::start_peer_label.

Here is the call graph for this function:

◆ GNUNET_TRANSPORT_cmd_send_simple_v2()

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

Create command.

Parameters
labelname for command.
mThe number of the local node of the actual network namespace.
nThe number of the actual namespace.
numNumber globally identifying the node.
start_peer_labelLabel of the cmd to start a peer.
Returns
command.

Definition at line 85 of file transport_api_cmd_send_simple_v2.c.

140 {
141  struct SendSimpleState *sss;
142 
143  sss = GNUNET_new (struct SendSimpleState);
144  sss->num = num;
146 
147  struct GNUNET_TESTING_Command cmd = {
148  .cls = sss,
149  .label = label,
150  .run = &send_simple_run,
151  .cleanup = &send_simple_cleanup,
152  .traits = &send_simple_traits
153  };
154 
155  return cmd;
156 }
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
static void send_simple_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
static void send_simple_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will send a simple message to the connected peer.
static int send_simple_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.