GNUnet  0.11.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
 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
Value:
#define GNUNET_TIME_UNIT_SECONDS
One second.
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:311

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 38 of file transport-testing-send.c.

40 {
42 
43  if (GNUNET_NO == cx->connected)
44  return;
45  *cr = cx;
46 }
@ GNUNET_NO
Definition: gnunet_common.h:94
Handle for a request to connect two peers.
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.

References GNUNET_TRANSPORT_TESTING_ConnectRequest::connected, and GNUNET_NO.

Referenced by GNUNET_TRANSPORT_TESTING_send().

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 66 of file transport-testing-send.c.

75 {
77  struct GNUNET_MQ_Envelope *env;
79 
80  if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
81  {
82  GNUNET_break (0);
83  return GNUNET_SYSERR;
84  }
85  cr = NULL;
87  receiver,
88  &find_cr,
89  &cr);
90  if (NULL == cr)
92  sender,
93  &find_cr,
94  &cr);
95  if (NULL == cr)
96  {
97  GNUNET_break (0);
98  return GNUNET_NO;
99  }
100  if (NULL == cr->mq)
101  {
102  GNUNET_break (0);
103  return GNUNET_NO;
104  }
105  {
106  char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
107 
109  "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
110  sender->no,
111  GNUNET_i2s (&sender->id),
112  receiver->no,
113  receiver_s);
114  GNUNET_free (receiver_s);
115  }
116  env = GNUNET_MQ_msg_extra (test,
117  msize - sizeof(*test),
118  mtype);
119  test->num = htonl (num);
120  memset (&test[1],
121  num,
122  msize - sizeof(*test));
124  cont,
125  cont_cls);
126  GNUNET_MQ_send (cr->mq,
127  env);
128  return GNUNET_OK;
129 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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: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
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:787
void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition: socks.c:329
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
unsigned int no
An unique number to identify the peer.
struct GNUNET_PeerIdentity id
Peer identity.
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_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.

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, GNUNET_TRANSPORT_TESTING_TestMessage::num, and receiver().

Referenced by do_send().

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 143 of file transport-testing-send.c.

147 {
148  int ret;
149 
150  ccc->global_ret = GNUNET_SYSERR;
152  ccc->p[1],
154  size,
155  ccc->send_num_gen++,
156  cont,
157  cont_cls);
159  if (GNUNET_NO == ret)
160  {
161  GNUNET_break (0);
162  ccc->global_ret = GNUNET_SYSERR;
164  }
165 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
static unsigned int size
Size of the "table".
Definition: peer.c:67
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.
uint32_t send_num_gen
Generator for the num field in test messages.
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_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().

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, GNUNET_TRANSPORT_TESTING_ConnectCheckContext::send_num_gen, and size.

Referenced by GNUNET_TRANSPORT_TESTING_large_send(), and 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 177 of file transport-testing-send.c.

178 {
180  int done;
181  size_t msize;
182 
183  if (0 < sc->num_messages)
184  {
185  sc->num_messages--;
186  done = (0 == sc->num_messages);
187  }
188  else
189  {
190  done = 0; /* infinite loop */
191  }
192  msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
193  if (NULL != sc->get_size_cb)
194  msize = sc->get_size_cb (sc->num_messages);
195  /* if this was the last message, call the continuation,
196  otherwise call this function again */
197  do_send (sc->ccc,
198  msize,
200  done ? sc->cont_cls : sc);
201 }
static void done()
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
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.
void GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
Task that sends a minimalistic test message from the first peer to the second peer.

References do_send(), done(), and sc.

Here is the call 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 213 of file transport-testing-send.c.

214 {
216  int done;
217  size_t msize;
218 
219  if (0 < sc->num_messages)
220  {
221  sc->num_messages--;
222  done = (0 == sc->num_messages);
223  }
224  else
225  {
226  done = 0; /* infinite loop */
227  }
228  msize = 2600;
229  if (NULL != sc->get_size_cb)
230  msize = sc->get_size_cb (sc->num_messages);
231  /* if this was the last message, call the continuation,
232  otherwise call this function again */
233  do_send (sc->ccc,
234  msize,
236  done ? sc->cont_cls : sc);
237 }
void GNUNET_TRANSPORT_TESTING_large_send(void *cls)
Task that sends a large test message from the first peer to the second peer.

References do_send(), done(), and sc.

Here is the call graph for this function: