aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-13 16:59:57 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-13 16:59:57 +0000
commit1257490cb630ade315a196a724d0233e662afb2c (patch)
tree0d9c01593a1aa73d8f6490127b640d67da69b54c /src/transport/gnunet-service-transport.c
parent35d79cb1941c9f9607195b8760d8a14d836e6397 (diff)
downloadgnunet-1257490cb630ade315a196a724d0233e662afb2c.tar.gz
gnunet-1257490cb630ade315a196a724d0233e662afb2c.zip
implementing 0003268 to inbound information in HELLO addresses
All transport plugin functions are modified to use HELLO addresses instead of peer,address,address_length All plugins are modified to use HELLO addresses internally This commit can break transport functionality: core tests on my system still pass, but transport tests may still fail, errors messages may occurs or crashs Will be fixed asap
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r--src/transport/gnunet-service-transport.c584
1 files changed, 243 insertions, 341 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index a5ce3fa4a..2c2d90dc4 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors) 3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport.c 22 * @file transport/gnunet-service-transport.c
@@ -40,7 +40,6 @@
40#include "gnunet-service-transport_manipulation.h" 40#include "gnunet-service-transport_manipulation.h"
41#include "transport.h" 41#include "transport.h"
42 42
43
44/** 43/**
45 * Information we need for an asynchronous session kill. 44 * Information we need for an asynchronous session kill.
46 */ 45 */
@@ -72,7 +71,6 @@ struct SessionKiller
72 GNUNET_SCHEDULER_TaskIdentifier task; 71 GNUNET_SCHEDULER_TaskIdentifier task;
73}; 72};
74 73
75
76/* globals */ 74/* globals */
77 75
78/** 76/**
@@ -130,7 +128,6 @@ static struct SessionKiller *sk_head;
130 */ 128 */
131static struct SessionKiller *sk_tail; 129static struct SessionKiller *sk_tail;
132 130
133
134/** 131/**
135 * Transmit our HELLO message to the given (connected) neighbour. 132 * Transmit our HELLO message to the given (connected) neighbour.
136 * 133 *
@@ -144,24 +141,21 @@ static struct SessionKiller *sk_tail;
144 */ 141 */
145static void 142static void
146transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, 143transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target,
147 const struct GNUNET_HELLO_Address *address, 144 const struct GNUNET_HELLO_Address *address,
148 enum GNUNET_TRANSPORT_PeerState state, 145 enum GNUNET_TRANSPORT_PeerState state,
149 struct GNUNET_TIME_Absolute state_timeout, 146 struct GNUNET_TIME_Absolute state_timeout,
150 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 147 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
151 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 148 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
152{ 149{
153 const struct GNUNET_MessageHeader *hello = cls; 150 const struct GNUNET_MessageHeader *hello = cls;
154 151
155 if ( GNUNET_NO == GST_neighbours_test_connected(target) ) 152 if (GNUNET_NO == GST_neighbours_test_connected (target))
156 return; 153 return;
157 154
158 GST_neighbours_send (target, 155 GST_neighbours_send (target, hello, ntohs (hello->size), hello_expiration,
159 hello, 156 NULL, NULL );
160 ntohs (hello->size),
161 hello_expiration, NULL, NULL);
162} 157}
163 158
164
165/** 159/**
166 * My HELLO has changed. Tell everyone who should know. 160 * My HELLO has changed. Tell everyone who should know.
167 * 161 *
@@ -169,14 +163,12 @@ transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target,
169 * @param hello new HELLO 163 * @param hello new HELLO
170 */ 164 */
171static void 165static void
172process_hello_update (void *cls, 166process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
173 const struct GNUNET_MessageHeader *hello)
174{ 167{
175 GST_clients_broadcast (hello, GNUNET_NO); 168 GST_clients_broadcast (hello, GNUNET_NO);
176 GST_neighbours_iterate (&transmit_our_hello, (void *) hello); 169 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
177} 170}
178 171
179
180/** 172/**
181 * We received some payload. Prepare to pass it on to our clients. 173 * We received some payload. Prepare to pass it on to our clients.
182 * 174 *
@@ -188,30 +180,26 @@ process_hello_update (void *cls,
188 */ 180 */
189static struct GNUNET_TIME_Relative 181static struct GNUNET_TIME_Relative
190process_payload (const struct GNUNET_PeerIdentity *peer, 182process_payload (const struct GNUNET_PeerIdentity *peer,
191 const struct GNUNET_HELLO_Address *address, 183 const struct GNUNET_HELLO_Address *address, struct Session *session,
192 struct Session *session, 184 const struct GNUNET_MessageHeader *message)
193 const struct GNUNET_MessageHeader *message)
194{ 185{
195 struct GNUNET_TIME_Relative ret; 186 struct GNUNET_TIME_Relative ret;
196 int do_forward; 187 int do_forward;
197 struct InboundMessage *im; 188 struct InboundMessage *im;
198 size_t msg_size = ntohs (message->size); 189 size_t msg_size = ntohs (message->size);
199 size_t size = 190 size_t size = sizeof(struct InboundMessage) + msg_size;
200 sizeof (struct InboundMessage) + msg_size;
201 char buf[size] GNUNET_ALIGN; 191 char buf[size] GNUNET_ALIGN;
202 192
203 do_forward = GNUNET_SYSERR; 193 do_forward = GNUNET_SYSERR;
204 ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward); 194 ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward);
205 if (! GST_neighbours_test_connected (peer)) 195 if (!GST_neighbours_test_connected (peer))
206 { 196 {
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 197 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
208 "Discarded %u bytes type %u payload from peer `%s'\n", 198 "Discarded %u bytes type %u payload from peer `%s'\n", msg_size,
209 msg_size, 199 ntohs (message->type), GNUNET_i2s (peer));
210 ntohs (message->type), GNUNET_i2s (peer)); 200 GNUNET_STATISTICS_update (GST_stats, gettext_noop
211 GNUNET_STATISTICS_update (GST_stats, 201 ("# bytes payload discarded due to not connected peer"), msg_size,
212 gettext_noop 202 GNUNET_NO);
213 ("# bytes payload discarded due to not connected peer"),
214 msg_size, GNUNET_NO);
215 return ret; 203 return ret;
216 } 204 }
217 205
@@ -228,7 +216,6 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
228 return ret; 216 return ret;
229} 217}
230 218
231
232/** 219/**
233 * Task to asynchronously terminate a session. 220 * Task to asynchronously terminate a session.
234 * 221 *
@@ -236,19 +223,16 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
236 * @param tc scheduler context 223 * @param tc scheduler context
237 */ 224 */
238static void 225static void
239kill_session_task (void *cls, 226kill_session_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
240 const struct GNUNET_SCHEDULER_TaskContext *tc)
241{ 227{
242 struct SessionKiller *sk = cls; 228 struct SessionKiller *sk = cls;
243 229
244 sk->task = GNUNET_SCHEDULER_NO_TASK; 230 sk->task = GNUNET_SCHEDULER_NO_TASK;
245 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); 231 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk);
246 sk->plugin->disconnect_session (sk->plugin->cls, 232 sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
247 sk->session); 233 GNUNET_free(sk);
248 GNUNET_free (sk);
249} 234}
250 235
251
252/** 236/**
253 * Force plugin to terminate session due to communication 237 * Force plugin to terminate session due to communication
254 * issue. 238 * issue.
@@ -257,8 +241,7 @@ kill_session_task (void *cls,
257 * @param session session to termiante 241 * @param session session to termiante
258 */ 242 */
259static void 243static void
260kill_session (const char *plugin_name, 244kill_session (const char *plugin_name, struct Session *session)
261 struct Session *session)
262{ 245{
263 struct GNUNET_TRANSPORT_PluginFunctions *plugin; 246 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
264 struct SessionKiller *sk; 247 struct SessionKiller *sk;
@@ -269,19 +252,17 @@ kill_session (const char *plugin_name,
269 plugin = GST_plugins_find (plugin_name); 252 plugin = GST_plugins_find (plugin_name);
270 if (NULL == plugin) 253 if (NULL == plugin)
271 { 254 {
272 GNUNET_break (0); 255 GNUNET_break(0);
273 return; 256 return;
274 } 257 }
275 /* need to issue disconnect asynchronously */ 258 /* need to issue disconnect asynchronously */
276 sk = GNUNET_new (struct SessionKiller); 259 sk = GNUNET_new (struct SessionKiller);
277 sk->session = session; 260 sk->session = session;
278 sk->plugin = plugin; 261 sk->plugin = plugin;
279 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, 262 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
280 sk); 263 GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk);
281 GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk);
282} 264}
283 265
284
285/** 266/**
286 * Function called by the transport for each received message. 267 * Function called by the transport for each received message.
287 * 268 *
@@ -303,35 +284,25 @@ kill_session (const char *plugin_name,
303 */ 284 */
304struct GNUNET_TIME_Relative 285struct GNUNET_TIME_Relative
305GST_receive_callback (void *cls, 286GST_receive_callback (void *cls,
306 const struct GNUNET_PeerIdentity *peer, 287 const struct GNUNET_HELLO_Address *address,
307 const struct GNUNET_MessageHeader *message,
308 struct Session *session, 288 struct Session *session,
309 const char *sender_address, 289 const struct GNUNET_MessageHeader *message)
310 uint16_t sender_address_len)
311{ 290{
312 const char *plugin_name = cls; 291 const char *plugin_name = cls;
313 struct GNUNET_TIME_Relative ret; 292 struct GNUNET_TIME_Relative ret;
314 struct GNUNET_HELLO_Address address;
315 uint16_t type; 293 uint16_t type;
316 294
317 address.peer = *peer;
318 address.address = sender_address;
319 address.address_length = sender_address_len;
320 address.transport_name = plugin_name;
321 ret = GNUNET_TIME_UNIT_ZERO; 295 ret = GNUNET_TIME_UNIT_ZERO;
322 if (NULL == message) 296 if (NULL == message)
323 goto end; 297 goto end;
324 type = ntohs (message->type); 298 type = ntohs (message->type);
325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 299 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
326 "Received Message with type %u from peer `%s'\n", 300 "Received Message with type %u from peer `%s'\n", type,
327 type, 301 GNUNET_i2s (&address->peer));
328 GNUNET_i2s (peer));
329 302
330 GNUNET_STATISTICS_update (GST_stats, 303 GNUNET_STATISTICS_update (GST_stats, gettext_noop
331 gettext_noop 304 ("# bytes total received"), ntohs (message->size), GNUNET_NO);
332 ("# bytes total received"), 305 GST_neighbours_notify_data_recv (&address->peer, address, session, message);
333 ntohs (message->size), GNUNET_NO);
334 GST_neighbours_notify_data_recv (peer, &address, session, message);
335 306
336 switch (type) 307 switch (type)
337 { 308 {
@@ -339,85 +310,76 @@ GST_receive_callback (void *cls,
339 /* Legacy HELLO message, discard */ 310 /* Legacy HELLO message, discard */
340 return ret; 311 return ret;
341 case GNUNET_MESSAGE_TYPE_HELLO: 312 case GNUNET_MESSAGE_TYPE_HELLO:
342 if (GNUNET_OK != 313 if (GNUNET_OK != GST_validation_handle_hello (message))
343 GST_validation_handle_hello (message))
344 { 314 {
345 GNUNET_break_op (0); 315 GNUNET_break_op(0);
346 kill_session (plugin_name, session); 316 kill_session (plugin_name, session);
347 } 317 }
348 return ret; 318 return ret;
349 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: 319 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
351 "Processing `%s' from `%s'\n", "PING", 321 "Processing `%s' from `%s'\n", "PING", GST_plugins_a2s (address));
352 (sender_address != 322 if (GNUNET_OK
353 NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING); 323 != GST_validation_handle_ping (&address->peer, message, address, session))
354 if (GNUNET_OK !=
355 GST_validation_handle_ping (peer, message, &address, session))
356 kill_session (plugin_name, session); 324 kill_session (plugin_name, session);
357 break; 325 break;
358 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 326 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 327 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
360 "Processing `%s' from `%s'\n", "PONG", 328 "Processing `%s' from `%s'\n", "PONG",
361 (sender_address != 329 GST_plugins_a2s (address));
362 NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING); 330 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
363 if (GNUNET_OK !=
364 GST_validation_handle_pong (peer, message))
365 { 331 {
366 GNUNET_break_op (0); 332 GNUNET_break_op(0);
367 kill_session (plugin_name, session); 333 kill_session (plugin_name, session);
368 } 334 }
369 break; 335 break;
370 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: 336 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
371 if (GNUNET_OK != 337 if (GNUNET_OK
372 GST_neighbours_handle_connect (message, peer, &address, session)) 338 != GST_neighbours_handle_connect (message, &address->peer, address, session))
373 { 339 {
374 GNUNET_break_op (0); 340 GNUNET_break_op(0);
375 kill_session (plugin_name, session); 341 kill_session (plugin_name, session);
376 } 342 }
377 break; 343 break;
378 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: 344 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK:
379 if (GNUNET_OK != 345 if (GNUNET_OK
380 GST_neighbours_handle_connect_ack (message, peer, &address, session)) 346 != GST_neighbours_handle_connect_ack (message, &address->peer, address, session))
381 { 347 {
382 kill_session (plugin_name, session); 348 kill_session (plugin_name, session);
383 } 349 }
384 break; 350 break;
385 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: 351 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
386 if (GNUNET_OK != 352 if (GNUNET_OK
387 GST_neighbours_handle_session_ack (message, peer, &address, session)) 353 != GST_neighbours_handle_session_ack (message, &address->peer, address, session))
388 { 354 {
389 GNUNET_break_op (0); 355 GNUNET_break_op(0);
390 kill_session (plugin_name, session); 356 kill_session (plugin_name, session);
391 } 357 }
392 break; 358 break;
393 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 359 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
394 GST_neighbours_handle_disconnect_message (peer, message); 360 GST_neighbours_handle_disconnect_message (&address->peer, message);
395 break; 361 break;
396 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: 362 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
397 GST_neighbours_keepalive (peer, message); 363 GST_neighbours_keepalive (&address->peer, message);
398 break; 364 break;
399 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: 365 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
400 GST_neighbours_keepalive_response (peer, message); 366 GST_neighbours_keepalive_response (&address->peer, message);
401 break; 367 break;
402 default: 368 default:
403 /* should be payload */ 369 /* should be payload */
404 GNUNET_STATISTICS_update (GST_stats, 370 GNUNET_STATISTICS_update (GST_stats, gettext_noop
405 gettext_noop 371 ("# bytes payload received"), ntohs (message->size), GNUNET_NO);
406 ("# bytes payload received"), 372 GST_neighbours_notify_payload_recv (&address->peer, address, session, message);
407 ntohs (message->size), GNUNET_NO); 373 ret = process_payload (&address->peer, address, session, message);
408 GST_neighbours_notify_payload_recv (peer, &address, session, message);
409 ret = process_payload (peer, &address, session, message);
410 break; 374 break;
411 } 375 }
412end: 376 end:
413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 377 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
414 "Allowing receive from peer %s to continue in %s\n", 378 "Allowing receive from peer %s to continue in %s\n", GNUNET_i2s (&address->peer),
415 GNUNET_i2s (peer), 379 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
416 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
417 return ret; 380 return ret;
418} 381}
419 382
420
421/** 383/**
422 * Function that will be called for each address the transport 384 * Function that will be called for each address the transport
423 * is aware that it might be reachable under. Update our HELLO. 385 * is aware that it might be reachable under. Update our HELLO.
@@ -425,26 +387,15 @@ end:
425 * @param cls name of the plugin (const char*) 387 * @param cls name of the plugin (const char*)
426 * @param add_remove should the address added (YES) or removed (NO) from the 388 * @param add_remove should the address added (YES) or removed (NO) from the
427 * set of valid addresses? 389 * set of valid addresses?
428 * @param addr one of the addresses of the host 390 * @param address the address to add or remove
429 * the specific address format depends on the transport
430 * @param addrlen length of the @a addr
431 * @param dest_plugin destination plugin to use this address with
432 */ 391 */
433static void 392static void
434plugin_env_address_change_notification (void *cls, int add_remove, 393plugin_env_address_change_notification (void *cls, int add_remove,
435 const void *addr, size_t addrlen, 394 const struct GNUNET_HELLO_Address *address)
436 const char *dest_plugin)
437{ 395{
438 struct GNUNET_HELLO_Address address; 396 GST_hello_modify_addresses (add_remove, address);
439
440 address.peer = GST_my_identity;
441 address.transport_name = dest_plugin;
442 address.address = addr;
443 address.address_length = addrlen;
444 GST_hello_modify_addresses (add_remove, &address);
445} 397}
446 398
447
448/** 399/**
449 * Function that will be called whenever the plugin internally 400 * Function that will be called whenever the plugin internally
450 * cleans up a session pointer and hence the service needs to 401 * cleans up a session pointer and hence the service needs to
@@ -460,22 +411,21 @@ plugin_env_address_change_notification (void *cls, int add_remove,
460 */ 411 */
461static void 412static void
462plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, 413plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
463 struct Session *session) 414 struct Session *session)
464{ 415{
465 const char *transport_name = cls; 416 const char *transport_name = cls;
466 struct GNUNET_HELLO_Address address; 417 struct GNUNET_HELLO_Address address;
467 struct SessionKiller *sk; 418 struct SessionKiller *sk;
468 419
469 GNUNET_assert (strlen (transport_name) > 0); 420 GNUNET_assert(strlen (transport_name) > 0);
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' ended \n",
471 "Session %p to peer `%s' ended \n", 422 session, GNUNET_i2s (peer));
472 session,
473 GNUNET_i2s (peer));
474 if (NULL != session) 423 if (NULL != session)
475 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 424 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
476 "transport-ats", 425 "transport-ats", "Telling ATS to destroy session %p from peer %s\n",
477 "Telling ATS to destroy session %p from peer %s\n", 426 session, GNUNET_i2s (peer));
478 session, GNUNET_i2s (peer)); 427
428 memset (&address, '\0', sizeof (address));
479 address.peer = *peer; 429 address.peer = *peer;
480 address.address = NULL; 430 address.address = NULL;
481 address.address_length = 0; 431 address.address_length = 0;
@@ -488,15 +438,14 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
488 { 438 {
489 if (sk->session == session) 439 if (sk->session == session)
490 { 440 {
491 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); 441 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk);
492 GNUNET_SCHEDULER_cancel (sk->task); 442 GNUNET_SCHEDULER_cancel (sk->task);
493 GNUNET_free (sk); 443 GNUNET_free(sk);
494 break; 444 break;
495 } 445 }
496 } 446 }
497} 447}
498 448
499
500/** 449/**
501 * Function that will be called to figure if an address is an loopback, 450 * Function that will be called to figure if an address is an loopback,
502 * LAN, WAN etc. address 451 * LAN, WAN etc. address
@@ -507,9 +456,8 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
507 * @return ATS Information containing the network type 456 * @return ATS Information containing the network type
508 */ 457 */
509static struct GNUNET_ATS_Information 458static struct GNUNET_ATS_Information
510plugin_env_address_to_type (void *cls, 459plugin_env_address_to_type (void *cls, const struct sockaddr *addr,
511 const struct sockaddr *addr, 460 size_t addrlen)
512 size_t addrlen)
513{ 461{
514 struct GNUNET_ATS_Information ats; 462 struct GNUNET_ATS_Information ats;
515 463
@@ -517,24 +465,23 @@ plugin_env_address_to_type (void *cls,
517 ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); 465 ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED);
518 if (NULL == GST_ats) 466 if (NULL == GST_ats)
519 { 467 {
520 GNUNET_break (0); 468 GNUNET_break(0);
521 return ats; 469 return ats;
522 } 470 }
523 if (((addr->sa_family != AF_INET) && (addrlen != sizeof (struct sockaddr_in))) && 471 if (((addr->sa_family != AF_INET) && (addrlen != sizeof(struct sockaddr_in)))
524 ((addr->sa_family != AF_INET6) && (addrlen != sizeof (struct sockaddr_in6))) && 472 && ((addr->sa_family != AF_INET6)
525 (addr->sa_family != AF_UNIX)) 473 && (addrlen != sizeof(struct sockaddr_in6)))
474 && (addr->sa_family != AF_UNIX))
526 { 475 {
527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 476 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
528 "Malformed address with length %u `%s'\n", 477 "Malformed address with length %u `%s'\n", addrlen,
529 addrlen, 478 GNUNET_a2s (addr, addrlen));
530 GNUNET_a2s (addr, addrlen)); 479 GNUNET_break(0);
531 GNUNET_break (0);
532 return ats; 480 return ats;
533 } 481 }
534 return GNUNET_ATS_address_get_type (GST_ats, addr, addrlen); 482 return GNUNET_ATS_address_get_type (GST_ats, addr, addrlen);
535} 483}
536 484
537
538/** 485/**
539 * Notify ATS about the new address including the network this address is 486 * Notify ATS about the new address including the network this address is
540 * located in. 487 * located in.
@@ -546,9 +493,8 @@ plugin_env_address_to_type (void *cls,
546 */ 493 */
547void 494void
548GST_ats_add_address (const struct GNUNET_HELLO_Address *address, 495GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
549 struct Session *session, 496 struct Session *session, const struct GNUNET_ATS_Information *ats,
550 const struct GNUNET_ATS_Information *ats, 497 uint32_t ats_count)
551 uint32_t ats_count)
552{ 498{
553 struct GNUNET_TRANSPORT_PluginFunctions *papi; 499 struct GNUNET_TRANSPORT_PluginFunctions *papi;
554 struct GNUNET_ATS_Information ats2[ats_count + 1]; 500 struct GNUNET_ATS_Information ats2[ats_count + 1];
@@ -557,48 +503,43 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
557 /* valid new address, let ATS know! */ 503 /* valid new address, let ATS know! */
558 if (NULL == address->transport_name) 504 if (NULL == address->transport_name)
559 { 505 {
560 GNUNET_break (0); 506 GNUNET_break(0);
561 return; 507 return;
562 } 508 }
563 if (NULL == (papi = GST_plugins_find (address->transport_name))) 509 if (NULL == (papi = GST_plugins_find (address->transport_name)))
564 { 510 {
565 /* we don't have the plugin for this address */ 511 /* we don't have the plugin for this address */
566 GNUNET_break (0); 512 GNUNET_break(0);
567 return; 513 return;
568 } 514 }
569 515
570 if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session)) 516 if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session))
571 { 517 {
572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 518 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
573 "ATS already knows the address, not passing it on again\n"); 519 "ATS already knows the address, not passing it on again\n");
574 return; 520 return;
575 } 521 }
576 522
577 net = papi->get_network (NULL, session); 523 net = papi->get_network (NULL, session);
578 if (GNUNET_ATS_NET_UNSPECIFIED == net) 524 if (GNUNET_ATS_NET_UNSPECIFIED == net)
579 { 525 {
580 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 526 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
581 _("Could not obtain a valid network for `%s' %s (%s)\n"), 527 _("Could not obtain a valid network for `%s' %s (%s)\n"),
582 GNUNET_i2s (&address->peer), 528 GNUNET_i2s (&address->peer), GST_plugins_a2s (address),
583 GST_plugins_a2s (address), 529 address->transport_name);
584 address->transport_name); 530 GNUNET_break(0);
585 GNUNET_break (0);
586 } 531 }
587 ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); 532 ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
588 ats2[0].value = htonl(net); 533 ats2[0].value = htonl (net);
589 memcpy (&ats2[1], ats, sizeof (struct GNUNET_ATS_Information) * ats_count); 534 memcpy (&ats2[1], ats, sizeof(struct GNUNET_ATS_Information) * ats_count);
590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 535 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
591 "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", 536 "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n",
592 GNUNET_i2s (&address->peer), 537 GNUNET_i2s (&address->peer),
593 (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), 538 (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address),
594 session, 539 session, GNUNET_ATS_print_network_type (net));
595 GNUNET_ATS_print_network_type(net)); 540 GNUNET_ATS_address_add (GST_ats, address, session, ats2, ats_count + 1);
596 GNUNET_ATS_address_add (GST_ats,
597 address, session,
598 ats2, ats_count + 1);
599} 541}
600 542
601
602/** 543/**
603 * Notify ATS about property changes to an address 544 * Notify ATS about property changes to an address
604 * 545 *
@@ -610,10 +551,8 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
610 */ 551 */
611void 552void
612GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, 553GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
613 const struct GNUNET_HELLO_Address *address, 554 const struct GNUNET_HELLO_Address *address, struct Session *session,
614 struct Session *session, 555 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
615 const struct GNUNET_ATS_Information *ats,
616 uint32_t ats_count)
617{ 556{
618 struct GNUNET_ATS_Information *ats_new; 557 struct GNUNET_ATS_Information *ats_new;
619 558
@@ -622,26 +561,23 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
622 561
623 /* Call to manipulation to manipulate ATS information */ 562 /* Call to manipulation to manipulate ATS information */
624 ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats, 563 ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats,
625 ats_count); 564 ats_count);
626 if (NULL == ats_new) 565 if (NULL == ats_new)
627 { 566 {
628 GNUNET_break(0); 567 GNUNET_break(0);
629 return; 568 return;
630 } 569 }
631 if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats, 570 if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats, address, session,
632 address, session, ats_new, ats_count)) 571 ats_new, ats_count))
633 { 572 {
634 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 573 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
635 _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"), 574 _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"),
636 GNUNET_i2s (peer), 575 GNUNET_i2s (peer), address->transport_name, GST_plugins_a2s (address),
637 address->transport_name, 576 session);
638 GST_plugins_a2s (address),
639 session);
640 } 577 }
641 GNUNET_free (ats_new); 578 GNUNET_free(ats_new);
642} 579}
643 580
644
645/** 581/**
646 * Function that will be called to figure if an address is an loopback, 582 * Function that will be called to figure if an address is an loopback,
647 * LAN, WAN etc. address 583 * LAN, WAN etc. address
@@ -656,63 +592,37 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
656 */ 592 */
657static void 593static void
658plugin_env_update_metrics (void *cls, 594plugin_env_update_metrics (void *cls,
659 const struct GNUNET_PeerIdentity *peer, 595 const struct GNUNET_HELLO_Address *address,
660 const void *address, 596 struct Session *session,
661 uint16_t address_len, 597 const struct GNUNET_ATS_Information *ats,
662 struct Session *session, 598 uint32_t ats_count)
663 const struct GNUNET_ATS_Information *ats,
664 uint32_t ats_count)
665{ 599{
666 const char *plugin_name = cls;
667 struct GNUNET_HELLO_Address haddress;
668
669 if ((NULL == ats) || (0 == ats_count)) 600 if ((NULL == ats) || (0 == ats_count))
670 return; 601 return;
671 GNUNET_assert (NULL != GST_ats); 602 GNUNET_assert(NULL != GST_ats);
672
673 haddress.peer = *peer;
674 haddress.address = address;
675 haddress.address_length = address_len;
676 haddress.transport_name = plugin_name;
677
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
679 "Updating metrics for peer `%s' address %s session %p\n",
680 GNUNET_i2s (peer),
681 GST_plugins_a2s (&haddress),
682 session);
683 GST_ats_update_metrics (peer, &haddress, session, ats, ats_count);
684}
685 603
604 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
605 "Updating metrics for peer `%s' address %s session %p\n",
606 GNUNET_i2s (&address->peer), GST_plugins_a2s (address), session);
607 GST_ats_update_metrics (&address->peer, address, session, ats, ats_count);
608}
686 609
687/** 610/**
688 * Plugin tells transport service about a new (inbound) session 611 * Plugin tells transport service about a new inbound session
689 * 612 *
690 * @param cls unused 613 * @param cls unused
691 * @param peer the peer 614 * @param address the address
692 * @param plugin plugin name
693 * @param address address
694 * @param address_len @a address length
695 * @param session the new session 615 * @param session the new session
696 * @param ats ats information 616 * @param ats ats information
697 * @param ats_count number of @a ats information 617 * @param ats_count number of @a ats information
698 */ 618 */
699static void 619static void
700plugin_env_session_start (void *cls, 620plugin_env_session_start (void *cls, struct GNUNET_HELLO_Address *address,
701 const struct GNUNET_PeerIdentity *peer, 621 struct Session *session, const struct GNUNET_ATS_Information *ats,
702 const char *plugin, 622 uint32_t ats_count)
703 const void *address, uint16_t address_len,
704 struct Session *session,
705 const struct GNUNET_ATS_Information *ats,
706 uint32_t ats_count)
707{ 623{
708 struct GNUNET_HELLO_Address *addr; 624 int inbound;
709 625 if (NULL == address)
710 if (NULL == peer)
711 {
712 GNUNET_break(0);
713 return;
714 }
715 if (NULL == plugin)
716 { 626 {
717 GNUNET_break(0); 627 GNUNET_break(0);
718 return; 628 return;
@@ -723,17 +633,18 @@ plugin_env_session_start (void *cls,
723 return; 633 return;
724 } 634 }
725 635
726 addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len); 636 if (GNUNET_HELLO_ADDRESS_INFO_INBOUND
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 637 == (address->local_info & GNUNET_HELLO_ADDRESS_INFO_INBOUND))
728 "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n", 638 inbound = GNUNET_YES;
729 plugin, 639 else
730 session, 640 inbound = GNUNET_NO;
731 GNUNET_i2s (peer),
732 GST_plugins_a2s (addr));
733 GST_ats_add_address (addr, session, ats, ats_count);
734 GNUNET_free(addr);
735}
736 641
642 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
643 "Notification from plugin `%s' about new %s session %p from peer `%s' address `%s'\n",
644 address->transport_name, (GNUNET_YES == inbound) ? "inbound" : "outbound",
645 session, GNUNET_i2s (&address->peer), GST_plugins_a2s (address));
646 GST_ats_add_address (address, session, ats, ats_count);
647}
737 648
738/** 649/**
739 * Function called by ATS to notify the callee that the 650 * Function called by ATS to notify the callee that the
@@ -753,14 +664,11 @@ plugin_env_session_start (void *cls,
753 * @param ats_count number of @a ats elements 664 * @param ats_count number of @a ats elements
754 */ 665 */
755static void 666static void
756ats_request_address_change (void *cls, 667ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer,
757 const struct GNUNET_PeerIdentity *peer, 668 const struct GNUNET_HELLO_Address *address, struct Session *session,
758 const struct GNUNET_HELLO_Address *address, 669 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
759 struct Session *session, 670 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
760 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 671 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
761 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
762 const struct GNUNET_ATS_Information *ats,
763 uint32_t ats_count)
764{ 672{
765 uint32_t bw_in = ntohl (bandwidth_in.value__); 673 uint32_t bw_in = ntohl (bandwidth_in.value__);
766 uint32_t bw_out = ntohl (bandwidth_out.value__); 674 uint32_t bw_out = ntohl (bandwidth_out.value__);
@@ -768,19 +676,17 @@ ats_request_address_change (void *cls,
768 /* ATS tells me to disconnect from peer */ 676 /* ATS tells me to disconnect from peer */
769 if ((0 == bw_in) && (0 == bw_out)) 677 if ((0 == bw_in) && (0 == bw_out))
770 { 678 {
771 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 679 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
772 "ATS tells me to disconnect from peer `%s'\n", 680 "ATS tells me to disconnect from peer `%s'\n",
773 GNUNET_i2s (&address->peer)); 681 GNUNET_i2s (&address->peer));
774 GST_neighbours_force_disconnect (&address->peer); 682 GST_neighbours_force_disconnect (&address->peer);
775 return; 683 return;
776 } 684 }
777 685
778 GST_neighbours_switch_to_address (&address->peer, address, session, ats, 686 GST_neighbours_switch_to_address (&address->peer, address, session, ats,
779 ats_count, bandwidth_in, 687 ats_count, bandwidth_in, bandwidth_out);
780 bandwidth_out);
781} 688}
782 689
783
784/** 690/**
785 * Function called to notify transport users that another 691 * Function called to notify transport users that another
786 * peer connected to us. 692 * peer connected to us.
@@ -792,19 +698,19 @@ ats_request_address_change (void *cls,
792 */ 698 */
793static void 699static void
794neighbours_connect_notification (void *cls, 700neighbours_connect_notification (void *cls,
795 const struct GNUNET_PeerIdentity *peer, 701 const struct GNUNET_PeerIdentity *peer,
796 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 702 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
797 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 703 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
798{ 704{
799 size_t len = sizeof (struct ConnectInfoMessage); 705 size_t len = sizeof(struct ConnectInfoMessage);
800 char buf[len] GNUNET_ALIGN; 706 char buf[len] GNUNET_ALIGN;
801 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; 707 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
802 708
803 connections++; 709 connections++;
804 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 710 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
805 "We are now connected to peer `%s' and %u peers in total\n", 711 "We are now connected to peer `%s' and %u peers in total\n",
806 GNUNET_i2s (peer), connections); 712 GNUNET_i2s (peer), connections);
807 connect_msg->header.size = htons (sizeof (buf)); 713 connect_msg->header.size = htons (sizeof(buf));
808 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 714 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
809 connect_msg->id = *peer; 715 connect_msg->id = *peer;
810 connect_msg->quota_in = bandwidth_in; 716 connect_msg->quota_in = bandwidth_in;
@@ -812,7 +718,6 @@ neighbours_connect_notification (void *cls,
812 GST_clients_broadcast (&connect_msg->header, GNUNET_NO); 718 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
813} 719}
814 720
815
816/** 721/**
817 * Function called to notify transport users that another 722 * Function called to notify transport users that another
818 * peer disconnected from us. 723 * peer disconnected from us.
@@ -822,24 +727,23 @@ neighbours_connect_notification (void *cls,
822 */ 727 */
823static void 728static void
824neighbours_disconnect_notification (void *cls, 729neighbours_disconnect_notification (void *cls,
825 const struct GNUNET_PeerIdentity *peer) 730 const struct GNUNET_PeerIdentity *peer)
826{ 731{
827 struct DisconnectInfoMessage disconnect_msg; 732 struct DisconnectInfoMessage disconnect_msg;
828 733
829 connections--; 734 connections--;
830 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 735 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
831 "Peer `%s' disconnected and we are connected to %u peers\n", 736 "Peer `%s' disconnected and we are connected to %u peers\n",
832 GNUNET_i2s (peer), connections); 737 GNUNET_i2s (peer), connections);
833 738
834 GST_manipulation_peer_disconnect (peer); 739 GST_manipulation_peer_disconnect (peer);
835 disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage)); 740 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
836 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 741 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
837 disconnect_msg.reserved = htonl (0); 742 disconnect_msg.reserved = htonl (0);
838 disconnect_msg.peer = *peer; 743 disconnect_msg.peer = *peer;
839 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO); 744 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
840} 745}
841 746
842
843/** 747/**
844 * Function called to notify transport users that a neighbour peer changed its 748 * Function called to notify transport users that a neighbour peer changed its
845 * active address. 749 * active address.
@@ -854,24 +758,23 @@ neighbours_disconnect_notification (void *cls,
854 */ 758 */
855static void 759static void
856neighbours_changed_notification (void *cls, 760neighbours_changed_notification (void *cls,
857 const struct GNUNET_PeerIdentity *peer, 761 const struct GNUNET_PeerIdentity *peer,
858 const struct GNUNET_HELLO_Address *address, 762 const struct GNUNET_HELLO_Address *address,
859 enum GNUNET_TRANSPORT_PeerState state, 763 enum GNUNET_TRANSPORT_PeerState state,
860 struct GNUNET_TIME_Absolute state_timeout, 764 struct GNUNET_TIME_Absolute state_timeout,
861 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 765 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
862 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 766 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
863{ 767{
864 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 768 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
865 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", 769 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
866 GNUNET_i2s (peer), 770 GNUNET_i2s (peer),
867 (NULL != address) ? GST_plugins_a2s (address) : "<none>", 771 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
868 GNUNET_TRANSPORT_p2s(state), 772 GNUNET_TRANSPORT_p2s (state),
869 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 773 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
870 774
871 GST_clients_broadcast_peer_notification (peer, address, state, state_timeout); 775 GST_clients_broadcast_peer_notification (peer, address, state, state_timeout);
872} 776}
873 777
874
875/** 778/**
876 * Function called when the service shuts down. Unloads our plugins 779 * Function called when the service shuts down. Unloads our plugins
877 * and cancels pending validations. 780 * and cancels pending validations.
@@ -905,13 +808,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
905 } 808 }
906 if (NULL != GST_my_private_key) 809 if (NULL != GST_my_private_key)
907 { 810 {
908 GNUNET_free (GST_my_private_key); 811 GNUNET_free(GST_my_private_key);
909 GST_my_private_key = NULL; 812 GST_my_private_key = NULL;
910 } 813 }
911 GST_server = NULL; 814 GST_server = NULL;
912} 815}
913 816
914
915/** 817/**
916 * Initiate transport service. 818 * Initiate transport service.
917 * 819 *
@@ -921,7 +823,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
921 */ 823 */
922static void 824static void
923run (void *cls, struct GNUNET_SERVER_Handle *server, 825run (void *cls, struct GNUNET_SERVER_Handle *server,
924 const struct GNUNET_CONFIGURATION_Handle *c) 826 const struct GNUNET_CONFIGURATION_Handle *c)
925{ 827{
926 char *keyfile; 828 char *keyfile;
927 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 829 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
@@ -932,42 +834,42 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
932 834
933 /* setup globals */ 835 /* setup globals */
934 GST_cfg = c; 836 GST_cfg = c;
935 if (GNUNET_OK != 837 if (GNUNET_OK
936 GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", 838 != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY",
937 &keyfile)) 839 &keyfile))
938 { 840 {
939 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 841 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
940 _("Transport service is lacking key configuration settings. Exiting.\n")); 842 _("Transport service is lacking key configuration settings. Exiting.\n"));
941 GNUNET_SCHEDULER_shutdown (); 843 GNUNET_SCHEDULER_shutdown ();
942 return; 844 return;
943 } 845 }
944 if (GNUNET_OK != 846 if (GNUNET_OK
945 GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", 847 != GNUNET_CONFIGURATION_get_value_time (c, "transport",
946 &hello_expiration)) 848 "HELLO_EXPIRATION", &hello_expiration))
947 { 849 {
948 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; 850 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
949 } 851 }
950 GST_server = server; 852 GST_server = server;
951 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); 853 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
952 GNUNET_free (keyfile); 854 GNUNET_free(keyfile);
953 GNUNET_assert (NULL != pk); 855 GNUNET_assert(NULL != pk);
954 GST_my_private_key = pk; 856 GST_my_private_key = pk;
955 857
956 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); 858 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
957 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); 859 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
958 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, 860 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
959 &GST_my_identity.public_key); 861 &GST_my_identity.public_key);
960 GNUNET_assert (NULL != GST_my_private_key); 862 GNUNET_assert(NULL != GST_my_private_key);
961 863
962 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 864 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "My identity is `%4s'\n",
963 "My identity is `%4s'\n", GNUNET_i2s (&GST_my_identity)); 865 GNUNET_i2s (&GST_my_identity));
964 866
965 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 867 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
966 NULL); 868 NULL );
967 if (NULL == GST_peerinfo) 869 if (NULL == GST_peerinfo)
968 { 870 {
969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 871 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
970 _("Could not access PEERINFO service. Exiting.\n")); 872 _("Could not access PEERINFO service. Exiting.\n"));
971 GNUNET_SCHEDULER_shutdown (); 873 GNUNET_SCHEDULER_shutdown ();
972 return; 874 return;
973 } 875 }
@@ -980,51 +882,50 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
980 { 882 {
981 max_fd_rlimit = r_file.rlim_cur; 883 max_fd_rlimit = r_file.rlim_cur;
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
983 "Maximum number of open files was: %u/%u\n", 885 "Maximum number of open files was: %u/%u\n",
984 r_file.rlim_cur, 886 r_file.rlim_cur,
985 r_file.rlim_max); 887 r_file.rlim_max);
986 } 888 }
987 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ 889 max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
988#endif 890#endif
989 GNUNET_CONFIGURATION_get_value_number (GST_cfg, "transport", "MAX_FD", &max_fd_cfg); 891 GNUNET_CONFIGURATION_get_value_number (GST_cfg, "transport", "MAX_FD",
892 &max_fd_cfg);
990 893
991 if (max_fd_cfg > max_fd_rlimit) 894 if (max_fd_cfg > max_fd_rlimit)
992 max_fd = max_fd_cfg; 895 max_fd = max_fd_cfg;
993 else 896 else
994 max_fd = max_fd_rlimit; 897 max_fd = max_fd_rlimit;
995 if (max_fd < DEFAULT_MAX_FDS) 898 if (max_fd < DEFAULT_MAX_FDS)
996 max_fd = DEFAULT_MAX_FDS; 899 max_fd = DEFAULT_MAX_FDS;
997 900
998 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 901 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
999 "Limiting number of sockets to %u: validation %u, neighbors: %u\n", 902 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
1000 max_fd, (max_fd / 3) , (max_fd / 3) * 2); 903 max_fd, (max_fd / 3), (max_fd / 3) * 2);
1001 904
1002 friend_only = GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology","FRIENDS-ONLY"); 905 friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology",
906 "FRIENDS-ONLY");
1003 if (GNUNET_SYSERR == friend_only) 907 if (GNUNET_SYSERR == friend_only)
1004 friend_only = GNUNET_NO; /* According to topology defaults */ 908 friend_only = GNUNET_NO; /* According to topology defaults */
1005 /* start subsystems */ 909 /* start subsystems */
1006 GST_hello_start (friend_only, &process_hello_update, NULL); 910 GST_hello_start (friend_only, &process_hello_update, NULL );
1007 GNUNET_assert (NULL != GST_hello_get()); 911 GNUNET_assert(NULL != GST_hello_get());
1008 GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity); 912 GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity);
1009 GST_ats = 913 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change,
1010 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); 914 NULL );
1011 GST_manipulation_init (GST_cfg); 915 GST_manipulation_init (GST_cfg);
1012 GST_plugins_load (&GST_manipulation_recv, 916 GST_plugins_load (&GST_manipulation_recv,
1013 &plugin_env_address_change_notification, 917 &plugin_env_address_change_notification,
1014 &plugin_env_session_start, 918 &plugin_env_session_start,
1015 &plugin_env_session_end, 919 &plugin_env_session_end,
1016 &plugin_env_address_to_type, 920 &plugin_env_address_to_type,
1017 &plugin_env_update_metrics); 921 &plugin_env_update_metrics);
1018 GST_neighbours_start (NULL, 922 GST_neighbours_start (NULL, &neighbours_connect_notification,
1019 &neighbours_connect_notification, 923 &neighbours_disconnect_notification, &neighbours_changed_notification,
1020 &neighbours_disconnect_notification, 924 (max_fd / 3) * 2);
1021 &neighbours_changed_notification,
1022 (max_fd / 3) * 2);
1023 GST_clients_start (GST_server); 925 GST_clients_start (GST_server);
1024 GST_validation_start ((max_fd / 3)); 926 GST_validation_start ((max_fd / 3));
1025} 927}
1026 928
1027
1028/** 929/**
1029 * The main function for the transport service. 930 * The main function for the transport service.
1030 * 931 *
@@ -1033,11 +934,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1033 * @return 0 ok, 1 on error 934 * @return 0 ok, 1 on error
1034 */ 935 */
1035int 936int
1036main (int argc, char *const *argv) 937main (int argc, char * const *argv)
1037{ 938{
1038 return (GNUNET_OK == 939 return
1039 GNUNET_SERVICE_run (argc, argv, "transport", 940 (GNUNET_OK
1040 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 941 == GNUNET_SERVICE_run (argc, argv, "transport",
942 GNUNET_SERVICE_OPTION_NONE, &run, NULL )) ? 0 : 1;
1041} 943}
1042 944
1043/* end of file gnunet-service-transport.c */ 945/* end of file gnunet-service-transport.c */