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/transport/gnunet-service-transport.c | |
parent | 2e30d52c8b5dfa6587b3cfc94ca035d51ff7b7af (diff) | |
download | gnunet-7402a01c58bc72833e5a126bc204a21d8db908d2.tar.gz gnunet-7402a01c58bc72833e5a126bc204a21d8db908d2.zip |
removing bad reserved field, small refactoring
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 201 |
1 files changed, 118 insertions, 83 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 | ||