diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-17 13:55:08 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-17 13:55:08 +0000 |
commit | 7402a01c58bc72833e5a126bc204a21d8db908d2 (patch) | |
tree | 3ec24bbbd15c2a42bdf089dc76c3bd3a0ddd487b /src | |
parent | 2e30d52c8b5dfa6587b3cfc94ca035d51ff7b7af (diff) | |
download | gnunet-7402a01c58bc72833e5a126bc204a21d8db908d2.tar.gz gnunet-7402a01c58bc72833e5a126bc204a21d8db908d2.zip |
removing bad reserved field, small refactoring
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 201 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 137 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.h | 24 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 6 | ||||
-rw-r--r-- | src/transport/transport.h | 5 | ||||
-rw-r--r-- | src/transport/transport_api.c | 1 |
6 files changed, 251 insertions, 123 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 5bde153e4..c571277e2 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -136,6 +136,71 @@ try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
136 | 136 | ||
137 | 137 | ||
138 | /** | 138 | /** |
139 | * We received some payload. Prepare to pass it on to our clients. | ||
140 | * | ||
141 | * @param peer (claimed) identity of the other peer | ||
142 | * @param message the message, NULL if we only care about | ||
143 | * learning about the delay until we should receive again -- FIXME! | ||
144 | * @param ats performance information | ||
145 | * @param ats_count number of records in ats | ||
146 | * @return how long the plugin should wait until receiving more data | ||
147 | */ | ||
148 | static struct GNUNET_TIME_Relative | ||
149 | process_payload (const struct GNUNET_PeerIdentity *peer, | ||
150 | const struct GNUNET_MessageHeader *message, | ||
151 | const struct GNUNET_ATS_Information *ats, | ||
152 | uint32_t ats_count) | ||
153 | { | ||
154 | struct GNUNET_TIME_Relative ret; | ||
155 | int do_forward; | ||
156 | struct InboundMessage *im; | ||
157 | size_t size = sizeof (struct InboundMessage) + ntohs (message->size); | ||
158 | char buf[size]; | ||
159 | |||
160 | ret = GNUNET_TIME_UNIT_ZERO; | ||
161 | do_forward = GNUNET_SYSERR; | ||
162 | ret = | ||
163 | GST_neighbours_calculate_receive_delay (peer, | ||
164 | (message == | ||
165 | NULL) ? 0 : | ||
166 | ntohs (message->size), | ||
167 | &do_forward); | ||
168 | im = (struct InboundMessage*) buf; | ||
169 | im->header.size = htons (size); | ||
170 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); | ||
171 | im->ats_count = htonl (0); | ||
172 | memcpy (&(im->peer), peer, sizeof (struct GNUNET_PeerIdentity)); | ||
173 | memcpy (&im[1], message, ntohs (message->size)); | ||
174 | |||
175 | switch (do_forward) | ||
176 | { | ||
177 | case GNUNET_YES: | ||
178 | GST_clients_broadcast (&im->header, GNUNET_YES); | ||
179 | break; | ||
180 | case GNUNET_NO: | ||
181 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
182 | _("Discarded %u bytes of type %u from %s: quota violated!\n"), | ||
183 | ntohs (message->size), | ||
184 | ntohs (message->type), | ||
185 | GNUNET_i2s (peer)); | ||
186 | break; | ||
187 | case GNUNET_SYSERR: | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
189 | _("Discarded %u bytes of type %u from %s: connection is down!\n"), | ||
190 | ntohs (message->size), | ||
191 | ntohs (message->type), | ||
192 | GNUNET_i2s (peer)); | ||
193 | /* FIXME: store until connection is up? This is virtually always a SETKEY and a PING... */ | ||
194 | break; | ||
195 | default: | ||
196 | GNUNET_break (0); | ||
197 | break; | ||
198 | } | ||
199 | return ret; | ||
200 | } | ||
201 | |||
202 | |||
203 | /** | ||
139 | * Function called by the transport for each received message. | 204 | * Function called by the transport for each received message. |
140 | * This function should also be called with "NULL" for the | 205 | * This function should also be called with "NULL" for the |
141 | * message to signal that the other peer disconnected. | 206 | * message to signal that the other peer disconnected. |
@@ -167,104 +232,74 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
167 | uint16_t sender_address_len) | 232 | uint16_t sender_address_len) |
168 | { | 233 | { |
169 | const char *plugin_name = cls; | 234 | const char *plugin_name = cls; |
170 | int do_forward; | ||
171 | struct GNUNET_TIME_Relative ret; | 235 | struct GNUNET_TIME_Relative ret; |
172 | uint16_t type; | 236 | uint16_t type; |
173 | 237 | ||
174 | ret = GNUNET_TIME_UNIT_ZERO; | 238 | ret = GNUNET_TIME_UNIT_ZERO; |
175 | if (NULL != message) | 239 | if (NULL == message) |
240 | goto end; | ||
241 | type = ntohs (message->type); | ||
242 | switch (type) | ||
176 | { | 243 | { |
177 | type = ntohs (message->type); | 244 | case GNUNET_MESSAGE_TYPE_HELLO: |
178 | switch (type) | 245 | GST_validation_handle_hello (message); |
179 | { | 246 | return ret; |
180 | case GNUNET_MESSAGE_TYPE_HELLO: | 247 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: |
181 | GST_validation_handle_hello (message); | ||
182 | return ret; | ||
183 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: | ||
184 | #if DEBUG_TRANSPORT | 248 | #if DEBUG_TRANSPORT |
185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
186 | "Processing `%s' from `%s'\n", "PING", | 250 | "Processing `%s' from `%s'\n", "PING", |
187 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, | 251 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, |
188 | sender_address, | 252 | sender_address, |
189 | sender_address_len) | 253 | sender_address_len) |
190 | : "<inbound>"); | 254 | : "<inbound>"); |
191 | #endif | 255 | #endif |
192 | GST_validation_handle_ping (peer, message, plugin_name, session, | 256 | GST_validation_handle_ping (peer, message, plugin_name, session, |
193 | sender_address, sender_address_len); | 257 | sender_address, sender_address_len); |
194 | break; | 258 | break; |
195 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | 259 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: |
196 | #if DEBUG_TRANSPORT | 260 | #if DEBUG_TRANSPORT |
197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 261 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
198 | "Processing `%s' from `%s'\n", "PONG", | 262 | "Processing `%s' from `%s'\n", "PONG", |
199 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, | 263 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, |
200 | sender_address, | 264 | sender_address, |
201 | sender_address_len) | 265 | sender_address_len) |
202 | : "<inbound>"); | 266 | : "<inbound>"); |
203 | #endif | 267 | #endif |
204 | GST_validation_handle_pong (peer, message); | 268 | GST_validation_handle_pong (peer, message); |
205 | break; | 269 | break; |
206 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: | 270 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: |
207 | (void) GST_blacklist_test_allowed (peer, NULL, &try_connect_if_allowed, | 271 | GST_neighbours_handle_connect (message, |
208 | NULL); | 272 | peer, |
209 | /* TODO: if 'session != NULL', and timestamp more recent than the | 273 | plugin_name, sender_address, sender_address_len, |
210 | * previous one, maybe notify ATS that this is now the preferred | 274 | session, ats, ats_count); |
211 | * * way to communicate with this peer (other peer switched transport) */ | 275 | (void) GST_blacklist_test_allowed (peer, NULL, &try_connect_if_allowed, |
212 | break; | 276 | NULL); |
213 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | 277 | break; |
214 | /* FIXME: do some validation to prevent an attacker from sending | 278 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: |
215 | * a fake disconnect message... */ | 279 | /* FIXME: do some validation to prevent an attacker from sending |
216 | GST_neighbours_force_disconnect (peer); | 280 | * a fake disconnect message... */ |
217 | break; | 281 | GST_neighbours_force_disconnect (peer); |
218 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: | 282 | break; |
219 | GST_neighbours_keepalive (peer); | 283 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: |
220 | break; | 284 | GST_neighbours_keepalive (peer); |
221 | default: | 285 | break; |
222 | /* should be payload */ | 286 | default: |
223 | do_forward = GNUNET_SYSERR; | 287 | /* should be payload */ |
224 | ret = | 288 | process_payload (peer, |
225 | GST_neighbours_calculate_receive_delay (peer, | 289 | message, |
226 | (message == | 290 | ats, ats_count); |
227 | NULL) ? 0 : | 291 | break; |
228 | ntohs (message->size), | ||
229 | &do_forward); | ||
230 | if (do_forward == GNUNET_YES) | ||
231 | { | ||
232 | struct InboundMessage *im; | ||
233 | size_t size = sizeof (struct InboundMessage) + ntohs (message->size); | ||
234 | |||
235 | im = GNUNET_malloc (size); | ||
236 | im->header.size = htons (size); | ||
237 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); | ||
238 | im->ats_count = htonl (0); | ||
239 | memcpy (&(im->peer), peer, sizeof (struct GNUNET_PeerIdentity)); | ||
240 | memcpy (&im[1], message, ntohs (message->size)); | ||
241 | GST_clients_broadcast ((const struct GNUNET_MessageHeader *) im, | ||
242 | GNUNET_YES); | ||
243 | |||
244 | GNUNET_free (im); | ||
245 | } | ||
246 | else | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
248 | _("Discarded %u bytes of type %u from %s via plugin %s: connection is down!\n"), | ||
249 | ntohs (message->size), | ||
250 | type, | ||
251 | GNUNET_i2s (peer), | ||
252 | plugin_name); | ||
253 | break; | ||
254 | } | ||
255 | } | 292 | } |
256 | /* | 293 | end: |
257 | FIXME: this gives an address that might not have been validated to | 294 | #if 1 |
258 | ATS for 'selection', which is probably not what we want; this | 295 | /* FIXME: this should not be needed, and not sure it's good to have it, but without |
259 | might be particularly wrong (as in, possibly hiding bugs with address | 296 | this connections seem to go extra-slow */ |
260 | validation) as 'GNUNET_ATS_address_update' currently ignores | ||
261 | the expiration given. | ||
262 | */ | ||
263 | if ((ats_count > 0) && (ats != NULL)) | 297 | if ((ats_count > 0) && (ats != NULL)) |
264 | GNUNET_ATS_address_update (GST_ats, peer, | 298 | GNUNET_ATS_address_update (GST_ats, peer, |
265 | plugin_name, sender_address, sender_address_len, | 299 | plugin_name, sender_address, sender_address_len, |
266 | session, | 300 | session, |
267 | ats, ats_count); | 301 | ats, ats_count); |
302 | #endif | ||
268 | return ret; | 303 | return ret; |
269 | } | 304 | } |
270 | 305 | ||
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 9676366a6..db2dce5e7 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -248,6 +248,11 @@ struct NeighbourMapEntry | |||
248 | struct GNUNET_BANDWIDTH_Tracker in_tracker; | 248 | struct GNUNET_BANDWIDTH_Tracker in_tracker; |
249 | 249 | ||
250 | /** | 250 | /** |
251 | * Timestamp of the 'SESSION_CONNECT' message we got from the other peer | ||
252 | */ | ||
253 | struct GNUNET_TIME_Absolute connect_ts; | ||
254 | |||
255 | /** | ||
251 | * How often has the other peer (recently) violated the inbound | 256 | * How often has the other peer (recently) violated the inbound |
252 | * traffic limit? Incremented by 10 per violation, decremented by 1 | 257 | * traffic limit? Incremented by 10 per violation, decremented by 1 |
253 | * per non-violation (for each time interval). | 258 | * per non-violation (for each time interval). |
@@ -642,16 +647,18 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
642 | n = lookup_neighbour (peer); | 647 | n = lookup_neighbour (peer); |
643 | if (NULL == n) | 648 | if (NULL == n) |
644 | { | 649 | { |
645 | /* FIXME: ATS not fully implemented, once ATS only generates | 650 | GNUNET_ATS_address_destroyed (GST_ats, |
646 | these events for 'connected' addresses, things should be better... */ | 651 | peer, |
647 | // GNUNET_break (0); | 652 | plugin_name, address, |
653 | address_len, session); | ||
648 | return; | 654 | return; |
649 | } | 655 | } |
650 | was_connected = n->is_connected; | 656 | was_connected = n->is_connected; |
651 | n->is_connected = GNUNET_YES; | 657 | n->is_connected = GNUNET_YES; |
652 | if (GNUNET_YES != was_connected) | 658 | if (GNUNET_YES != was_connected) |
653 | n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task, | 659 | n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, |
654 | n); | 660 | &neighbour_keepalive_task, |
661 | n); | ||
655 | 662 | ||
656 | #if DEBUG_TRANSPORT | 663 | #if DEBUG_TRANSPORT |
657 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -662,7 +669,6 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
662 | address_len), | 669 | address_len), |
663 | session); | 670 | session); |
664 | #endif | 671 | #endif |
665 | |||
666 | GNUNET_free_non_null (n->addr); | 672 | GNUNET_free_non_null (n->addr); |
667 | n->addr = GNUNET_malloc (address_len); | 673 | n->addr = GNUNET_malloc (address_len); |
668 | memcpy (n->addr, address, address_len); | 674 | memcpy (n->addr, address, address_len); |
@@ -682,7 +688,6 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
682 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 688 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
683 | GST_neighbours_send (peer, &connect_msg, sizeof (connect_msg), | 689 | GST_neighbours_send (peer, &connect_msg, sizeof (connect_msg), |
684 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); | 690 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); |
685 | |||
686 | if (GNUNET_YES == was_connected) | 691 | if (GNUNET_YES == was_connected) |
687 | return; | 692 | return; |
688 | /* First tell clients about connected neighbours...*/ | 693 | /* First tell clients about connected neighbours...*/ |
@@ -692,6 +697,39 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
692 | connect_notify_cb (callback_cls, peer, ats, ats_count); | 697 | connect_notify_cb (callback_cls, peer, ats, ats_count); |
693 | } | 698 | } |
694 | 699 | ||
700 | |||
701 | /** | ||
702 | * Create an entry in the neighbour map for the given peer | ||
703 | * | ||
704 | * @param peer peer to create an entry for | ||
705 | * @return new neighbour map entry | ||
706 | */ | ||
707 | static struct NeighbourMapEntry * | ||
708 | setup_neighbour (const struct GNUNET_PeerIdentity *peer) | ||
709 | { | ||
710 | struct NeighbourMapEntry *n; | ||
711 | |||
712 | #if DEBUG_TRANSPORT | ||
713 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
714 | "Unknown peer `%s', creating new neighbour\n", | ||
715 | GNUNET_i2s (peer)); | ||
716 | #endif | ||
717 | n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); | ||
718 | n->id = *peer; | ||
719 | GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, | ||
720 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | ||
721 | MAX_BANDWIDTH_CARRY_S); | ||
722 | n->timeout_task = | ||
723 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
724 | &neighbour_timeout_task, n); | ||
725 | GNUNET_assert (GNUNET_OK == | ||
726 | GNUNET_CONTAINER_multihashmap_put (neighbours, | ||
727 | &n->id.hashPubKey, n, | ||
728 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
729 | return n; | ||
730 | } | ||
731 | |||
732 | |||
695 | /** | 733 | /** |
696 | * Try to create a connection to the given target (eventually). | 734 | * Try to create a connection to the given target (eventually). |
697 | * | 735 | * |
@@ -703,12 +741,10 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
703 | struct NeighbourMapEntry *n; | 741 | struct NeighbourMapEntry *n; |
704 | 742 | ||
705 | GNUNET_assert (neighbours != NULL); | 743 | GNUNET_assert (neighbours != NULL); |
706 | |||
707 | #if DEBUG_TRANSPORT | 744 | #if DEBUG_TRANSPORT |
708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n", | 745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n", |
709 | GNUNET_i2s (target)); | 746 | GNUNET_i2s (target)); |
710 | #endif | 747 | #endif |
711 | |||
712 | GNUNET_assert (0 != | 748 | GNUNET_assert (0 != |
713 | memcmp (target, &GST_my_identity, | 749 | memcmp (target, &GST_my_identity, |
714 | sizeof (struct GNUNET_PeerIdentity))); | 750 | sizeof (struct GNUNET_PeerIdentity))); |
@@ -716,31 +752,13 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
716 | if ((NULL != n) && (GNUNET_YES == n->is_connected)) | 752 | if ((NULL != n) && (GNUNET_YES == n->is_connected)) |
717 | return; /* already connected */ | 753 | return; /* already connected */ |
718 | if (n == NULL) | 754 | if (n == NULL) |
719 | { | 755 | n = setup_neighbour (target); |
720 | #if DEBUG_TRANSPORT | ||
721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
722 | "Unknown peer `%s', creating new neighbour\n", | ||
723 | GNUNET_i2s (target)); | ||
724 | #endif | ||
725 | n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); | ||
726 | n->id = *target; | ||
727 | GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, | ||
728 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | ||
729 | MAX_BANDWIDTH_CARRY_S); | ||
730 | n->timeout_task = | ||
731 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
732 | &neighbour_timeout_task, n); | ||
733 | GNUNET_assert (GNUNET_OK == | ||
734 | GNUNET_CONTAINER_multihashmap_put (neighbours, | ||
735 | &n->id.hashPubKey, n, | ||
736 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
737 | } | ||
738 | #if DEBUG_TRANSPORT | 756 | #if DEBUG_TRANSPORT |
739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
740 | "Asking ATS for suggested address to connect to peer `%s'\n", | 758 | "Asking ATS for suggested address to connect to peer `%s'\n", |
741 | GNUNET_i2s (target)); | 759 | GNUNET_i2s (&n->id)); |
742 | #endif | 760 | #endif |
743 | GNUNET_ATS_suggest_address (GST_ats, target); | 761 | GNUNET_ATS_suggest_address (GST_ats, &n->id); |
744 | } | 762 | } |
745 | 763 | ||
746 | 764 | ||
@@ -783,7 +801,10 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | |||
783 | "Session %X to peer `%s' ended \n", | 801 | "Session %X to peer `%s' ended \n", |
784 | session, GNUNET_i2s (peer)); | 802 | session, GNUNET_i2s (peer)); |
785 | #endif | 803 | #endif |
786 | 804 | GNUNET_ATS_address_destroyed (GST_ats, | |
805 | peer, | ||
806 | NULL, NULL, 0, | ||
807 | session); | ||
787 | n = lookup_neighbour (peer); | 808 | n = lookup_neighbour (peer); |
788 | if (NULL == n) | 809 | if (NULL == n) |
789 | return; | 810 | return; |
@@ -894,7 +915,8 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, | |||
894 | * @param sender sender of the message | 915 | * @param sender sender of the message |
895 | * @param size size of the message | 916 | * @param size size of the message |
896 | * @param do_forward set to GNUNET_YES if the message should be forwarded to clients | 917 | * @param do_forward set to GNUNET_YES if the message should be forwarded to clients |
897 | * GNUNET_NO if the neighbour is not connected or violates the quota | 918 | * GNUNET_NO if the neighbour is not connected or violates the quota, |
919 | * GNUNET_SYSERR if the connection is not fully up yet | ||
898 | * @return how long to wait before reading more from this sender | 920 | * @return how long to wait before reading more from this sender |
899 | */ | 921 | */ |
900 | struct GNUNET_TIME_Relative | 922 | struct GNUNET_TIME_Relative |
@@ -917,7 +939,7 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity | |||
917 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 939 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
918 | _("Plugin gave us %d bytes of data but somehow the session is not marked as UP yet!\n"), | 940 | _("Plugin gave us %d bytes of data but somehow the session is not marked as UP yet!\n"), |
919 | (int) size); | 941 | (int) size); |
920 | *do_forward = GNUNET_NO; | 942 | *do_forward = GNUNET_SYSERR; |
921 | return GNUNET_TIME_UNIT_ZERO; | 943 | return GNUNET_TIME_UNIT_ZERO; |
922 | } | 944 | } |
923 | if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size)) | 945 | if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size)) |
@@ -1141,4 +1163,53 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) | |||
1141 | } | 1163 | } |
1142 | 1164 | ||
1143 | 1165 | ||
1166 | /** | ||
1167 | * We received a 'SESSION_CONNECT' message from the other peer. | ||
1168 | * Consider switching to it. | ||
1169 | * | ||
1170 | * @param message possibly a 'struct SessionConnectMessage' (check format) | ||
1171 | * @param peer identity of the peer to switch the address for | ||
1172 | * @param plugin_name name of transport that delivered the PONG | ||
1173 | * @param address address of the other peer, NULL if other peer | ||
1174 | * connected to us | ||
1175 | * @param address_len number of bytes in address | ||
1176 | * @param session session to use (or NULL) | ||
1177 | * @param ats performance data | ||
1178 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
1179 | */ | ||
1180 | void | ||
1181 | GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, | ||
1182 | const struct GNUNET_PeerIdentity *peer, | ||
1183 | const char *plugin_name, | ||
1184 | const char *sender_address, uint16_t sender_address_len, | ||
1185 | struct Session *session, | ||
1186 | const struct GNUNET_ATS_Information *ats, | ||
1187 | uint32_t ats_count) | ||
1188 | { | ||
1189 | const struct SessionConnectMessage *scm; | ||
1190 | struct GNUNET_TIME_Absolute ts; | ||
1191 | struct NeighbourMapEntry *n; | ||
1192 | |||
1193 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) | ||
1194 | { | ||
1195 | GNUNET_break_op (0); | ||
1196 | return; | ||
1197 | } | ||
1198 | scm = (const struct SessionConnectMessage *) message; | ||
1199 | GNUNET_break_op (ntohl (scm->reserved) == 0); | ||
1200 | ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); | ||
1201 | n = lookup_neighbour (peer); | ||
1202 | if (NULL == n) | ||
1203 | n = setup_neighbour (peer); | ||
1204 | if (ts.abs_value > n->connect_ts.abs_value) | ||
1205 | { | ||
1206 | GNUNET_ATS_address_update (GST_ats, | ||
1207 | peer, | ||
1208 | plugin_name, sender_address, sender_address_len, | ||
1209 | session, ats, ats_count); | ||
1210 | n->connect_ts = ts; | ||
1211 | } | ||
1212 | } | ||
1213 | |||
1214 | |||
1144 | /* end of file gnunet-service-transport_neighbours.c */ | 1215 | /* end of file gnunet-service-transport_neighbours.c */ |
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 5b4929c2c..2f6962a67 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h | |||
@@ -209,5 +209,29 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
209 | *ats, uint32_t ats_count); | 209 | *ats, uint32_t ats_count); |
210 | 210 | ||
211 | 211 | ||
212 | /** | ||
213 | * We received a 'SESSION_CONNECT' message from the other peer. | ||
214 | * Consider switching to it. | ||
215 | * | ||
216 | * @param message possibly a 'struct SessionConnectMessage' (check format) | ||
217 | * @param peer identity of the peer to switch the address for | ||
218 | * @param plugin_name name of transport that delivered the PONG | ||
219 | * @param address address of the other peer, NULL if other peer | ||
220 | * connected to us | ||
221 | * @param address_len number of bytes in address | ||
222 | * @param session session to use (or NULL) | ||
223 | * @param ats performance data | ||
224 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
225 | */ | ||
226 | void | ||
227 | GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, | ||
228 | const struct GNUNET_PeerIdentity *peer, | ||
229 | const char *plugin_name, | ||
230 | const char *sender_address, uint16_t sender_address_len, | ||
231 | struct Session *session, | ||
232 | const struct GNUNET_ATS_Information *ats, | ||
233 | uint32_t ats_count); | ||
234 | |||
235 | |||
212 | #endif | 236 | #endif |
213 | /* end of file gnunet-service-transport_neighbours.h */ | 237 | /* end of file gnunet-service-transport_neighbours.h */ |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index d3391e1b2..546c2aa36 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -696,6 +696,10 @@ do_transmit (void *cls, size_t size, void *buf) | |||
696 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 696 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
697 | session->pending_messages_tail, pos); | 697 | session->pending_messages_tail, pos); |
698 | GNUNET_assert (size >= pos->message_size); | 698 | GNUNET_assert (size >= pos->message_size); |
699 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
700 | "tcp", | ||
701 | "Transmitting message of type %u\n", | ||
702 | ntohs (((struct GNUNET_MessageHeader*)pos->msg)->type)); | ||
699 | /* FIXME: this memcpy can be up to 7% of our total runtime */ | 703 | /* FIXME: this memcpy can be up to 7% of our total runtime */ |
700 | memcpy (cbuf, pos->msg, pos->message_size); | 704 | memcpy (cbuf, pos->msg, pos->message_size); |
701 | cbuf += pos->message_size; | 705 | cbuf += pos->message_size; |
@@ -1706,7 +1710,7 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
1706 | return; | 1710 | return; |
1707 | } | 1711 | } |
1708 | session->last_activity = GNUNET_TIME_absolute_get (); | 1712 | session->last_activity = GNUNET_TIME_absolute_get (); |
1709 | #if DEBUG_TCP > 1 | 1713 | #if DEBUG_TCP |
1710 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", | 1714 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", |
1711 | "Passing %u bytes of type %u from `%4s' to transport service.\n", | 1715 | "Passing %u bytes of type %u from `%4s' to transport service.\n", |
1712 | (unsigned int) ntohs (message->size), | 1716 | (unsigned int) ntohs (message->size), |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 440b0dfed..b4ddd0a7f 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -205,11 +205,6 @@ struct InboundMessage | |||
205 | struct GNUNET_MessageHeader header; | 205 | struct GNUNET_MessageHeader header; |
206 | 206 | ||
207 | /** | 207 | /** |
208 | * Always zero. | ||
209 | */ | ||
210 | uint32_t reserved GNUNET_PACKED; | ||
211 | |||
212 | /** | ||
213 | * Number of ATS key-value pairs that follow this struct | 208 | * Number of ATS key-value pairs that follow this struct |
214 | * (excluding the 0-terminator). | 209 | * (excluding the 0-terminator). |
215 | */ | 210 | */ |
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index a258172d5..41ef306b7 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -543,7 +543,6 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) | |||
543 | break; | 543 | break; |
544 | } | 544 | } |
545 | im = (const struct InboundMessage *) msg; | 545 | im = (const struct InboundMessage *) msg; |
546 | GNUNET_break (0 == ntohl (im->reserved)); | ||
547 | ats_count = ntohl (im->ats_count); | 546 | ats_count = ntohl (im->ats_count); |
548 | imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count + 1]); | 547 | imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count + 1]); |
549 | 548 | ||