aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport-new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport-new.c')
-rw-r--r--src/transport/gnunet-service-transport-new.c102
1 files changed, 41 insertions, 61 deletions
diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c
index 8ceffd86c..6c2b396dc 100644
--- a/src/transport/gnunet-service-transport-new.c
+++ b/src/transport/gnunet-service-transport-new.c
@@ -85,16 +85,13 @@ struct GNUNET_ATS_Handle *GST_ats;
85 * @param ats_count number of records in ats (unused) 85 * @param ats_count number of records in ats (unused)
86 */ 86 */
87static void 87static void
88transmit_our_hello (void *cls, 88transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target,
89 const struct GNUNET_PeerIdentity *target,
90 const struct GNUNET_TRANSPORT_ATS_Information *ats, 89 const struct GNUNET_TRANSPORT_ATS_Information *ats,
91 uint32_t ats_count) 90 uint32_t ats_count)
92{ 91{
93 const struct GNUNET_MessageHeader *hello = cls; 92 const struct GNUNET_MessageHeader *hello = cls;
94 93
95 GST_neighbours_send (target, 94 GST_neighbours_send (target, (const char *) hello, ntohs (hello->size),
96 (const char *) hello,
97 ntohs (hello->size),
98 GST_HELLO_ADDRESS_EXPIRATION, NULL, NULL); 95 GST_HELLO_ADDRESS_EXPIRATION, NULL, NULL);
99} 96}
100 97
@@ -123,8 +120,8 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
123 * GNUNET_NO if not 120 * GNUNET_NO if not
124 */ 121 */
125static void 122static void
126try_connect_if_allowed (void *cls, 123try_connect_if_allowed (void *cls, const struct GNUNET_PeerIdentity *peer,
127 const struct GNUNET_PeerIdentity *peer, int result) 124 int result)
128{ 125{
129 if (GNUNET_OK != result) 126 if (GNUNET_OK != result)
130 return; /* not allowed */ 127 return; /* not allowed */
@@ -156,8 +153,7 @@ try_connect_if_allowed (void *cls,
156 * (plugins that do not support this, can ignore the return value) 153 * (plugins that do not support this, can ignore the return value)
157 */ 154 */
158static struct GNUNET_TIME_Relative 155static struct GNUNET_TIME_Relative
159plugin_env_receive_callback (void *cls, 156plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
160 const struct GNUNET_PeerIdentity *peer,
161 const struct GNUNET_MessageHeader *message, 157 const struct GNUNET_MessageHeader *message,
162 const struct GNUNET_TRANSPORT_ATS_Information *ats, 158 const struct GNUNET_TRANSPORT_ATS_Information *ats,
163 uint32_t ats_count, struct Session *session, 159 uint32_t ats_count, struct Session *session,
@@ -182,33 +178,29 @@ plugin_env_receive_callback (void *cls,
182 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: 178 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
183#if DEBUG_TRANSPORT 179#if DEBUG_TRANSPORT
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
185 "Processing `%s' from `%s'\n", 181 "Processing `%s' from `%s'\n", "PING",
186 "PING", 182 (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
187 (sender_address != NULL) 183 sender_address,
188 ? GST_plugins_a2s (plugin_name, 184 sender_address_len)
189 sender_address, 185 : "<inbound>");
190 sender_address_len) : "<inbound>");
191#endif 186#endif
192 GST_validation_handle_ping (peer, 187 GST_validation_handle_ping (peer, message, plugin_name, session,
193 message, 188 sender_address, sender_address_len);
194 plugin_name,
195 session, sender_address, sender_address_len);
196 break; 189 break;
197 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 190 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
198#if DEBUG_TRANSPORT 191#if DEBUG_TRANSPORT
199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
200 "Processing `%s' from `%s'\n", 193 "Processing `%s' from `%s'\n", "PONG",
201 "PONG", 194 (sender_address != NULL) ? GST_plugins_a2s (plugin_name,
202 (sender_address != NULL) 195 sender_address,
203 ? GST_plugins_a2s (plugin_name, 196 sender_address_len)
204 sender_address, 197 : "<inbound>");
205 sender_address_len) : "<inbound>");
206#endif 198#endif
207 GST_validation_handle_pong (peer, message); 199 GST_validation_handle_pong (peer, message);
208 break; 200 break;
209 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: 201 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
210 (void) GST_blacklist_test_allowed (peer, 202 (void) GST_blacklist_test_allowed (peer, NULL, &try_connect_if_allowed,
211 NULL, &try_connect_if_allowed, NULL); 203 NULL);
212 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred 204 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred
213 * way to communicate with this peer (other peer switched transport) */ 205 * way to communicate with this peer (other peer switched transport) */
214 break; 206 break;
@@ -223,20 +215,19 @@ plugin_env_receive_callback (void *cls,
223 default: 215 default:
224 /* should be payload */ 216 /* should be payload */
225 do_forward = GNUNET_SYSERR; 217 do_forward = GNUNET_SYSERR;
226 ret = GST_neighbours_calculate_receive_delay (peer, 218 ret =
227 (message == NULL) 219 GST_neighbours_calculate_receive_delay (peer,
228 ? 0 220 (message ==
229 : ntohs (message->size), 221 NULL) ? 0 : ntohs (message->
230 &do_forward); 222 size),
223 &do_forward);
231 if (do_forward == GNUNET_YES) 224 if (do_forward == GNUNET_YES)
232 GST_clients_broadcast (message, GNUNET_YES); 225 GST_clients_broadcast (message, GNUNET_YES);
233 break; 226 break;
234 } 227 }
235 } 228 }
236 GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (), /* valid at least until right now... */ 229 GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (), /* valid at least until right now... */
237 plugin_name, 230 plugin_name, session, sender_address,
238 session,
239 sender_address,
240 sender_address_len, ats, ats_count); 231 sender_address_len, ats, ats_count);
241 232
242 return ret; 233 return ret;
@@ -255,8 +246,7 @@ plugin_env_receive_callback (void *cls,
255 * @param addrlen length of the address 246 * @param addrlen length of the address
256 */ 247 */
257static void 248static void
258plugin_env_address_change_notification (void *cls, 249plugin_env_address_change_notification (void *cls, int add_remove,
259 int add_remove,
260 const void *addr, size_t addrlen) 250 const void *addr, size_t addrlen)
261{ 251{
262 const char *plugin_name = cls; 252 const char *plugin_name = cls;
@@ -279,8 +269,7 @@ plugin_env_address_change_notification (void *cls,
279 * @param session which session is being destoyed 269 * @param session which session is being destoyed
280 */ 270 */
281static void 271static void
282plugin_env_session_end (void *cls, 272plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
283 const struct GNUNET_PeerIdentity *peer,
284 struct Session *session) 273 struct Session *session)
285{ 274{
286 GST_neighbours_session_terminated (peer, session); 275 GST_neighbours_session_terminated (peer, session);
@@ -303,17 +292,12 @@ plugin_env_session_end (void *cls,
303 * @param bandwidth assigned outbound bandwidth for the connection 292 * @param bandwidth assigned outbound bandwidth for the connection
304 */ 293 */
305static void 294static void
306ats_request_address_change (void *cls, 295ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer,
307 const struct GNUNET_PeerIdentity *peer, 296 const char *plugin_name, struct Session *session,
308 const char *plugin_name, 297 const void *plugin_addr, size_t plugin_addr_len,
309 struct Session *session,
310 const void *plugin_addr,
311 size_t plugin_addr_len,
312 struct GNUNET_BANDWIDTH_Value32NBO bandwidth) 298 struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
313{ 299{
314 GST_neighbours_switch_to_address (peer, 300 GST_neighbours_switch_to_address (peer, plugin_name, plugin_addr,
315 plugin_name,
316 plugin_addr,
317 plugin_addr_len, session, NULL, 0); 301 plugin_addr_len, session, NULL, 0);
318 GST_neighbours_set_incoming_quota (peer, bandwidth); 302 GST_neighbours_set_incoming_quota (peer, bandwidth);
319} 303}
@@ -417,8 +401,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
417 * @param c configuration to use 401 * @param c configuration to use
418 */ 402 */
419static void 403static void
420run (void *cls, 404run (void *cls, struct GNUNET_SERVER_Handle *server,
421 struct GNUNET_SERVER_Handle *server,
422 const struct GNUNET_CONFIGURATION_Handle *c) 405 const struct GNUNET_CONFIGURATION_Handle *c)
423{ 406{
424 char *keyfile; 407 char *keyfile;
@@ -426,8 +409,8 @@ run (void *cls,
426 /* setup globals */ 409 /* setup globals */
427 GST_cfg = c; 410 GST_cfg = c;
428 if (GNUNET_OK != 411 if (GNUNET_OK !=
429 GNUNET_CONFIGURATION_get_value_filename (c, 412 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
430 "GNUNETD", "HOSTKEY", &keyfile)) 413 &keyfile))
431 { 414 {
432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
433 _ 416 _
@@ -447,10 +430,10 @@ run (void *cls,
447 GST_stats = GNUNET_STATISTICS_create ("transport", c); 430 GST_stats = GNUNET_STATISTICS_create ("transport", c);
448 GST_peerinfo = GNUNET_PEERINFO_connect (c); 431 GST_peerinfo = GNUNET_PEERINFO_connect (c);
449 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); 432 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
450 GNUNET_CRYPTO_hash (&GST_my_public_key, 433 GNUNET_CRYPTO_hash (&GST_my_public_key, sizeof (GST_my_public_key),
451 sizeof (GST_my_public_key), &GST_my_identity.hashPubKey); 434 &GST_my_identity.hashPubKey);
452 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 435 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
453 &shutdown_task, NULL); 436 NULL);
454 if (GST_peerinfo == NULL) 437 if (GST_peerinfo == NULL)
455 { 438 {
456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -466,8 +449,7 @@ run (void *cls,
466 &plugin_env_address_change_notification, 449 &plugin_env_address_change_notification,
467 &plugin_env_session_end); 450 &plugin_env_session_end);
468 GST_ats = GNUNET_ATS_init (GST_cfg, &ats_request_address_change, NULL); 451 GST_ats = GNUNET_ATS_init (GST_cfg, &ats_request_address_change, NULL);
469 GST_neighbours_start (NULL, 452 GST_neighbours_start (NULL, &neighbours_connect_notification,
470 &neighbours_connect_notification,
471 &neighbours_disconnect_notification); 453 &neighbours_disconnect_notification);
472 GST_clients_start (server); 454 GST_clients_start (server);
473 GST_validation_start (); 455 GST_validation_start ();
@@ -485,9 +467,7 @@ int
485main (int argc, char *const *argv) 467main (int argc, char *const *argv)
486{ 468{
487 return (GNUNET_OK == 469 return (GNUNET_OK ==
488 GNUNET_SERVICE_run (argc, 470 GNUNET_SERVICE_run (argc, argv, "transport",
489 argv,
490 "transport",
491 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; 471 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
492} 472}
493 473