summaryrefslogtreecommitdiff
path: root/src/transport/transport-testing-send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing-send.c')
-rw-r--r--src/transport/transport-testing-send.c191
1 files changed, 97 insertions, 94 deletions
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c
index 42735e4c1..5885ffb03 100644
--- a/src/transport/transport-testing-send.c
+++ b/src/transport/transport-testing-send.c
@@ -27,15 +27,16 @@
27/** 27/**
28 * Acceptable transmission delay. 28 * Acceptable transmission delay.
29 */ 29 */
30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 30#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply ( \
31 GNUNET_TIME_UNIT_SECONDS, 30)
31 32
32 33
33/** 34/**
34 * Return @a cx in @a cls. 35 * Return @a cx in @a cls.
35 */ 36 */
36static void 37static void
37find_cr(void *cls, 38find_cr (void *cls,
38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 39 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
39{ 40{
40 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; 41 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
41 42
@@ -62,66 +63,68 @@ find_cr(void *cls,
62 * #GNUNET_SYSERR if @a msize is illegal 63 * #GNUNET_SYSERR if @a msize is illegal
63 */ 64 */
64int 65int
65GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, 66GNUNET_TRANSPORT_TESTING_send (struct
66 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 67 GNUNET_TRANSPORT_TESTING_PeerContext *sender,
67 uint16_t mtype, 68 struct GNUNET_TRANSPORT_TESTING_PeerContext *
68 uint16_t msize, 69 receiver,
69 uint32_t num, 70 uint16_t mtype,
70 GNUNET_SCHEDULER_TaskCallback cont, 71 uint16_t msize,
71 void *cont_cls) 72 uint32_t num,
73 GNUNET_SCHEDULER_TaskCallback cont,
74 void *cont_cls)
72{ 75{
73 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; 76 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
74 struct GNUNET_MQ_Envelope *env; 77 struct GNUNET_MQ_Envelope *env;
75 struct GNUNET_TRANSPORT_TESTING_TestMessage *test; 78 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
76 79
77 if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)) 80 if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
78 { 81 {
79 GNUNET_break(0); 82 GNUNET_break (0);
80 return GNUNET_SYSERR; 83 return GNUNET_SYSERR;
81 } 84 }
82 cr = NULL; 85 cr = NULL;
83 GNUNET_TRANSPORT_TESTING_find_connecting_context(sender, 86 GNUNET_TRANSPORT_TESTING_find_connecting_context (sender,
84 receiver, 87 receiver,
85 &find_cr, 88 &find_cr,
86 &cr); 89 &cr);
87 if (NULL == cr) 90 if (NULL == cr)
88 GNUNET_TRANSPORT_TESTING_find_connecting_context(receiver, 91 GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver,
89 sender, 92 sender,
90 &find_cr, 93 &find_cr,
91 &cr); 94 &cr);
92 if (NULL == cr) 95 if (NULL == cr)
93 { 96 {
94 GNUNET_break(0); 97 GNUNET_break (0);
95 return GNUNET_NO; 98 return GNUNET_NO;
96 } 99 }
97 if (NULL == cr->mq) 100 if (NULL == cr->mq)
98 {
99 GNUNET_break(0);
100 return GNUNET_NO;
101 }
102 { 101 {
103 char *receiver_s = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 102 GNUNET_break (0);
104 103 return GNUNET_NO;
105 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
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 } 104 }
113 env = GNUNET_MQ_msg_extra(test, 105 {
114 msize - sizeof(*test), 106 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id));
115 mtype); 107
116 test->num = htonl(num); 108 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
117 memset(&test[1], 109 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
118 num, 110 sender->no,
119 msize - sizeof(*test)); 111 GNUNET_i2s (&sender->id),
120 GNUNET_MQ_notify_sent(env, 112 receiver->no,
121 cont, 113 receiver_s);
122 cont_cls); 114 GNUNET_free (receiver_s);
123 GNUNET_MQ_send(cr->mq, 115 }
124 env); 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));
123 GNUNET_MQ_notify_sent (env,
124 cont,
125 cont_cls);
126 GNUNET_MQ_send (cr->mq,
127 env);
125 return GNUNET_OK; 128 return GNUNET_OK;
126} 129}
127 130
@@ -137,28 +140,28 @@ GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sende
137 * @param cont_cls closure for @a cont 140 * @param cont_cls closure for @a cont
138 */ 141 */
139static void 142static void
140do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 143do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
141 uint16_t size, 144 uint16_t size,
142 GNUNET_SCHEDULER_TaskCallback cont, 145 GNUNET_SCHEDULER_TaskCallback cont,
143 void *cont_cls) 146 void *cont_cls)
144{ 147{
145 int ret; 148 int ret;
146 149
147 ccc->global_ret = GNUNET_SYSERR; 150 ccc->global_ret = GNUNET_SYSERR;
148 ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[0], 151 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0],
149 ccc->p[1], 152 ccc->p[1],
150 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 153 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
151 size, 154 size,
152 ccc->send_num_gen++, 155 ccc->send_num_gen++,
153 cont, 156 cont,
154 cont_cls); 157 cont_cls);
155 GNUNET_assert(GNUNET_SYSERR != ret); 158 GNUNET_assert (GNUNET_SYSERR != ret);
156 if (GNUNET_NO == ret) 159 if (GNUNET_NO == ret)
157 { 160 {
158 GNUNET_break(0); 161 GNUNET_break (0);
159 ccc->global_ret = GNUNET_SYSERR; 162 ccc->global_ret = GNUNET_SYSERR;
160 GNUNET_SCHEDULER_shutdown(); 163 GNUNET_SCHEDULER_shutdown ();
161 } 164 }
162} 165}
163 166
164 167
@@ -171,30 +174,30 @@ do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
171 * of which should be currently connected 174 * of which should be currently connected
172 */ 175 */
173void 176void
174GNUNET_TRANSPORT_TESTING_simple_send(void *cls) 177GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
175{ 178{
176 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 179 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
177 int done; 180 int done;
178 size_t msize; 181 size_t msize;
179 182
180 if (0 < sc->num_messages) 183 if (0 < sc->num_messages)
181 { 184 {
182 sc->num_messages--; 185 sc->num_messages--;
183 done = (0 == sc->num_messages); 186 done = (0 == sc->num_messages);
184 } 187 }
185 else 188 else
186 { 189 {
187 done = 0; /* infinite loop */ 190 done = 0; /* infinite loop */
188 } 191 }
189 msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage); 192 msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
190 if (NULL != sc->get_size_cb) 193 if (NULL != sc->get_size_cb)
191 msize = sc->get_size_cb(sc->num_messages); 194 msize = sc->get_size_cb (sc->num_messages);
192 /* if this was the last message, call the continuation, 195 /* if this was the last message, call the continuation,
193 otherwise call this function again */ 196 otherwise call this function again */
194 do_send(sc->ccc, 197 do_send (sc->ccc,
195 msize, 198 msize,
196 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send, 199 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
197 done ? sc->cont_cls : sc); 200 done ? sc->cont_cls : sc);
198} 201}
199 202
200 203
@@ -207,30 +210,30 @@ GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
207 * of which should be currently connected 210 * of which should be currently connected
208 */ 211 */
209void 212void
210GNUNET_TRANSPORT_TESTING_large_send(void *cls) 213GNUNET_TRANSPORT_TESTING_large_send (void *cls)
211{ 214{
212 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 215 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
213 int done; 216 int done;
214 size_t msize; 217 size_t msize;
215 218
216 if (0 < sc->num_messages) 219 if (0 < sc->num_messages)
217 { 220 {
218 sc->num_messages--; 221 sc->num_messages--;
219 done = (0 == sc->num_messages); 222 done = (0 == sc->num_messages);
220 } 223 }
221 else 224 else
222 { 225 {
223 done = 0; /* infinite loop */ 226 done = 0; /* infinite loop */
224 } 227 }
225 msize = 2600; 228 msize = 2600;
226 if (NULL != sc->get_size_cb) 229 if (NULL != sc->get_size_cb)
227 msize = sc->get_size_cb(sc->num_messages); 230 msize = sc->get_size_cb (sc->num_messages);
228 /* if this was the last message, call the continuation, 231 /* if this was the last message, call the continuation,
229 otherwise call this function again */ 232 otherwise call this function again */
230 do_send(sc->ccc, 233 do_send (sc->ccc,
231 msize, 234 msize,
232 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send, 235 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
233 done ? sc->cont_cls : sc); 236 done ? sc->cont_cls : sc);
234} 237}
235 238
236/* end of transport-testing-send.c */ 239/* end of transport-testing-send.c */