GNUnet  0.20.0
transport-testing-send.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
25 #include "platform.h"
26 #include "transport-testing.h"
27 
31 #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply ( \
32  GNUNET_TIME_UNIT_SECONDS, 30)
33 
34 
38 static void
39 find_cr (void *cls,
41 {
43 
44  if (GNUNET_NO == cx->connected)
45  return;
46  *cr = cx;
47 }
48 
49 
66 int
70  receiver,
71  uint16_t mtype,
72  uint16_t msize,
73  uint32_t num,
75  void *cont_cls)
76 {
78  struct GNUNET_MQ_Envelope *env;
80 
81  if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
82  {
83  GNUNET_break (0);
84  return GNUNET_SYSERR;
85  }
86  cr = NULL;
88  receiver,
89  &find_cr,
90  &cr);
91  if (NULL == cr)
93  sender,
94  &find_cr,
95  &cr);
96  if (NULL == cr)
97  {
98  GNUNET_break (0);
99  return GNUNET_NO;
100  }
101  if (NULL == cr->mq)
102  {
103  GNUNET_break (0);
104  return GNUNET_NO;
105  }
106  {
107  char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
108 
110  "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
111  sender->no,
112  GNUNET_i2s (&sender->id),
113  receiver->no,
114  receiver_s);
115  GNUNET_free (receiver_s);
116  }
117  env = GNUNET_MQ_msg_extra (test,
118  msize - sizeof(*test),
119  mtype);
120  test->num = htonl (num);
121  memset (&test[1],
122  num,
123  msize - sizeof(*test));
125  cont,
126  cont_cls);
127  GNUNET_MQ_send (cr->mq,
128  env);
129  return GNUNET_OK;
130 }
131 
132 
143 static void
145  uint16_t size,
147  void *cont_cls)
148 {
149  int ret;
150 
151  ccc->global_ret = GNUNET_SYSERR;
153  ccc->p[1],
155  size,
156  ccc->send_num_gen++,
157  cont,
158  cont_cls);
160  if (GNUNET_NO == ret)
161  {
162  GNUNET_break (0);
163  ccc->global_ret = GNUNET_SYSERR;
165  }
166 }
167 
168 
177 void
179 {
181  int done;
182  size_t msize;
183 
184  if (0 < sc->num_messages)
185  {
186  sc->num_messages--;
187  done = (0 == sc->num_messages);
188  }
189  else
190  {
191  done = 0; /* infinite loop */
192  }
193  msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
194  if (NULL != sc->get_size_cb)
195  msize = sc->get_size_cb (sc->num_messages);
196  /* if this was the last message, call the continuation,
197  otherwise call this function again */
198  do_send (sc->ccc,
199  msize,
201  done ? sc->cont_cls : sc);
202 }
203 
204 
213 void
215 {
217  int done;
218  size_t msize;
219 
220  if (0 < sc->num_messages)
221  {
222  sc->num_messages--;
223  done = (0 == sc->num_messages);
224  }
225  else
226  {
227  done = 0; /* infinite loop */
228  }
229  msize = 2600;
230  if (NULL != sc->get_size_cb)
231  msize = sc->get_size_cb (sc->num_messages);
232  /* if this was the last message, call the continuation,
233  otherwise call this function again */
234  do_send (sc->ccc,
235  msize,
237  done ? sc->cont_cls : sc);
238 }
239 
240 
241 /* end of transport-testing-send.c */
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void done()
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
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.
#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:304
#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:63
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:638
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
static unsigned int size
Size of the "table".
Definition: peer.c:68
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:330
Closure that must be passed to GNUNET_TRANSPORT_TESTING_connect_check.
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.
Handle for a request to connect two peers.
struct GNUNET_MQ_Handle * mq
Message queue for sending from p1 to p2.
int connected
GNUNET_YES if both p1_c and p2_c are GNUNET_YES.
unsigned int no
An unique number to identify the peer.
struct GNUNET_PeerIdentity id
Peer identity.
Type of the closure argument to pass to GNUNET_TRANSPORT_TESTING_simple_send() and GNUNET_TRANSPORT_T...
uint32_t num
Monotonically increasing counter throughout the test.
void GNUNET_TRANSPORT_TESTING_large_send(void *cls)
Task that sends a large test message from the first peer to the second peer.
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.
static void find_cr(void *cls, struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
Return cx in cls.
void GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
Task that sends a minimalistic test message from the first peer to the second peer.
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.
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.
testing lib for transport service
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().