GNUnet debian-0.24.3-23-g589b01d60
testing_core_cmd_send.c File Reference
Include dependency graph for testing_core_cmd_send.c:

Go to the source code of this file.

Data Structures

struct  SendState
 State for the 'send' command. More...
 

Macros

#define LOG(kind, ...)    GNUNET_log_from (kind, "testing-core-send", __VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

static void * connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer_id, struct GNUNET_MQ_Handle *mq)
 
static void cleanup_callbacks (struct SendState *send_state)
 
static void send_messages (struct SendState *send_state)
 
static void exec_send_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 
static void exec_send_cleanup (void *cls)
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_CORE_cmd_send (const char *label, uint64_t num_messages, enum GNUNET_GenericReturnValue await_new_connection)
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)     GNUNET_log_from (kind, "testing-core-send", __VA_ARGS__)

Generic logging shortcut.

Definition at line 37 of file testing_core_cmd_send.c.

Function Documentation

◆ connect_cb()

static void * connect_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer_id,
struct GNUNET_MQ_Handle mq 
)
static

Definition at line 135 of file testing_core_cmd_send.c.

139{
140 struct SendState *send_state = cls;
141
142 send_messages (send_state);
143 // FIXME this returns something but the calling function discards the
144 // returned value anyways
145 return NULL;
146}
State for the 'send' command.
static void send_messages(struct SendState *send_state)

References send_messages().

Referenced by cleanup_callbacks(), and exec_send_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_callbacks()

static void cleanup_callbacks ( struct SendState send_state)
static

Definition at line 56 of file testing_core_cmd_send.c.

57{
58 const struct GNUNET_TESTING_CORE_ConnectState *connect_state =
59 send_state->connect_state;
60 struct GNUNET_TESTING_CORE_ConnectCb *connect_cb_iter;
61
62 for (uint64_t i = 0; i < connect_state->connect_cbs_len; i++)
63 {
64 connect_cb_iter = &connect_state->connect_cbs[i];
65 if (connect_cb == connect_cb_iter->callback)
66 {
67 /* remove the callback */
68 GNUNET_memcpy (connect_cb_iter,
69 connect_cb_iter + 1,
70 (connect_state->connect_cbs_len - i - 1) *
71 sizeof (struct GNUNET_TESTING_CORE_ConnectCb));
72 GNUNET_array_grow (connect_state->connect_cbs,
73 connect_state->connect_cbs_len,
74 connect_state->connect_cbs_len - 1);
75 //FIXME the following seems to be a double free, but I currently don't
76 //know where the other free should be
77 //GNUNET_free (connect_cb_iter);
78 }
79 }
80}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
GNUNET_TESTING_CORE_connect_cb callback
struct GNUNET_TESTING_CORE_ConnectCb * connect_cbs
Connect callback TODO we probably only need a single one.
const struct GNUNET_TESTING_CORE_ConnectState * connect_state
static void * connect_cb(void *cls, const struct GNUNET_PeerIdentity *peer_id, struct GNUNET_MQ_Handle *mq)

References GNUNET_TESTING_CORE_ConnectCb::callback, connect_cb(), GNUNET_TESTING_CORE_ConnectState::connect_cbs, GNUNET_TESTING_CORE_ConnectState::connect_cbs_len, SendState::connect_state, GNUNET_array_grow, and GNUNET_memcpy.

Referenced by send_messages().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_messages()

static void send_messages ( struct SendState send_state)
static

Definition at line 84 of file testing_core_cmd_send.c.

85{
86 const struct GNUNET_TESTING_CORE_ConnectState *connect_state =
87 send_state->connect_state;
88 struct GNUNET_MQ_Envelope *env;
90 struct GNUNET_TESTING_CORE_Channel *channel_iter;
91 uint64_t channel_index = 0;
92
94 "Going to send %" PRIu64 " messages\n",
95 send_state->num_messages);
97 /* For now send on all available channels as we don't know at this stage
98 * which is an usable channel - this should be fine as the unusable channel
99 * will (probably) be discoverd and cleand up in the process. */
100 for (channel_iter = connect_state->channels_head;
101 NULL != channel_iter;
102 channel_iter = channel_iter->next)
103 {
104 for (uint64_t i = 0; i < send_state->num_messages; i++)
105 {
107 "Going to send message (type %u) %" PRIu64 ", %s (channel %" PRIu64 ") to %s\n",
108 MTYPE,
109 i,
111 channel_index,
112 GNUNET_i2s (&channel_iter->peer_id));
113 env = GNUNET_MQ_msg (msg, MTYPE); // usually we wanted to keep the
114 // envelopes to potentially cancel the
115 // message
116 msg->id = GNUNET_htonll (i);
117 msg->batch = GNUNET_htonll (channel_index);
119 GNUNET_MQ_send (channel_iter->mq, env);
121 "Sent message %" PRIu64 " (channel %" PRIu64 ")\n",
122 i,
123 channel_index);
124 }
125 channel_index++;
126 }
127 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent messages\n");
128
129 cleanup_callbacks (send_state);
130 GNUNET_free (send_state);
131}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define MTYPE
API for cmds working with core sub system provided by libgnunetcoretesting.
#define NODE_ID_LEN
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
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:305
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
struct GNUNET_MQ_Handle * mq
struct GNUNET_TESTING_CORE_ConnectState * connect_state
struct GNUNET_PeerIdentity peer_id
struct GNUNET_TESTING_CORE_Channel * next
struct GNUNET_TESTING_CORE_Channel * channels_head
uint64_t num_messages
static void cleanup_callbacks(struct SendState *send_state)
#define LOG(kind,...)
Generic logging shortcut.

References GNUNET_TESTING_CORE_ConnectState::channels_head, cleanup_callbacks(), GNUNET_TESTING_CORE_Channel::connect_state, SendState::connect_state, env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_htonll(), GNUNET_i2s(), GNUNET_memcpy, GNUNET_MQ_msg, GNUNET_MQ_send(), LOG, GNUNET_TESTING_CORE_Channel::mq, msg, MTYPE, GNUNET_TESTING_CORE_Channel::next, GNUNET_TESTING_CORE_ConnectState::node_id, NODE_ID_LEN, SendState::num_messages, and GNUNET_TESTING_CORE_Channel::peer_id.

Referenced by connect_cb(), and exec_send_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_send_run()

static void exec_send_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

Definition at line 150 of file testing_core_cmd_send.c.

152{
153 struct SendState *send_state = cls;
154 const struct GNUNET_TESTING_CORE_ConnectState *connect_state;
155
156 // TODO make the "connect" label an input to the command
159 &connect_state)) {
160 GNUNET_assert (0);
161 };
162 send_state->connect_state = connect_state;
163
164 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to (register to) send messages\n");
165
166 if ((NULL != connect_state->channels_head) &&
167 (GNUNET_NO == send_state->await_new_connection))
168 {
169 /* We are connected to a peer - send messages */
170 send_messages (send_state);
171 }
172 else
173 {
174 /* We are not connected yet - subscribe via callback */
175 // FIXME is the following ok?
176 struct GNUNET_TESTING_CORE_ConnectCb *connect_cb_struct =
178 LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering our connect callback with the connect callbacks\n");
179 connect_cb_struct->callback = connect_cb;
180 connect_cb_struct->cls = send_state;
181 GNUNET_array_append (connect_state->connect_cbs,
182 connect_state->connect_cbs_len,
183 *connect_cb_struct);
184 }
185}
static struct GNUNET_TESTING_Interpreter * is
enum GNUNET_GenericReturnValue GNUNET_CORE_TESTING_get_trait_connect(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_CORE_ConnectState **ret)
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
@ GNUNET_OK
@ GNUNET_NO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
enum GNUNET_GenericReturnValue await_new_connection

References SendState::await_new_connection, GNUNET_TESTING_CORE_ConnectCb::callback, GNUNET_TESTING_CORE_ConnectState::channels_head, GNUNET_TESTING_CORE_ConnectCb::cls, connect_cb(), GNUNET_TESTING_CORE_ConnectState::connect_cbs, GNUNET_TESTING_CORE_ConnectState::connect_cbs_len, SendState::connect_state, GNUNET_array_append, GNUNET_assert, GNUNET_CORE_TESTING_get_trait_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_TESTING_interpreter_lookup_command(), is, LOG, and send_messages().

Referenced by GNUNET_TESTING_CORE_cmd_send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_send_cleanup()

static void exec_send_cleanup ( void *  cls)
static

Definition at line 189 of file testing_core_cmd_send.c.

190{
191 struct GNUNET_TESTING_CORE_ConnectState *connect_state = cls;
192
193}

Referenced by GNUNET_TESTING_CORE_cmd_send().

Here is the caller graph for this function:

◆ GNUNET_TESTING_CORE_cmd_send()

const struct GNUNET_TESTING_Command GNUNET_TESTING_CORE_cmd_send ( const char *  label,
uint64_t  num_messages,
enum GNUNET_GenericReturnValue  await_new_connection 
)

Definition at line 198 of file testing_core_cmd_send.c.

202{
203 struct SendState *send_state;
204
205 // TODO make struct static global?
206 send_state = GNUNET_new (struct SendState);
207 send_state->num_messages = num_messages;
209 LOG (GNUNET_ERROR_TYPE_DEBUG, "(Setting up _cmd_send)\n");
211 send_state, // state
212 label,
215 NULL);
216}
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)
Create a new command.
static void exec_send_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
static void exec_send_cleanup(void *cls)

References SendState::await_new_connection, exec_send_cleanup(), exec_send_run(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_TESTING_command_new, LOG, and SendState::num_messages.

Here is the call graph for this function: