diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-06-28 11:07:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-06-28 11:07:52 +0000 |
commit | 34c384edf42db39955b54a640dc37e7067217229 (patch) | |
tree | 8f9bd2ced347738489f42de665bd55dbb998808d /src/transport/plugin_transport_tcp.c | |
parent | 618779d80c15219b8d9504067f286b5ac1b9b194 (diff) | |
download | gnunet-34c384edf42db39955b54a640dc37e7067217229.tar.gz gnunet-34c384edf42db39955b54a640dc37e7067217229.zip |
fixes to plugin API for DV
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 08bb00ff6..edf403ac6 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1366,29 +1366,29 @@ tcp_plugin_address_pretty_printer (void *cls, | |||
1366 | /** | 1366 | /** |
1367 | * Check if the given port is plausible (must be either | 1367 | * Check if the given port is plausible (must be either |
1368 | * our listen port or our advertised port). If it is | 1368 | * our listen port or our advertised port). If it is |
1369 | * neither, we return one of these two ports at random. | 1369 | * neither, we return GNUNET_SYSERR. |
1370 | * | 1370 | * |
1371 | * @param plugin global variables | 1371 | * @param plugin global variables |
1372 | * @param in_port port number to check | 1372 | * @param in_port port number to check |
1373 | * @return either in_port or a more plausible port | 1373 | * @return GNUNET_OK if port is either open_port or adv_port |
1374 | */ | 1374 | */ |
1375 | static uint16_t | 1375 | static int |
1376 | check_port (struct Plugin *plugin, uint16_t in_port) | 1376 | check_port (struct Plugin *plugin, uint16_t in_port) |
1377 | { | 1377 | { |
1378 | if ((in_port == plugin->adv_port) || (in_port == plugin->open_port)) | 1378 | if ((in_port == plugin->adv_port) || (in_port == plugin->open_port)) |
1379 | return in_port; | 1379 | return GNUNET_OK; |
1380 | return (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1380 | return GNUNET_SYSERR; |
1381 | 2) == 0) | ||
1382 | ? plugin->open_port : plugin->adv_port; | ||
1383 | } | 1381 | } |
1384 | 1382 | ||
1385 | 1383 | ||
1386 | /** | 1384 | /** |
1387 | * Another peer has suggested an address for this peer and transport | 1385 | * Function that will be called to check if a binary address for this |
1388 | * plugin. Check that this could be a valid address. This function | 1386 | * plugin is well-formed and corresponds to an address for THIS peer |
1389 | * is not expected to 'validate' the address in the sense of trying to | 1387 | * (as per our configuration). Naturally, if absolutely necessary, |
1390 | * connect to it but simply to see if the binary format is technically | 1388 | * plugins can be a bit conservative in their answer, but in general |
1391 | * legal for establishing a connection. | 1389 | * plugins should make sure that the address does not redirect |
1390 | * traffic to a 3rd party that might try to man-in-the-middle our | ||
1391 | * traffic. | ||
1392 | * | 1392 | * |
1393 | * @param cls closure, our 'struct Plugin*' | 1393 | * @param cls closure, our 'struct Plugin*' |
1394 | * @param addr pointer to the address | 1394 | * @param addr pointer to the address |
@@ -1397,7 +1397,9 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
1397 | * and transport, GNUNET_SYSERR if not | 1397 | * and transport, GNUNET_SYSERR if not |
1398 | */ | 1398 | */ |
1399 | static int | 1399 | static int |
1400 | tcp_plugin_check_address (void *cls, void *addr, size_t addrlen) | 1400 | tcp_plugin_check_address (void *cls, |
1401 | const void *addr, | ||
1402 | size_t addrlen) | ||
1401 | { | 1403 | { |
1402 | struct Plugin *plugin = cls; | 1404 | struct Plugin *plugin = cls; |
1403 | struct IPv4TcpAddress *v4; | 1405 | struct IPv4TcpAddress *v4; |
@@ -1412,7 +1414,10 @@ tcp_plugin_check_address (void *cls, void *addr, size_t addrlen) | |||
1412 | if (addrlen == sizeof (struct IPv4TcpAddress)) | 1414 | if (addrlen == sizeof (struct IPv4TcpAddress)) |
1413 | { | 1415 | { |
1414 | v4 = (struct IPv4TcpAddress *) addr; | 1416 | v4 = (struct IPv4TcpAddress *) addr; |
1415 | v4->t_port = htons (check_port (plugin, ntohs (v4->t_port))); | 1417 | if (GNUNET_OK != |
1418 | check_port (plugin, ntohs (v4->t_port))) | ||
1419 | return GNUNET_SYSERR; | ||
1420 | /* FIXME: check IP! */ | ||
1416 | } | 1421 | } |
1417 | else | 1422 | else |
1418 | { | 1423 | { |
@@ -1422,7 +1427,10 @@ tcp_plugin_check_address (void *cls, void *addr, size_t addrlen) | |||
1422 | GNUNET_break_op (0); | 1427 | GNUNET_break_op (0); |
1423 | return GNUNET_SYSERR; | 1428 | return GNUNET_SYSERR; |
1424 | } | 1429 | } |
1425 | v6->t6_port = htons (check_port (plugin, ntohs (v6->t6_port))); | 1430 | if (GNUNET_OK != |
1431 | check_port (plugin, ntohs (v6->t6_port))) | ||
1432 | return GNUNET_SYSERR; | ||
1433 | /* FIXME: check IP! */ | ||
1426 | } | 1434 | } |
1427 | return GNUNET_OK; | 1435 | return GNUNET_OK; |
1428 | } | 1436 | } |