diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-28 15:43:30 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-28 15:43:30 +0000 |
commit | 363b7a14f9e07ddbdbf7d3b6e6243b276693222e (patch) | |
tree | bc779bb85411555059b8217b741f2e6b880fdec1 /src/transport/gnunet-service-transport.c | |
parent | 3a70e67854d7696dfb0de49c7bbd19ab82b42348 (diff) | |
download | gnunet-363b7a14f9e07ddbdbf7d3b6e6243b276693222e.tar.gz gnunet-363b7a14f9e07ddbdbf7d3b6e6243b276693222e.zip |
moving files from dev to final location
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 122 |
1 files changed, 44 insertions, 78 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 7e75b4499..ef9068c9b 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -116,24 +116,6 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) | |||
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | /** | ||
120 | * Try to initiate a connection to the given peer if the blacklist | ||
121 | * allowed it. | ||
122 | * | ||
123 | * @param cls closure (unused, NULL) | ||
124 | * @param peer identity of peer that was tested | ||
125 | * @param result GNUNET_OK if the connection is allowed, | ||
126 | * GNUNET_NO if not | ||
127 | */ | ||
128 | static void | ||
129 | try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
130 | int result) | ||
131 | { | ||
132 | if (GNUNET_OK != result) | ||
133 | return; /* not allowed */ | ||
134 | GST_neighbours_try_connect (peer); | ||
135 | } | ||
136 | |||
137 | 119 | ||
138 | /** | 120 | /** |
139 | * We received some payload. Prepare to pass it on to our clients. | 121 | * We received some payload. Prepare to pass it on to our clients. |
@@ -154,7 +136,8 @@ process_payload (const struct GNUNET_PeerIdentity *peer, | |||
154 | struct GNUNET_TIME_Relative ret; | 136 | struct GNUNET_TIME_Relative ret; |
155 | int do_forward; | 137 | int do_forward; |
156 | struct InboundMessage *im; | 138 | struct InboundMessage *im; |
157 | size_t size = sizeof (struct InboundMessage) + ntohs (message->size) + sizeof (struct GNUNET_ATS_Information) * ats_count; | 139 | size_t msg_size = ntohs (message->size); |
140 | size_t size = sizeof (struct InboundMessage) + msg_size + sizeof (struct GNUNET_ATS_Information) * ats_count; | ||
158 | char buf[size]; | 141 | char buf[size]; |
159 | struct GNUNET_ATS_Information *ap; | 142 | struct GNUNET_ATS_Information *ap; |
160 | 143 | ||
@@ -164,8 +147,26 @@ process_payload (const struct GNUNET_PeerIdentity *peer, | |||
164 | GST_neighbours_calculate_receive_delay (peer, | 147 | GST_neighbours_calculate_receive_delay (peer, |
165 | (message == | 148 | (message == |
166 | NULL) ? 0 : | 149 | NULL) ? 0 : |
167 | ntohs (message->size), | 150 | msg_size, |
168 | &do_forward); | 151 | &do_forward); |
152 | |||
153 | if (!GST_neighbours_test_connected (peer)) | ||
154 | { | ||
155 | |||
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Discarded %u bytes type %u payload from peer `%s'\n", | ||
157 | msg_size, | ||
158 | ntohs (message->type), | ||
159 | GNUNET_i2s (peer)); | ||
160 | |||
161 | GNUNET_STATISTICS_update (GST_stats, | ||
162 | gettext_noop ("# bytes payload discarded due to not connected peer "), | ||
163 | msg_size, | ||
164 | GNUNET_NO); | ||
165 | return ret; | ||
166 | } | ||
167 | |||
168 | if (do_forward != GNUNET_YES) | ||
169 | return ret; | ||
169 | im = (struct InboundMessage*) buf; | 170 | im = (struct InboundMessage*) buf; |
170 | im->header.size = htons (size); | 171 | im->header.size = htons (size); |
171 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); | 172 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); |
@@ -175,30 +176,8 @@ process_payload (const struct GNUNET_PeerIdentity *peer, | |||
175 | memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | 176 | memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); |
176 | memcpy (&ap[ats_count], message, ntohs (message->size)); | 177 | memcpy (&ap[ats_count], message, ntohs (message->size)); |
177 | 178 | ||
178 | switch (do_forward) | 179 | GST_clients_broadcast (&im->header, GNUNET_YES); |
179 | { | 180 | |
180 | case GNUNET_YES: | ||
181 | GST_clients_broadcast (&im->header, GNUNET_YES); | ||
182 | break; | ||
183 | case GNUNET_NO: | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
185 | _("Discarded %u bytes of type %u from %s: quota violated or no neighbour record!\n"), | ||
186 | ntohs (message->size), | ||
187 | ntohs (message->type), | ||
188 | GNUNET_i2s (peer)); | ||
189 | break; | ||
190 | case GNUNET_SYSERR: | ||
191 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
192 | _("Discarded %u bytes of type %u from %s: connection is down!\n"), | ||
193 | ntohs (message->size), | ||
194 | ntohs (message->type), | ||
195 | GNUNET_i2s (peer)); | ||
196 | /* FIXME: store until connection is up? This is virtually always a SETKEY and a PING... */ | ||
197 | break; | ||
198 | default: | ||
199 | GNUNET_break (0); | ||
200 | break; | ||
201 | } | ||
202 | return ret; | 181 | return ret; |
203 | } | 182 | } |
204 | 183 | ||
@@ -242,6 +221,11 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
242 | if (NULL == message) | 221 | if (NULL == message) |
243 | goto end; | 222 | goto end; |
244 | type = ntohs (message->type); | 223 | type = ntohs (message->type); |
224 | #if DEBUG_TRANSPORT | ||
225 | |||
226 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received Message with type %u\n", type); | ||
227 | #endif | ||
228 | |||
245 | switch (type) | 229 | switch (type) |
246 | { | 230 | { |
247 | case GNUNET_MESSAGE_TYPE_HELLO: | 231 | case GNUNET_MESSAGE_TYPE_HELLO: |
@@ -275,8 +259,18 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
275 | peer, | 259 | peer, |
276 | plugin_name, sender_address, sender_address_len, | 260 | plugin_name, sender_address, sender_address_len, |
277 | session, ats, ats_count); | 261 | session, ats, ats_count); |
278 | (void) GST_blacklist_test_allowed (peer, NULL, &try_connect_if_allowed, | 262 | break; |
279 | NULL); | 263 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: |
264 | GST_neighbours_handle_connect_ack (message, | ||
265 | peer, | ||
266 | plugin_name, sender_address, sender_address_len, | ||
267 | session, ats, ats_count); | ||
268 | break; | ||
269 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: | ||
270 | GST_neighbours_handle_ack (message, | ||
271 | peer, | ||
272 | plugin_name, sender_address, sender_address_len, | ||
273 | session, ats, ats_count); | ||
280 | break; | 274 | break; |
281 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | 275 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: |
282 | GST_neighbours_handle_disconnect_message (peer, message); | 276 | GST_neighbours_handle_disconnect_message (peer, message); |
@@ -285,7 +279,6 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
285 | GST_neighbours_keepalive (peer); | 279 | GST_neighbours_keepalive (peer); |
286 | break; | 280 | break; |
287 | default: | 281 | default: |
288 | |||
289 | /* should be payload */ | 282 | /* should be payload */ |
290 | ret = process_payload (peer, | 283 | ret = process_payload (peer, |
291 | message, | 284 | message, |
@@ -393,7 +386,6 @@ ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
393 | { | 386 | { |
394 | uint32_t bw_in = ntohl (bandwidth_in.value__); | 387 | uint32_t bw_in = ntohl (bandwidth_in.value__); |
395 | uint32_t bw_out = ntohl (bandwidth_out.value__); | 388 | uint32_t bw_out = ntohl (bandwidth_out.value__); |
396 | struct QuotaSetMessage msg; | ||
397 | 389 | ||
398 | /* ATS tells me to disconnect from peer*/ | 390 | /* ATS tells me to disconnect from peer*/ |
399 | if ((bw_in == 0) && (bw_out == 0)) | 391 | if ((bw_in == 0) && (bw_out == 0)) |
@@ -406,36 +398,10 @@ ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
406 | GST_neighbours_force_disconnect(peer); | 398 | GST_neighbours_force_disconnect(peer); |
407 | return; | 399 | return; |
408 | } | 400 | } |
409 | if (GNUNET_YES != | 401 | /* will never return GNUNET_YES since connection is to be established */ |
410 | GST_neighbours_switch_to_address (peer, plugin_name, plugin_addr, | 402 | GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr, |
411 | plugin_addr_len, session, ats, ats_count)) | 403 | plugin_addr_len, session, ats, ats_count, |
412 | { | 404 | bandwidth_in, bandwidth_out); |
413 | #if DEBUG_TRANSPORT | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
415 | "Connection is not yet up, ignoring quota for now\n"); | ||
416 | #endif | ||
417 | /* FIXME: maybe we should let ATS know somehow? This is a problem | ||
418 | with the design; ATS may assign bandwidth, but we don't use it; | ||
419 | the current ATS API doesn't give us a good way to sync the | ||
420 | connection status between ATS and TRANSPORT */ | ||
421 | return; | ||
422 | } | ||
423 | #if DEBUG_TRANSPORT | ||
424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
425 | "Sending outbound quota of %u Bps for peer `%s' to all clients\n", | ||
426 | ntohl (bandwidth_out.value__), GNUNET_i2s (peer)); | ||
427 | #endif | ||
428 | msg.header.size = htons (sizeof (struct QuotaSetMessage)); | ||
429 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); | ||
430 | msg.quota = bandwidth_out; | ||
431 | msg.peer = (*peer); | ||
432 | GST_clients_broadcast (&msg.header, GNUNET_NO); | ||
433 | #if DEBUG_TRANSPORT | ||
434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
435 | "Setting inbound quota of %u for peer `%s' to \n", | ||
436 | ntohl (bandwidth_in.value__), GNUNET_i2s (peer)); | ||
437 | #endif | ||
438 | GST_neighbours_set_incoming_quota (peer, bandwidth_in); | ||
439 | } | 405 | } |
440 | 406 | ||
441 | 407 | ||