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

Go to the source code of this file.

Macros

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

Functions

static void handle_test (void *cls, const struct GNUNET_TESTING_CORE_Message *msg)
 
static enum GNUNET_GenericReturnValue connect_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 This function prepares an array with traits. More...
 
static void init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
 
static void * connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer_id, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
 
static void disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
 
static void exec_connect_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 
static void exec_connect_cleanup (void *cls)
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_CORE_cmd_connect (const char *label, const char *node_id, char *arm_service_label)
 

Macro Definition Documentation

◆ MTYPE

#define MTYPE   12345

Definition at line 38 of file testing_core_cmd_connect.c.

◆ LOG

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

Generic logging shortcut.

Definition at line 43 of file testing_core_cmd_connect.c.

Function Documentation

◆ handle_test()

static void handle_test ( void *  cls,
const struct GNUNET_TESTING_CORE_Message msg 
)
static

Definition at line 48 of file testing_core_cmd_connect.c.

49{
50 struct GNUNET_TESTING_CORE_Channel *channel = cls;
51
53 "Received message (%" PRIu64 ", %" PRIu64 ", %s) - going to call handlers\n",
54 GNUNET_ntohll (msg->id),
55 GNUNET_ntohll (msg->batch),
56 msg->node_id);
57 LOG (GNUNET_ERROR_TYPE_DEBUG, " (We: %s)\n", channel->connect_state->node_id);
58
59 if (0 == strncmp (msg->node_id, channel->connect_state->node_id, NODE_ID_LEN))
61 "We received a message from ourself!\n");
62
63 for (uint32_t i = 0; i < channel->connect_state->recv_handlers_len; i++)
64 {
65 if (NULL == channel->connect_state->recv_handlers[i]) continue;
66 // FIXME: set cls per handler
67 channel->connect_state->recv_handlers[i] (
69 channel,
70 msg);
71 }
72
73 // FIXME do we need to call something like the below?
74 //GNUNET_CORE_UNDERLAY_DUMMY_receive_continue (channel->connect_state->h,
75 // channel->mq);
76}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define NODE_ID_LEN
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
struct GNUNET_TESTING_CORE_ConnectState * connect_state
GNUNET_TESTING_CORE_handle_msg * recv_handlers
Receive callback.
#define LOG(kind,...)
Generic logging shortcut.

References GNUNET_TESTING_CORE_Channel::connect_state, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ntohll(), LOG, msg, GNUNET_TESTING_CORE_ConnectState::node_id, NODE_ID_LEN, GNUNET_TESTING_CORE_ConnectState::recv_handlers, GNUNET_TESTING_CORE_ConnectState::recv_handlers_cls, and GNUNET_TESTING_CORE_ConnectState::recv_handlers_len.

Here is the call graph for this function:

◆ connect_traits()

static enum GNUNET_GenericReturnValue connect_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

This function prepares an array with traits.

Definition at line 83 of file testing_core_cmd_connect.c.

87{
88 struct GNUNET_TESTING_CORE_ConnectState *connect_state = cls;
89 struct GNUNET_TESTING_Trait traits[] = {
92 };
93
95 ret,
96 trait,
97 index);
98}
static int ret
Final status code.
Definition: gnunet-arm.c:93
struct GNUNET_TESTING_Trait GNUNET_CORE_TESTING_make_trait_connect(const struct GNUNET_TESTING_CORE_ConnectState *value)
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_CORE_TESTING_make_trait_connect(), GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ret, and traits().

Referenced by GNUNET_TESTING_CORE_cmd_connect().

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

◆ init_cb()

static void init_cb ( void *  cls,
const struct GNUNET_PeerIdentity my_identity 
)
static

Definition at line 102 of file testing_core_cmd_connect.c.

105{
106 struct GNUNET_TESTING_CORE_ConnectState *connect_state = cls;
108 "Connected to core, own pid: %s\n",
110 GNUNET_memcpy (&connect_state->peer_id, my_identity, sizeof (struct GNUNET_PeerIdentity));
111 GNUNET_TESTING_async_finish (&connect_state->ac);
112 // TODO we could finish connect at the first incoming connection
113}
struct GNUNET_PeerIdentity my_identity
Our peer identity.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TESTING_AsyncContext ac

References GNUNET_TESTING_CORE_ConnectState::ac, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcpy, GNUNET_TESTING_async_finish(), LOG, my_identity, and GNUNET_TESTING_CORE_ConnectState::peer_id.

Referenced by exec_connect_run().

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

◆ connect_cb()

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

Definition at line 117 of file testing_core_cmd_connect.c.

122{
123 struct GNUNET_TESTING_CORE_ConnectState *connect_state = cls;
124 struct GNUNET_TESTING_CORE_Channel *channel;
125 (void) class; // unused
126
128 "A new connection was established with peer %s\n",
131 " (us: %s)\n",
134 "size of connect_state: %lu of channel: %lu\n",
135 sizeof (struct GNUNET_TESTING_CORE_ConnectState),
136 sizeof (struct GNUNET_TESTING_CORE_Channel));
138 "memcmp: %u\n",
142 " (That's us - connection was established to ourself)\n");
143
144 channel = GNUNET_new (struct GNUNET_TESTING_CORE_Channel);
145 channel->connect_state = connect_state;
146 channel->mq = mq;
147 GNUNET_memcpy (&channel->peer_id, peer_id, sizeof (struct GNUNET_PeerIdentity));
149 {
151 "Inserting channel into list\n");
152 if ((NULL != connect_state->channels_head) &&
153 (NULL != connect_state->channels_tail))
154 {
156 "Peer at list head: %s\n",
159 "Peer at list tail: %s\n",
161 }
162 else
163 {
165 "empty list\n");
166 }
169 channel);
170 }
171
172 /* Call connect handlers from test */
174 for (uint32_t i = 0; i < connect_state->connect_cbs_len; i++)
175 {
176 // TODO check if we really want to pass everything as-is
177 struct GNUNET_TESTING_CORE_ConnectCb *connect_cb_struct =
178 &connect_state->connect_cbs[i];
179 // FIXME this might return something, but the implemented function also
180 // returns nothing
181 connect_cb_struct->callback (connect_cb_struct->cls,
182 peer_id,
183 mq);
184 }
185
186 //if ((connect_state->num_channels_target == connect_state->channels_len) &&
187 // (GNUNET_NO == connect_state->finished))
188 //{
189 // LOG (GNUNET_ERROR_TYPE_DEBUG, "(post connect_cb _async_finish)\n");
190 // GNUNET_TESTING_async_finish (&connect_state->ac);
191 // connect_state->finished = GNUNET_YES;
192 //}
193 //LOG (GNUNET_ERROR_TYPE_DEBUG,
194 // "(post connect_cb - %u of %u)\n",
195 // connect_state->channels_len,
196 // connect_state->num_channels_target);
197
198 return channel;
199}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MQ_Handle * mq
struct GNUNET_PeerIdentity peer_id
GNUNET_TESTING_CORE_connect_cb callback
struct GNUNET_TESTING_CORE_ConnectCb * connect_cbs
Connect callback TODO we probably only need a single one.
struct GNUNET_TESTING_CORE_Channel * channels_tail
struct GNUNET_TESTING_CORE_Channel * channels_head

References GNUNET_TESTING_CORE_ConnectCb::callback, GNUNET_TESTING_CORE_ConnectState::channels_head, GNUNET_TESTING_CORE_ConnectState::channels_tail, GNUNET_TESTING_CORE_ConnectCb::cls, GNUNET_TESTING_CORE_ConnectState::connect_cbs, GNUNET_TESTING_CORE_ConnectState::connect_cbs_len, GNUNET_TESTING_CORE_Channel::connect_state, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcmp, GNUNET_memcpy, GNUNET_new, LOG, mq, GNUNET_TESTING_CORE_Channel::mq, peer_id, GNUNET_TESTING_CORE_Channel::peer_id, and GNUNET_TESTING_CORE_ConnectState::peer_id.

Referenced by exec_connect_run(), GNUNET_SERVICE_register_(), GNUNET_SERVICE_run_(), and GNUNET_SERVICE_start().

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

◆ disconnect_cb()

static void disconnect_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  peer_cls 
)
static

Remove the closed channel:

  1. find the (index of the) closed channel
  2. copy all following channel one to the front

Definition at line 203 of file testing_core_cmd_connect.c.

207{
208 struct GNUNET_TESTING_CORE_ConnectState *connect_state = cls;
209 struct GNUNET_TESTING_CORE_Channel *channel = peer_cls;
210
211 LOG (GNUNET_ERROR_TYPE_DEBUG, "from notify_disconnect_cb()\n");
213 "Channel from peer %s (peer_cls) disconnects\n",
214 GNUNET_i2s (&channel->peer_id));
216 " %s (arg)\n",
217 GNUNET_i2s (peer));
219 " (we are %s)\n",
226 //if (NULL != channel->next)
227 if (0 != GNUNET_memcmp (&connect_state->peer_id, peer))
228 {
229 /* this channel might not be in the list */
230 LOG (GNUNET_ERROR_TYPE_DEBUG, "removing channel from list\n");
233 channel);
234 }
235 GNUNET_free (channel);
236}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_TESTING_CORE_ConnectState::channels_head, GNUNET_TESTING_CORE_ConnectState::channels_tail, GNUNET_TESTING_CORE_Channel::connect_state, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_memcmp, LOG, GNUNET_TESTING_CORE_Channel::peer_id, and GNUNET_TESTING_CORE_ConnectState::peer_id.

Referenced by exec_connect_run(), GNUNET_SERVICE_register_(), GNUNET_SERVICE_run_(), and GNUNET_SERVICE_start().

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

◆ exec_connect_run()

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

Definition at line 240 of file testing_core_cmd_connect.c.

242{
243 struct GNUNET_TESTING_CORE_ConnectState *connect_state = cls;
244 const struct GNUNET_TESTING_Command *arm_cmd;
246 {
249 };
250 const struct GNUNET_CORE_ServiceInfo service_info =
251 {
253 .version = { 1, 0 },
254 .version_max = { 1, 0 },
255 .version_min = { 1, 0 },
256 };
257
259 "(%s) Going to connect to core\n",
260 connect_state->node_id);
261
263 is,
264 connect_state->arm_service_label);
265 if (NULL == arm_cmd)
267 if (GNUNET_OK !=
268 GNUNET_TESTING_ARM_get_trait_config (
269 arm_cmd,
270 &connect_state->cfg))
272
273 connect_state->h = GNUNET_CORE_connect (connect_state->cfg,
274 connect_state, // cls
275 init_cb,
278 handlers,
279 &service_info);
280
281}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static struct GNUNET_TESTING_Interpreter * is
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers, struct GNUNET_CORE_ServiceInfo *service_info)
Connect to the core service.
Definition: core_api.c:698
@ GNUNET_CORE_SERVICE_TEST
Identifier for testing the api.
@ GNUNET_OK
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
Gnunet service info - identifying compatibility with a range of version of a service communicating ov...
enum GNUNET_CORE_Service service
Identifier of the service on top of CORE.
Message handler for a specific message type.
const struct GNUNET_CONFIGURATION_Handle * cfg
A command to be run by the interpreter.
static void * connect_cb(void *cls, const struct GNUNET_PeerIdentity *peer_id, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
static void init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)
#define MTYPE
static void disconnect_cb(void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)

References GNUNET_TESTING_CORE_ConnectState::arm_service_label, GNUNET_TESTING_CORE_ConnectState::cfg, connect_cb(), disconnect_cb(), GNUNET_CORE_connect(), GNUNET_CORE_SERVICE_TEST, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_OK, GNUNET_TESTING_FAIL, GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_CORE_ConnectState::h, handlers, init_cb(), is, LOG, MTYPE, GNUNET_TESTING_CORE_ConnectState::node_id, and GNUNET_CORE_ServiceInfo::service.

Referenced by GNUNET_TESTING_CORE_cmd_connect().

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

◆ exec_connect_cleanup()

static void exec_connect_cleanup ( void *  cls)
static

Definition at line 285 of file testing_core_cmd_connect.c.

286{
287 struct GNUNET_TESTING_CORE_ConnectState *connect_state = cls;
288
289 GNUNET_assert (NULL != connect_state->h);
290 GNUNET_CORE_disconnect (connect_state->h);
291 // TODO cleanup!
292}
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:744
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References GNUNET_assert, GNUNET_CORE_disconnect(), and GNUNET_TESTING_CORE_ConnectState::h.

Referenced by GNUNET_TESTING_CORE_cmd_connect().

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

◆ GNUNET_TESTING_CORE_cmd_connect()

const struct GNUNET_TESTING_Command GNUNET_TESTING_CORE_cmd_connect ( const char *  label,
const char *  node_id,
char *  arm_service_label 
)

Definition at line 297 of file testing_core_cmd_connect.c.

301{
302 struct GNUNET_TESTING_CORE_ConnectState *connect_state;
303
304 // TODO get handler from caller to call on new connections
305
306 connect_state = GNUNET_new (struct GNUNET_TESTING_CORE_ConnectState);
307 connect_state->node_id = GNUNET_strdup (node_id);
309 connect_state->recv_handlers_len = 0;
310 connect_state->recv_handlers =
311 GNUNET_new_array (connect_state->recv_handlers_len,
313 connect_state->connect_cbs_len = 0;
314 connect_state->connect_cbs =
315 GNUNET_new_array (connect_state->connect_cbs_len,
317 connect_state->finished = GNUNET_NO;
318 LOG (GNUNET_ERROR_TYPE_DEBUG, "(Setting up _cmd_connect)\n");
319 return GNUNET_TESTING_command_new_ac ( // TODO make this sync?
320 connect_state, // state
321 label,
325 &connect_state->ac); // TODO make this sync?
326}
void(* GNUNET_TESTING_CORE_handle_msg)(void *cls, struct GNUNET_TESTING_CORE_Channel *channel, const struct GNUNET_TESTING_CORE_Message *msg)
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.
@ GNUNET_NO
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
enum GNUNET_GenericReturnValue finished
static void exec_connect_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
static void exec_connect_cleanup(void *cls)
static enum GNUNET_GenericReturnValue connect_traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_TESTING_CORE_ConnectState::ac, GNUNET_TESTING_CORE_ConnectState::arm_service_label, GNUNET_TESTING_CORE_ConnectState::connect_cbs, GNUNET_TESTING_CORE_ConnectState::connect_cbs_len, connect_traits(), exec_connect_cleanup(), exec_connect_run(), GNUNET_TESTING_CORE_ConnectState::finished, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_new_array, GNUNET_NO, GNUNET_strdup, GNUNET_TESTING_command_new_ac(), LOG, GNUNET_TESTING_CORE_ConnectState::node_id, GNUNET_TESTING_CORE_ConnectState::recv_handlers, and GNUNET_TESTING_CORE_ConnectState::recv_handlers_len.

Here is the call graph for this function: