diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-27 11:45:18 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-09-27 11:45:18 +0000 |
commit | 621e141e0ce52f5793cce348ff070e90dad296cc (patch) | |
tree | 98944b9c16464eddfb874ec61d117d3a2eb1fa40 /src/transport | |
parent | 9aa61a38dafb287e5737cf571354dbdd767a5f50 (diff) | |
download | gnunet-621e141e0ce52f5793cce348ff070e90dad296cc.tar.gz gnunet-621e141e0ce52f5793cce348ff070e90dad296cc.zip |
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-transport-connect-running-peers.c | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/src/transport/gnunet-transport-connect-running-peers.c b/src/transport/gnunet-transport-connect-running-peers.c index 697c9b015..aac63cb35 100644 --- a/src/transport/gnunet-transport-connect-running-peers.c +++ b/src/transport/gnunet-transport-connect-running-peers.c | |||
@@ -138,48 +138,13 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | static void | ||
142 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
143 | const struct GNUNET_MessageHeader *message, | ||
144 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
145 | uint32_t ats_count) | ||
146 | { | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
148 | "Received message of type %d from peer %s!\n", | ||
149 | ntohs (message->type), GNUNET_i2s (peer)); | ||
150 | |||
151 | if ((MTYPE == ntohs (message->type)) && | ||
152 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | ||
153 | { | ||
154 | ok = 0; | ||
155 | end (NULL, NULL); | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | GNUNET_break (0); | ||
160 | ok = 1; | ||
161 | end (NULL, NULL); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | |||
166 | static size_t | 141 | static size_t |
167 | notify_ready (void *cls, size_t size, void *buf) | 142 | notify_ready (void *cls, size_t size, void *buf) |
168 | { | 143 | { |
169 | struct PeerContext *p = cls; | 144 | struct PeerContext *p = cls; |
170 | struct GNUNET_MessageHeader *hdr; | 145 | struct GNUNET_MessageHeader *hdr; |
171 | char t; | ||
172 | 146 | ||
173 | th = NULL; | 147 | th = NULL; |
174 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
175 | "Press <q> to quit or any key to transmit a message\n"); | ||
176 | |||
177 | scanf("%c", &t); | ||
178 | if (t == 'q') | ||
179 | { | ||
180 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
181 | return 0; | ||
182 | } | ||
183 | 148 | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
185 | "Transmitting message with %u bytes to peer %s\n", | 150 | "Transmitting message with %u bytes to peer %s\n", |
@@ -193,12 +158,64 @@ notify_ready (void *cls, size_t size, void *buf) | |||
193 | hdr->type = htons (MTYPE); | 158 | hdr->type = htons (MTYPE); |
194 | } | 159 | } |
195 | 160 | ||
196 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, TIMEOUT, | ||
197 | ¬ify_ready, p1); | ||
198 | |||
199 | return sizeof (struct GNUNET_MessageHeader); | 161 | return sizeof (struct GNUNET_MessageHeader); |
200 | } | 162 | } |
201 | 163 | ||
164 | static void | ||
165 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
166 | { | ||
167 | send_task = GNUNET_SCHEDULER_NO_TASK; | ||
168 | static char t; | ||
169 | |||
170 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
171 | return; | ||
172 | |||
173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
174 | "Press <q> to quit or <1> to send from p1 to p2, <2> to send from p2 to p1, <enter> repeat\n"); | ||
175 | |||
176 | read: | ||
177 | t = getchar(); | ||
178 | if (t == '1') | ||
179 | { | ||
180 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, TIMEOUT, | ||
181 | ¬ify_ready, p1); | ||
182 | return; | ||
183 | } | ||
184 | if (t == '2') | ||
185 | { | ||
186 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, TIMEOUT, | ||
187 | ¬ify_ready, p2); | ||
188 | return; | ||
189 | } | ||
190 | if (t == 'q') | ||
191 | { | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
193 | "Exiting %c!\n", t); | ||
194 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
195 | return; | ||
196 | } | ||
197 | goto read; | ||
198 | } | ||
199 | |||
200 | static void | ||
201 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
202 | const struct GNUNET_MessageHeader *message, | ||
203 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
204 | uint32_t ats_count) | ||
205 | { | ||
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
207 | "Received message of type %d from peer %s!\n", | ||
208 | ntohs (message->type), GNUNET_i2s (peer)); | ||
209 | |||
210 | if ((MTYPE == ntohs (message->type)) && | ||
211 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | ||
212 | { | ||
213 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
214 | "Successfully received message\n"); | ||
215 | |||
216 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
217 | } | ||
218 | } | ||
202 | 219 | ||
203 | static void | 220 | static void |
204 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 221 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
@@ -270,18 +287,6 @@ connect_to_peer (const char *cfgname, GNUNET_TRANSPORT_ReceiveCallback rec, | |||
270 | } | 287 | } |
271 | 288 | ||
272 | static void | 289 | static void |
273 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
274 | { | ||
275 | send_task = GNUNET_SCHEDULER_NO_TASK; | ||
276 | |||
277 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
278 | return; | ||
279 | |||
280 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, 0, TIMEOUT, | ||
281 | ¬ify_ready, &p1); | ||
282 | } | ||
283 | |||
284 | static void | ||
285 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | 290 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) |
286 | { | 291 | { |
287 | cc = NULL; | 292 | cc = NULL; |