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

Go to the source code of this file.

Data Structures

struct  ChannelCount
 
struct  RecvState
 

Macros

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

Functions

static void handle_msg_test (void *cls, struct GNUNET_TESTING_CORE_Channel *channel, const struct GNUNET_TESTING_CORE_Message *msg)
 
static void do_finish_cmd_delayed (void *cls)
 
static void remove_recv_handler (struct GNUNET_TESTING_CORE_ConnectState *connect_state)
 
static void exec_recv_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 
static void exec_recv_cleanup (void *cls)
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_CORE_cmd_recv (const char *label, uint64_t num_messages)
 

Macro Definition Documentation

◆ LOG

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

Generic logging shortcut.

Definition at line 37 of file testing_core_cmd_recv.c.

Function Documentation

◆ handle_msg_test()

static void handle_msg_test ( void *  cls,
struct GNUNET_TESTING_CORE_Channel channel,
const struct GNUNET_TESTING_CORE_Message msg 
)
static

Definition at line 116 of file testing_core_cmd_recv.c.

119{
120 //struct ChannelCount *channel_count = cls;
121 struct RecvState *rs = cls;
122 struct ChannelCount *channel_count;
123 uint32_t channel_i;
124 uint64_t num_messages_received;
125 uint64_t num_messages_target;
127
128 LOG (GNUNET_ERROR_TYPE_INFO, "received test message %" PRIu64 " (%" PRIu64 ") %s\n",
129 GNUNET_ntohll (msg->id),
130 GNUNET_ntohll (msg->batch),
131 msg->node_id);
132
133 /* First, find the channel count struct with the channel over which we
134 * received this message */
135 channel_count = NULL;
136 channel_i = rs->num_channels; /* For error checking -
137 should be overwritten in the following loop. */
138 for (uint32_t i = 0; i<rs->num_channels; i++)
139 {
140 struct ChannelCount *channel_count_iter = &rs->channel_count[i];
141 if (NULL == channel_count_iter->channel)
142 {
143 channel_count = channel_count_iter;
144 channel_count->channel = channel;
145 channel_count->rs = rs;
146 channel_i = i;
147 break;
148 }
149 else if (channel == channel_count_iter->channel)
150 {
151 channel_count = channel_count_iter;
152 channel_i = i;
153 break;
154 }
155 // else: continue until suitable channel count structure is found
156 }
157 if (NULL == channel_count)
158 {
159 /* no suitable channel was found -> add this channel */
162 rs->num_channels + 1);
163 channel_count = &rs->channel_count[rs->num_channels - 1];
164 channel_count->channel = channel;
165 channel_count->rs = rs;
166 channel_i = rs->num_channels;
167 }
168
169 /* Then update number of received messages */
170 channel_count->num_messages_received++;
171
172 /* Finally check if this and then other channels received the correct amount
173 * potentially finish. */
175 num_messages_target = channel_count->rs->num_messages_target;
177 "Received %" PRIu64 " messages (of %" PRIu64 " on channel %" PRIu32 ")\n",
179 num_messages_target,
180 channel_i);
181 if (num_messages_target > num_messages_received) return;
182 if (num_messages_target < num_messages_received) GNUNET_assert (0);
183 //if (num_messages_target == num_messages_received)
184 // GNUNET_TESTING_async_finish (&rs->ac);
185 ret = GNUNET_YES;
186 for (uint32_t i = 0; i < rs->num_channels; i++)
187 {
188 channel_count = &rs->channel_count[i];
189 if (channel_count->num_messages_received != rs->num_messages_target)
190 ret = GNUNET_NO;
191 }
192 if (GNUNET_YES == ret)
193 {
194 LOG (GNUNET_ERROR_TYPE_INFO, "Received all expected messages on all channels\n");
196 // TODO do we want to keep track of this task?
197 /* If we finish this task, this ARM will shut down this peer, taking with
198 * it core and with it all the messages still in transit.
199 * Adding a bit of delay gives the other peer a chance to still receive
200 * them.
201 * This might be done nicer - via a barrier? Check the other node's receive
202 * state?
203 * The number of 3 Milliseconds was chosen by looking at logs and then
204 * continuously runnint the test and seeing how many actually work reliably
205 * (Increased it quite a bit in the end for valgrind - no repeated tests
206 * this time.)
207 */
211 rs);
212 }
213}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int ret
Final status code.
Definition: gnunet-arm.c:93
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:486
uint64_t num_messages_received
struct GNUNET_TESTING_CORE_Channel * channel
struct RecvState * rs
uint64_t num_messages_target
struct GNUNET_TESTING_CORE_ConnectState * connect_state
uint32_t num_channels
struct ChannelCount * channel_count
#define LOG(kind,...)
Generic logging shortcut.
static void remove_recv_handler(struct GNUNET_TESTING_CORE_ConnectState *connect_state)
static void do_finish_cmd_delayed(void *cls)

References ChannelCount::channel, RecvState::channel_count, RecvState::connect_state, do_finish_cmd_delayed(), GNUNET_array_grow, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NO, GNUNET_ntohll(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_YES, LOG, msg, RecvState::num_channels, ChannelCount::num_messages_received, RecvState::num_messages_target, remove_recv_handler(), ret, and ChannelCount::rs.

Referenced by exec_recv_run(), and remove_recv_handler().

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

◆ do_finish_cmd_delayed()

static void do_finish_cmd_delayed ( void *  cls)
static

Definition at line 69 of file testing_core_cmd_recv.c.

70{
71 struct RecvState *rs = cls;
72
73 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finishing test delayed\n");
75 GNUNET_free (rs);
76}
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TESTING_AsyncContext ac

References RecvState::ac, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_TESTING_async_finish(), and LOG.

Referenced by handle_msg_test().

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

◆ remove_recv_handler()

static void remove_recv_handler ( struct GNUNET_TESTING_CORE_ConnectState connect_state)
static

Definition at line 80 of file testing_core_cmd_recv.c.

81{
82 LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing recv handler\n");
83 for (uint64_t i = 0; i < connect_state->recv_handlers_len; i++)
84 {
85 if (&handle_msg_test == connect_state->recv_handlers[i])
86 {
87 // FIXME this is the dirty solution. The attempt below did for whatever
88 // reason not work.
89 connect_state->recv_handlers[i] = NULL;
90 //LOG (GNUNET_ERROR_TYPE_DEBUG,
91 // "recv handlers[0]: %p, handle_msg_test: %p, (%lu)\n",
92 // connect_state->recv_handlers[0],
93 // &handle_msg_test,
94 // sizeof (&handle_msg_test));
95 //LOG (GNUNET_ERROR_TYPE_DEBUG,
96 // "recv handlers: %p, %" PRIu64 "\n",
97 // connect_state->recv_handlers,
98 // connect_state->recv_handlers_len);
99 //GNUNET_memcpy (&connect_state->recv_handlers[i],
100 // &connect_state->recv_handlers[i+1],
101 // (connect_state->connect_cbs_len - i - 1) *
102 // sizeof (handle_msg_test));
103 //LOG (GNUNET_ERROR_TYPE_DEBUG,
104 // "recv handlers: %p, %" PRIu64 "\n",
105 // connect_state->recv_handlers,
106 // connect_state->recv_handlers_len);
107 //GNUNET_array_grow (connect_state->recv_handlers,
108 // connect_state->recv_handlers_len,
109 // connect_state->recv_handlers_len - 1);
110 }
111 }
112}
GNUNET_TESTING_CORE_handle_msg * recv_handlers
Receive callback.
static void handle_msg_test(void *cls, struct GNUNET_TESTING_CORE_Channel *channel, const struct GNUNET_TESTING_CORE_Message *msg)

References RecvState::connect_state, GNUNET_ERROR_TYPE_DEBUG, handle_msg_test(), LOG, GNUNET_TESTING_CORE_ConnectState::recv_handlers, and GNUNET_TESTING_CORE_ConnectState::recv_handlers_len.

Referenced by handle_msg_test().

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

◆ exec_recv_run()

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

Definition at line 217 of file testing_core_cmd_recv.c.

219{
220 struct RecvState *rs = cls;
221 const struct GNUNET_TESTING_CORE_ConnectState *connect_state;
222
224 // TODO make the "connect" an input to the command
226 &connect_state)) {
227 GNUNET_assert (0);
228 };
229 rs->connect_state = connect_state;
230 // FIXME: set cls per hanlder
231 GNUNET_array_append (connect_state->recv_handlers,
232 connect_state->recv_handlers_len,
234 // FIXME is the following ok?
235 ((struct GNUNET_TESTING_CORE_ConnectState *)connect_state)->recv_handlers_cls = rs;
236}
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
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).

References RecvState::connect_state, GNUNET_array_append, GNUNET_assert, GNUNET_CORE_TESTING_get_trait_connect(), GNUNET_OK, GNUNET_TESTING_interpreter_lookup_command(), handle_msg_test(), is, GNUNET_TESTING_CORE_ConnectState::recv_handlers, and GNUNET_TESTING_CORE_ConnectState::recv_handlers_len.

Referenced by GNUNET_TESTING_CORE_cmd_recv().

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

◆ exec_recv_cleanup()

static void exec_recv_cleanup ( void *  cls)
static

Definition at line 240 of file testing_core_cmd_recv.c.

241{
242 //struct RecvState *rs = cls;
243 // TODO
244
245 //GNUNET_free (rs->channel_count);
246 //GNUNET_free (rs);
247}

Referenced by GNUNET_TESTING_CORE_cmd_recv().

Here is the caller graph for this function:

◆ GNUNET_TESTING_CORE_cmd_recv()

const struct GNUNET_TESTING_Command GNUNET_TESTING_CORE_cmd_recv ( const char *  label,
uint64_t  num_messages 
)

Definition at line 251 of file testing_core_cmd_recv.c.

254{
255 struct RecvState *rs;
256
257 // TODO this could be a static global variable
258 rs = GNUNET_new (struct RecvState);
259 rs->num_channels = 0;
261 rs->num_messages_target = num_messages;
262 LOG (GNUNET_ERROR_TYPE_DEBUG, "(Setting up _cmd_recv)\n");
264 rs, // state
265 label,
268 NULL, // traits
269 &rs->ac); // FIXME
270}
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command that may be asynchronous.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
static void exec_recv_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
static void exec_recv_cleanup(void *cls)

References RecvState::ac, RecvState::channel_count, exec_recv_cleanup(), exec_recv_run(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_new_array, GNUNET_TESTING_command_new_ac(), LOG, RecvState::num_channels, and RecvState::num_messages_target.

Here is the call graph for this function: