diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-12-06 15:48:41 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-12-06 15:48:41 +0000 |
commit | 4f8ad2d211f9e0fb7491ffca0bc73f20face40f7 (patch) | |
tree | 257c513f47c5e2793841c079ad9c5faf9dd5bf7f /src | |
parent | 1bf79006d9c303944d1edf640e98131505c2ec17 (diff) | |
download | gnunet-4f8ad2d211f9e0fb7491ffca0bc73f20face40f7.tar.gz gnunet-4f8ad2d211f9e0fb7491ffca0bc73f20face40f7.zip |
- wip
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_protocols.h | 5 | ||||
-rw-r--r-- | src/mesh/gnunet-mesh.c | 72 |
2 files changed, 71 insertions, 6 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 2cd2aecba..8fc1cd6e6 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -911,6 +911,11 @@ extern "C" | |||
911 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL 288 | 911 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL 288 |
912 | 912 | ||
913 | /** | 913 | /** |
914 | * Traffic (net-cat style) used by the Command Line Interface. | ||
915 | */ | ||
916 | #define GNUNET_MESSAGE_TYPE_MESH_CLI 298 | ||
917 | |||
918 | /** | ||
914 | * 640kb should be enough for everybody | 919 | * 640kb should be enough for everybody |
915 | */ | 920 | */ |
916 | #define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 299 | 921 | #define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 299 |
diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c index 7450d8dc3..17ebbcbaf 100644 --- a/src/mesh/gnunet-mesh.c +++ b/src/mesh/gnunet-mesh.c | |||
@@ -68,11 +68,15 @@ static char *target_id; | |||
68 | */ | 68 | */ |
69 | static uint32_t target_port; | 69 | static uint32_t target_port; |
70 | 70 | ||
71 | |||
72 | |||
71 | /** | 73 | /** |
72 | * Mesh handle. | 74 | * Mesh handle. |
73 | */ | 75 | */ |
74 | static struct GNUNET_MESH_Handle *mh; | 76 | static struct GNUNET_MESH_Handle *mh; |
75 | 77 | ||
78 | static struct GNUNET_MESH_Channel *ch; | ||
79 | |||
76 | /** | 80 | /** |
77 | * Shutdown task handle. | 81 | * Shutdown task handle. |
78 | */ | 82 | */ |
@@ -89,6 +93,11 @@ static void | |||
89 | shutdown_task (void *cls, | 93 | shutdown_task (void *cls, |
90 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 94 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
91 | { | 95 | { |
96 | if (NULL != ch) | ||
97 | { | ||
98 | GNUNET_MESH_channel_destroy (ch); | ||
99 | ch = NULL; | ||
100 | } | ||
92 | if (NULL != mh) | 101 | if (NULL != mh) |
93 | { | 102 | { |
94 | GNUNET_MESH_disconnect (mh); | 103 | GNUNET_MESH_disconnect (mh); |
@@ -114,6 +123,8 @@ channel_ended (void *cls, | |||
114 | void *channel_ctx) | 123 | void *channel_ctx) |
115 | { | 124 | { |
116 | FPRINTF (stdout, "Channel ended!\n"); | 125 | FPRINTF (stdout, "Channel ended!\n"); |
126 | GNUNET_break (channel == ch); | ||
127 | GNUNET_SCHEDULER_shutdown (); | ||
117 | } | 128 | } |
118 | 129 | ||
119 | 130 | ||
@@ -141,7 +152,18 @@ channel_incoming (void *cls, | |||
141 | const struct GNUNET_PeerIdentity * initiator, | 152 | const struct GNUNET_PeerIdentity * initiator, |
142 | uint32_t port, enum MeshOption options) | 153 | uint32_t port, enum MeshOption options) |
143 | { | 154 | { |
144 | FPRINTF (stdout, "Incoming channel!\n"); | 155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Incoming channel on port %u\n", port); |
156 | if (NULL != ch) | ||
157 | { | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A channel already exists\n"); | ||
159 | return NULL; | ||
160 | } | ||
161 | if (0 == listen_port) | ||
162 | { | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not listening to channels\n"); | ||
164 | return NULL; | ||
165 | } | ||
166 | ch = channel; | ||
145 | return NULL; | 167 | return NULL; |
146 | } | 168 | } |
147 | 169 | ||
@@ -166,7 +188,7 @@ create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
166 | FPRINTF (stderr, | 188 | FPRINTF (stderr, |
167 | _("Invalid target `%s'\n"), | 189 | _("Invalid target `%s'\n"), |
168 | target_id); | 190 | target_id); |
169 | GNUNET_SCHEDULER_shutdown(); | 191 | GNUNET_SCHEDULER_shutdown (); |
170 | return; | 192 | return; |
171 | } | 193 | } |
172 | // GNUNET_MESH_channel_create () | 194 | // GNUNET_MESH_channel_create () |
@@ -174,6 +196,35 @@ create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
174 | 196 | ||
175 | 197 | ||
176 | /** | 198 | /** |
199 | * Function called whenever a message is received. | ||
200 | * | ||
201 | * Each time the function must call #GNUNET_MESH_receive_done on the channel | ||
202 | * in order to receive the next message. This doesn't need to be immediate: | ||
203 | * can be delayed if some processing is done on the message. | ||
204 | * | ||
205 | * @param cls Closure (set from #GNUNET_MESH_connect). | ||
206 | * @param channel Connection to the other end. | ||
207 | * @param channel_ctx Place to store local state associated with the channel. | ||
208 | * @param message The actual message. | ||
209 | * @return #GNUNET_OK to keep the channel open, | ||
210 | * #GNUNET_SYSERR to close it (signal serious error). | ||
211 | */ | ||
212 | int | ||
213 | data_callback (void *cls, | ||
214 | struct GNUNET_MESH_Channel *channel, | ||
215 | void **channel_ctx, | ||
216 | const struct GNUNET_MessageHeader *message) | ||
217 | { | ||
218 | int16_t len; | ||
219 | GNUNET_break (ch == channel); | ||
220 | |||
221 | len = ntohs (message->size) - sizeof (*message); | ||
222 | FPRINTF (stdout, "%.*s", len, (char *) &message[1]); | ||
223 | return GNUNET_OK; | ||
224 | } | ||
225 | |||
226 | |||
227 | /** | ||
177 | * Method called to retrieve information about each tunnel the mesh peer | 228 | * Method called to retrieve information about each tunnel the mesh peer |
178 | * is aware of. | 229 | * is aware of. |
179 | * | 230 | * |
@@ -188,9 +239,9 @@ tunnels_callback (void *cls, | |||
188 | const struct GNUNET_PeerIdentity *origin, | 239 | const struct GNUNET_PeerIdentity *origin, |
189 | const struct GNUNET_PeerIdentity *target) | 240 | const struct GNUNET_PeerIdentity *target) |
190 | { | 241 | { |
191 | fprintf (stdout, "Tunnel %s [%u]\n", | 242 | FPRINTF (stdout, "Tunnel %s [%u]\n", |
192 | GNUNET_i2s_full (origin), tunnel_number); | 243 | GNUNET_i2s_full (origin), tunnel_number); |
193 | fprintf (stdout, "\n"); | 244 | FPRINTF (stdout, "\n"); |
194 | } | 245 | } |
195 | 246 | ||
196 | 247 | ||
@@ -296,7 +347,10 @@ static void | |||
296 | run (void *cls, char *const *args, const char *cfgfile, | 347 | run (void *cls, char *const *args, const char *cfgfile, |
297 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 348 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
298 | { | 349 | { |
350 | GNUNET_MESH_InboundChannelNotificationHandler *newch = NULL; | ||
351 | GNUNET_MESH_ChannelEndHandler *endch = NULL; | ||
299 | static const struct GNUNET_MESH_MessageHandler handlers[] = { | 352 | static const struct GNUNET_MESH_MessageHandler handlers[] = { |
353 | {&data_callback, GNUNET_MESSAGE_TYPE_MESH_CLI, 0}, | ||
300 | {NULL, 0, 0} /* FIXME add option to monitor msg types */ | 354 | {NULL, 0, 0} /* FIXME add option to monitor msg types */ |
301 | }; | 355 | }; |
302 | /* FIXME add option to monitor apps */ | 356 | /* FIXME add option to monitor apps */ |
@@ -320,6 +374,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
320 | "Creating channel to %s\n", | 374 | "Creating channel to %s\n", |
321 | target_id); | 375 | target_id); |
322 | GNUNET_SCHEDULER_add_now (&create_channel, NULL); | 376 | GNUNET_SCHEDULER_add_now (&create_channel, NULL); |
377 | endch = &channel_ended; | ||
378 | } | ||
379 | else if (0 != listen_port) | ||
380 | { | ||
381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Listen\n"); | ||
382 | newch = &channel_incoming; | ||
323 | } | 383 | } |
324 | else if (NULL != tunnel_id) | 384 | else if (NULL != tunnel_id) |
325 | { | 385 | { |
@@ -350,8 +410,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mesh\n"); | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to mesh\n"); |
351 | mh = GNUNET_MESH_connect (cfg, | 411 | mh = GNUNET_MESH_connect (cfg, |
352 | NULL, /* cls */ | 412 | NULL, /* cls */ |
353 | NULL, /* new tunnel */ | 413 | newch, /* new channel */ |
354 | NULL, /* cleaner */ | 414 | endch, /* cleaner */ |
355 | handlers, | 415 | handlers, |
356 | NULL); | 416 | NULL); |
357 | FPRINTF (stdout, "Done\n"); | 417 | FPRINTF (stdout, "Done\n"); |