diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-18 21:55:13 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-19 12:41:01 +0100 |
commit | 5e041b56a98c49a944804420ad53e18707c9f823 (patch) | |
tree | de2bf458bb44c86bff53f0a5a73d7f1d4fdef0c2 | |
parent | 0bd15d392c8c1c4dab56c794ec88fdbd7245cc51 (diff) | |
download | gnunet-5e041b56a98c49a944804420ad53e18707c9f823.tar.gz gnunet-5e041b56a98c49a944804420ad53e18707c9f823.zip |
-got basics to work with dhtu and udp+ip underlay
-rw-r--r-- | src/dht/gnunet-service-dht_neighbours.c | 36 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_ip.c | 12 | ||||
-rw-r--r-- | src/hello/hello-uri.c | 20 |
3 files changed, 49 insertions, 19 deletions
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index c4d6b7428..e4d9ec8ea 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -2428,12 +2428,19 @@ static enum GNUNET_GenericReturnValue | |||
2428 | check_dht_p2p_hello (void *cls, | 2428 | check_dht_p2p_hello (void *cls, |
2429 | const struct GNUNET_MessageHeader *hello) | 2429 | const struct GNUNET_MessageHeader *hello) |
2430 | { | 2430 | { |
2431 | struct GNUNET_HELLO_Builder *b; | 2431 | struct Target *t = cls; |
2432 | struct PeerInfo *peer = t->pi; | ||
2432 | enum GNUNET_GenericReturnValue ret; | 2433 | enum GNUNET_GenericReturnValue ret; |
2433 | 2434 | size_t hellob_size; | |
2434 | b = GNUNET_HELLO_builder_from_msg (hello); | 2435 | void *hellob; |
2435 | ret = (NULL == b) ? GNUNET_SYSERR : GNUNET_OK; | 2436 | struct GNUNET_TIME_Absolute expiration; |
2436 | GNUNET_HELLO_builder_free (b); | 2437 | |
2438 | ret = GNUNET_HELLO_dht_msg_to_block (hello, | ||
2439 | &peer->id, | ||
2440 | &hellob, | ||
2441 | &hellob_size, | ||
2442 | &expiration); | ||
2443 | GNUNET_free (hellob); | ||
2437 | return ret; | 2444 | return ret; |
2438 | } | 2445 | } |
2439 | 2446 | ||
@@ -2469,30 +2476,37 @@ GDS_u_receive (void *cls, | |||
2469 | const void *message, | 2476 | const void *message, |
2470 | size_t message_size) | 2477 | size_t message_size) |
2471 | { | 2478 | { |
2472 | struct PeerInfo *pi = *tctx; | 2479 | struct Target *t = *tctx; |
2473 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 2480 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
2474 | GNUNET_MQ_hd_var_size (dht_p2p_get, | 2481 | GNUNET_MQ_hd_var_size (dht_p2p_get, |
2475 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, | 2482 | GNUNET_MESSAGE_TYPE_DHT_P2P_GET, |
2476 | struct PeerGetMessage, | 2483 | struct PeerGetMessage, |
2477 | pi), | 2484 | t), |
2478 | GNUNET_MQ_hd_var_size (dht_p2p_put, | 2485 | GNUNET_MQ_hd_var_size (dht_p2p_put, |
2479 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, | 2486 | GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, |
2480 | struct PeerPutMessage, | 2487 | struct PeerPutMessage, |
2481 | pi), | 2488 | t), |
2482 | GNUNET_MQ_hd_var_size (dht_p2p_result, | 2489 | GNUNET_MQ_hd_var_size (dht_p2p_result, |
2483 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, | 2490 | GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, |
2484 | struct PeerResultMessage, | 2491 | struct PeerResultMessage, |
2485 | pi), | 2492 | t), |
2486 | GNUNET_MQ_hd_var_size (dht_p2p_hello, | 2493 | GNUNET_MQ_hd_var_size (dht_p2p_hello, |
2487 | GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, | 2494 | GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, |
2488 | struct GNUNET_MessageHeader, | 2495 | struct GNUNET_MessageHeader, |
2489 | pi), | 2496 | t), |
2490 | GNUNET_MQ_handler_end () | 2497 | GNUNET_MQ_handler_end () |
2491 | }; | 2498 | }; |
2492 | const struct GNUNET_MessageHeader *mh = message; | 2499 | const struct GNUNET_MessageHeader *mh = message; |
2493 | 2500 | ||
2494 | (void) cls; /* the 'struct GDS_Underlay' */ | 2501 | (void) cls; /* the 'struct GDS_Underlay' */ |
2495 | (void) sctx; /* our receiver address */ | 2502 | (void) sctx; /* our receiver address */ |
2503 | if (NULL == t) | ||
2504 | { | ||
2505 | /* Received message claiming to originate from myself? | ||
2506 | Ignore! */ | ||
2507 | GNUNET_break_op (0); | ||
2508 | return; | ||
2509 | } | ||
2496 | if (message_size < sizeof (*mh)) | 2510 | if (message_size < sizeof (*mh)) |
2497 | { | 2511 | { |
2498 | GNUNET_break_op (0); | 2512 | GNUNET_break_op (0); |
@@ -2506,7 +2520,7 @@ GDS_u_receive (void *cls, | |||
2506 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2520 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2507 | "Handling message of type %u from peer %s\n", | 2521 | "Handling message of type %u from peer %s\n", |
2508 | ntohs (mh->type), | 2522 | ntohs (mh->type), |
2509 | GNUNET_i2s (&pi->id)); | 2523 | GNUNET_i2s (&t->pi->id)); |
2510 | if (GNUNET_OK != | 2524 | if (GNUNET_OK != |
2511 | GNUNET_MQ_handle_message (core_handlers, | 2525 | GNUNET_MQ_handle_message (core_handlers, |
2512 | mh)) | 2526 | mh)) |
diff --git a/src/dhtu/plugin_dhtu_ip.c b/src/dhtu/plugin_dhtu_ip.c index 617f722b5..2f6d6161e 100644 --- a/src/dhtu/plugin_dhtu_ip.c +++ b/src/dhtu/plugin_dhtu_ip.c | |||
@@ -809,7 +809,7 @@ read_cb (void *cls) | |||
809 | (cmsg->cmsg_level == IPPROTO_IPV6), | 809 | (cmsg->cmsg_level == IPPROTO_IPV6), |
810 | cmsg->cmsg_type, | 810 | cmsg->cmsg_type, |
811 | (cmsg->cmsg_type == IP_PKTINFO), | 811 | (cmsg->cmsg_type == IP_PKTINFO), |
812 | (cmsg->cmsg_type == IPV6_RECVPKTINFO)); | 812 | (cmsg->cmsg_type == IPV6_PKTINFO)); |
813 | if ( (cmsg->cmsg_level == IPPROTO_IP) && | 813 | if ( (cmsg->cmsg_level == IPPROTO_IP) && |
814 | (cmsg->cmsg_type == IP_PKTINFO) ) | 814 | (cmsg->cmsg_type == IP_PKTINFO) ) |
815 | { | 815 | { |
@@ -824,7 +824,8 @@ read_cb (void *cls) | |||
824 | { | 824 | { |
825 | struct sockaddr_in sa = { | 825 | struct sockaddr_in sa = { |
826 | .sin_family = AF_INET, | 826 | .sin_family = AF_INET, |
827 | .sin_addr = pi.ipi_addr | 827 | .sin_addr = pi.ipi_addr, |
828 | .sin_port = htons (plugin->port16) | ||
828 | }; | 829 | }; |
829 | 830 | ||
830 | src = find_source (plugin, | 831 | src = find_source (plugin, |
@@ -837,7 +838,7 @@ read_cb (void *cls) | |||
837 | GNUNET_break (0); | 838 | GNUNET_break (0); |
838 | } | 839 | } |
839 | if ( (cmsg->cmsg_level == IPPROTO_IPV6) && | 840 | if ( (cmsg->cmsg_level == IPPROTO_IPV6) && |
840 | (cmsg->cmsg_type == IPV6_RECVPKTINFO) ) | 841 | (cmsg->cmsg_type == IPV6_PKTINFO) ) |
841 | { | 842 | { |
842 | if (CMSG_LEN (sizeof (struct in6_pktinfo)) == | 843 | if (CMSG_LEN (sizeof (struct in6_pktinfo)) == |
843 | cmsg->cmsg_len) | 844 | cmsg->cmsg_len) |
@@ -851,6 +852,7 @@ read_cb (void *cls) | |||
851 | struct sockaddr_in6 sa = { | 852 | struct sockaddr_in6 sa = { |
852 | .sin6_family = AF_INET6, | 853 | .sin6_family = AF_INET6, |
853 | .sin6_addr = pi.ipi6_addr, | 854 | .sin6_addr = pi.ipi6_addr, |
855 | .sin6_port = htons (plugin->port16), | ||
854 | .sin6_scope_id = pi.ipi6_ifindex | 856 | .sin6_scope_id = pi.ipi6_ifindex |
855 | }; | 857 | }; |
856 | 858 | ||
@@ -880,8 +882,8 @@ read_cb (void *cls) | |||
880 | return; | 882 | return; |
881 | } | 883 | } |
882 | plugin->env->receive_cb (plugin->env->cls, | 884 | plugin->env->receive_cb (plugin->env->cls, |
883 | dst->app_ctx, | 885 | &dst->app_ctx, |
884 | src->app_ctx, | 886 | &src->app_ctx, |
885 | &buf[sizeof(*pid)], | 887 | &buf[sizeof(*pid)], |
886 | ret - sizeof (*pid)); | 888 | ret - sizeof (*pid)); |
887 | } | 889 | } |
diff --git a/src/hello/hello-uri.c b/src/hello/hello-uri.c index e57d49e86..bacaf697e 100644 --- a/src/hello/hello-uri.c +++ b/src/hello/hello-uri.c | |||
@@ -605,9 +605,13 @@ GNUNET_HELLO_builder_to_dht_hello_msg ( | |||
605 | priv, | 605 | priv, |
606 | buf, | 606 | buf, |
607 | &blen)); | 607 | &blen)); |
608 | msg = GNUNET_malloc (sizeof (*msg) + blen); | 608 | msg = GNUNET_malloc (sizeof (*msg) |
609 | + blen | ||
610 | - sizeof (*block)); | ||
609 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO); | 611 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO); |
610 | msg->header.size = htons (sizeof (*msg) + blen); | 612 | msg->header.size = htons (sizeof (*msg) |
613 | + blen | ||
614 | - sizeof (*block)); | ||
611 | memcpy (&msg[1], | 615 | memcpy (&msg[1], |
612 | &block[1], | 616 | &block[1], |
613 | blen - sizeof (*block)); | 617 | blen - sizeof (*block)); |
@@ -745,6 +749,9 @@ GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder, | |||
745 | "://"))) | 749 | "://"))) |
746 | { | 750 | { |
747 | GNUNET_break_op (0); | 751 | GNUNET_break_op (0); |
752 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
753 | "Invalid address `%s'\n", | ||
754 | address); | ||
748 | return GNUNET_SYSERR; | 755 | return GNUNET_SYSERR; |
749 | } | 756 | } |
750 | if (e == address) | 757 | if (e == address) |
@@ -847,7 +854,7 @@ GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello, | |||
847 | } | 854 | } |
848 | if (len < sizeof (*msg)) | 855 | if (len < sizeof (*msg)) |
849 | { | 856 | { |
850 | GNUNET_break (0); | 857 | GNUNET_break_op (0); |
851 | return GNUNET_SYSERR; | 858 | return GNUNET_SYSERR; |
852 | } | 859 | } |
853 | len -= sizeof (*msg); | 860 | len -= sizeof (*msg); |
@@ -863,6 +870,13 @@ GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello, | |||
863 | len); | 870 | len); |
864 | b = GNUNET_HELLO_builder_from_block (*block, | 871 | b = GNUNET_HELLO_builder_from_block (*block, |
865 | *block_size); | 872 | *block_size); |
873 | if (NULL == b) | ||
874 | { | ||
875 | GNUNET_break_op (0); | ||
876 | GNUNET_free (*block); | ||
877 | *block_size = 0; | ||
878 | return GNUNET_SYSERR; | ||
879 | } | ||
866 | ret = verify_hello (b, | 880 | ret = verify_hello (b, |
867 | *block_expiration, | 881 | *block_expiration, |
868 | &msg->sig); | 882 | &msg->sig); |