GNUnet  0.10.x
Macros | Functions
transport-testing-send.c File Reference

convenience transmission function for tests More...

#include "transport-testing.h"
Include dependency graph for transport-testing-send.c:

Go to the source code of this file.

Macros

#define TIMEOUT_TRANSMIT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
 Acceptable transmission delay. More...
 

Functions

static void find_cr (void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
 Return cx in cls. More...
 
int GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, uint16_t mtype, uint16_t msize, uint32_t num, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
 Send a test message of type mtype and size msize from peer sender to peer receiver. More...
 
static void do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, uint16_t size, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
 Task that sends a test message from the first peer to the second peer. More...
 
void GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
 Task that sends a minimalistic test message from the first peer to the second peer. More...
 
void GNUNET_TRANSPORT_TESTING_large_send (void *cls)
 Task that sends a large test message from the first peer to the second peer. More...
 

Detailed Description

convenience transmission function for tests

Author
Christian Grothoff

Definition in file transport-testing-send.c.

Macro Definition Documentation

◆ TIMEOUT_TRANSMIT

#define TIMEOUT_TRANSMIT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)

Acceptable transmission delay.

Definition at line 30 of file transport-testing-send.c.

Function Documentation

◆ find_cr()

static void find_cr ( void *  cls,
struct GNUNET_TRANSPORT_TESTING_ConnectRequest cx 
)
static

Return cx in cls.

Definition at line 37 of file transport-testing-send.c.

References GNUNET_TRANSPORT_TESTING_ConnectRequest::connected, and GNUNET_NO.

Referenced by GNUNET_TRANSPORT_TESTING_send().

39 {
41 
42  if (GNUNET_NO == cx->connected)
43  return;
44  *cr = cx;
45 }
Handle for a request to connect two peers.
#define GNUNET_NO
Definition: gnunet_common.h:78
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_send()

int GNUNET_TRANSPORT_TESTING_send ( struct GNUNET_TRANSPORT_TESTING_PeerContext sender,
struct GNUNET_TRANSPORT_TESTING_PeerContext receiver,
uint16_t  mtype,
uint16_t  msize,
uint32_t  num,
GNUNET_SCHEDULER_TaskCallback  cont,
void *  cont_cls 
)

Send a test message of type mtype and size msize from peer sender to peer receiver.

The peers should be connected when this function is called.

Parameters
senderthe sending peer
receiverthe receiving peer
mtypemessage type to use
msizesize of the message, at least sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)
numunique message number
contcontinuation to call after transmission
cont_clsclosure for cont
Returns
GNUNET_OK if message was queued, GNUNET_NO if peers are not connected GNUNET_SYSERR if msize is illegal

Definition at line 65 of file transport-testing-send.c.

References env, find_cr(), GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, GNUNET_TRANSPORT_TESTING_find_connecting_context(), GNUNET_TRANSPORT_TESTING_PeerContext::id, GNUNET_TRANSPORT_TESTING_ConnectRequest::mq, GNUNET_TRANSPORT_TESTING_PeerContext::no, and GNUNET_TRANSPORT_TESTING_TestMessage::num.

Referenced by do_send().

72 {
74  struct GNUNET_MQ_Envelope *env;
76 
77  if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
78  {
79  GNUNET_break(0);
80  return GNUNET_SYSERR;
81  }
82  cr = NULL;
84  receiver,
85  &find_cr,
86  &cr);
87  if (NULL == cr)
89  sender,
90  &find_cr,
91  &cr);
92  if (NULL == cr)
93  {
94  GNUNET_break(0);
95  return GNUNET_NO;
96  }
97  if (NULL == cr->mq)
98  {
99  GNUNET_break(0);
100  return GNUNET_NO;
101  }
102  {
103  char *receiver_s = GNUNET_strdup(GNUNET_i2s(&receiver->id));
104 
106  "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
107  sender->no,
108  GNUNET_i2s(&sender->id),
109  receiver->no,
110  receiver_s);
111  GNUNET_free(receiver_s);
112  }
113  env = GNUNET_MQ_msg_extra(test,
114  msize - sizeof(*test),
115  mtype);
116  test->num = htonl(num);
117  memset(&test[1],
118  num,
119  msize - sizeof(*test));
121  cont,
122  cont_cls);
123  GNUNET_MQ_send(cr->mq,
124  env);
125  return GNUNET_OK;
126 }
Handle for a request to connect two peers.
struct GNUNET_PeerIdentity id
Peer identity.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
unsigned int no
An unique number to identify the peer.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
#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
void GNUNET_TRANSPORT_TESTING_find_connecting_context(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, void *cb_cls)
Find any connecting context matching the given pair of peers.
uint32_t num
Monotonically increasing counter throughout the test.
static void find_cr(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
Return cx in cls.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:772
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
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:351
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_send()

static void do_send ( struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext ccc,
uint16_t  size,
GNUNET_SCHEDULER_TaskCallback  cont,
void *  cont_cls 
)
static

Task that sends a test message from the first peer to the second peer.

Parameters
ccccontext which should contain at least two peers, the first two of which should be currently connected
sizedesired message size
contcontinuation to call after transmission
cont_clsclosure for cont

Definition at line 140 of file transport-testing-send.c.

References GNUNET_TRANSPORT_TESTING_ConnectCheckContext::global_ret, GNUNET_assert, GNUNET_break, GNUNET_NO, GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_TRANSPORT_TESTING_send(), GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::p, ret, and GNUNET_TRANSPORT_TESTING_ConnectCheckContext::send_num_gen.

Referenced by GNUNET_TRANSPORT_TESTING_large_send(), and GNUNET_TRANSPORT_TESTING_simple_send().

144 {
145  int ret;
146 
147  ccc->global_ret = GNUNET_SYSERR;
148  ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[0],
149  ccc->p[1],
151  size,
152  ccc->send_num_gen++,
153  cont,
154  cont_cls);
156  if (GNUNET_NO == ret)
157  {
158  GNUNET_break(0);
159  ccc->global_ret = GNUNET_SYSERR;
161  }
162 }
int global_ret
Result from the main function, set to GNUNET_OK on success.
struct GNUNET_TRANSPORT_TESTING_PeerContext ** p
Array with num_peers entries.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
int GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, uint16_t mtype, uint16_t msize, uint32_t num, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Send a test message of type mtype and size msize from peer sender to peer receiver.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
uint32_t send_num_gen
Generator for the num field in test messages.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_simple_send()

void GNUNET_TRANSPORT_TESTING_simple_send ( void *  cls)

Task that sends a minimalistic test message from the first peer to the second peer.

Parameters
clsthe struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext which should contain at least two peers, the first two of which should be currently connected

Definition at line 174 of file transport-testing-send.c.

References GNUNET_TRANSPORT_TESTING_SendClosure::ccc, GNUNET_TRANSPORT_TESTING_SendClosure::cont, GNUNET_TRANSPORT_TESTING_SendClosure::cont_cls, do_send(), done(), GNUNET_TRANSPORT_TESTING_SendClosure::get_size_cb, GNUNET_TRANSPORT_TESTING_simple_send(), GNUNET_TRANSPORT_TESTING_SendClosure::num_messages, and sc.

Referenced by GNUNET_TRANSPORT_TESTING_simple_send().

175 {
177  int done;
178  size_t msize;
179 
180  if (0 < sc->num_messages)
181  {
182  sc->num_messages--;
183  done = (0 == sc->num_messages);
184  }
185  else
186  {
187  done = 0; /* infinite loop */
188  }
189  msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
190  if (NULL != sc->get_size_cb)
191  msize = sc->get_size_cb(sc->num_messages);
192  /* if this was the last message, call the continuation,
193  otherwise call this function again */
194  do_send(sc->ccc,
195  msize,
197  done ? sc->cont_cls : sc);
198 }
static void done()
unsigned int num_messages
Number of messages to be transmitted in a loop.
size_t(* get_size_cb)(unsigned int n)
Function that returns the desired message size.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
GNUNET_SCHEDULER_TaskCallback cont
Function to call after all transmissions, can be NULL.
static void do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, uint16_t size, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Task that sends a test message from the first peer to the second peer.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Context for the transmission.
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
void GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
Task that sends a minimalistic test message from the first peer to the second peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TRANSPORT_TESTING_large_send()

void GNUNET_TRANSPORT_TESTING_large_send ( void *  cls)

Task that sends a large test message from the first peer to the second peer.

Parameters
clsthe struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext which should contain at least two peers, the first two of which should be currently connected

Definition at line 210 of file transport-testing-send.c.

References GNUNET_TRANSPORT_TESTING_SendClosure::ccc, GNUNET_TRANSPORT_TESTING_SendClosure::cont, GNUNET_TRANSPORT_TESTING_SendClosure::cont_cls, do_send(), done(), GNUNET_TRANSPORT_TESTING_SendClosure::get_size_cb, GNUNET_TRANSPORT_TESTING_large_send(), GNUNET_TRANSPORT_TESTING_SendClosure::num_messages, and sc.

Referenced by GNUNET_TRANSPORT_TESTING_large_send().

211 {
213  int done;
214  size_t msize;
215 
216  if (0 < sc->num_messages)
217  {
218  sc->num_messages--;
219  done = (0 == sc->num_messages);
220  }
221  else
222  {
223  done = 0; /* infinite loop */
224  }
225  msize = 2600;
226  if (NULL != sc->get_size_cb)
227  msize = sc->get_size_cb(sc->num_messages);
228  /* if this was the last message, call the continuation,
229  otherwise call this function again */
230  do_send(sc->ccc,
231  msize,
233  done ? sc->cont_cls : sc);
234 }
static void done()
unsigned int num_messages
Number of messages to be transmitted in a loop.
size_t(* get_size_cb)(unsigned int n)
Function that returns the desired message size.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
GNUNET_SCHEDULER_TaskCallback cont
Function to call after all transmissions, can be NULL.
static void do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, uint16_t size, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Task that sends a test message from the first peer to the second peer.
struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext * ccc
Context for the transmission.
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
void GNUNET_TRANSPORT_TESTING_large_send(void *cls)
Task that sends a large test message from the first peer to the second peer.
Here is the call graph for this function:
Here is the caller graph for this function: