diff options
author | marshall <stmr@umich.edu> | 2023-07-25 10:01:47 -0400 |
---|---|---|
committer | marshall <stmr@umich.edu> | 2023-07-25 10:01:47 -0400 |
commit | effd970f95eb50bebbe4fed4b2343e192a1487f9 (patch) | |
tree | 17d6f950a23c11d243e89390f279b6a89d27042c | |
parent | b97fab0cbafd25b81953e041ec0fa2ba1145bc32 (diff) | |
download | gnunet-effd970f95eb50bebbe4fed4b2343e192a1487f9.tar.gz gnunet-effd970f95eb50bebbe4fed4b2343e192a1487f9.zip |
transport (quic): send our peerid
-rw-r--r-- | src/transport/gnunet-communicator-quic.c | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/src/transport/gnunet-communicator-quic.c b/src/transport/gnunet-communicator-quic.c index fd36f2fe4..566ad4287 100644 --- a/src/transport/gnunet-communicator-quic.c +++ b/src/transport/gnunet-communicator-quic.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #define TOKEN_LEN sizeof(uint8_t) * MAX_TOKEN_LEN | 28 | #define TOKEN_LEN sizeof(uint8_t) * MAX_TOKEN_LEN |
29 | /* Generic, bidirectional, client-initiated quic stream id */ | 29 | /* Generic, bidirectional, client-initiated quic stream id */ |
30 | #define STREAMID_BI 4 | 30 | #define STREAMID_BI 4 |
31 | #define PEERID_LEN sizeof(struct GNUNET_PeerIdentity) | ||
31 | /** | 32 | /** |
32 | * How long do we believe our addresses to remain up (before | 33 | * How long do we believe our addresses to remain up (before |
33 | * the other peer should revalidate). | 34 | * the other peer should revalidate). |
@@ -377,7 +378,7 @@ flush_egress (struct quic_conn *conn) | |||
377 | 378 | ||
378 | if (0 > written) | 379 | if (0 > written) |
379 | { | 380 | { |
380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "quiche failed to create packet\n"); | 381 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "quiche failed to create packet\n"); |
381 | return; | 382 | return; |
382 | } | 383 | } |
383 | 384 | ||
@@ -386,7 +387,7 @@ flush_egress (struct quic_conn *conn) | |||
386 | send_info.to_len); | 387 | send_info.to_len); |
387 | if (sent != written) | 388 | if (sent != written) |
388 | { | 389 | { |
389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
390 | "quiche failed to send data to peer\n"); | 391 | "quiche failed to send data to peer\n"); |
391 | return; | 392 | return; |
392 | } | 393 | } |
@@ -919,14 +920,15 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const | |||
919 | struct sockaddr *in; | 920 | struct sockaddr *in; |
920 | socklen_t in_len; | 921 | socklen_t in_len; |
921 | uint8_t scid[LOCAL_CONN_ID_LEN]; | 922 | uint8_t scid[LOCAL_CONN_ID_LEN]; |
922 | size_t send_len; | 923 | |
924 | ssize_t send_len; | ||
925 | char my_pid[PEERID_LEN]; | ||
923 | 926 | ||
924 | struct quic_conn *q_conn; | 927 | struct quic_conn *q_conn; |
925 | char *bindto; | 928 | char *bindto; |
926 | socklen_t local_in_len; | 929 | socklen_t local_in_len; |
927 | struct sockaddr *local_addr; | 930 | struct sockaddr *local_addr; |
928 | 931 | ||
929 | |||
930 | if (GNUNET_OK != | 932 | if (GNUNET_OK != |
931 | GNUNET_CONFIGURATION_get_value_string (cfg, | 933 | GNUNET_CONFIGURATION_get_value_string (cfg, |
932 | COMMUNICATOR_CONFIG_SECTION, | 934 | COMMUNICATOR_CONFIG_SECTION, |
@@ -990,18 +992,42 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer_id, const | |||
990 | local_addr, | 992 | local_addr, |
991 | local_in_len, peer->address, peer->address_len, | 993 | local_in_len, peer->address, peer->address_len, |
992 | config); | 994 | config); |
995 | if (GNUNET_NO == quiche_conn_is_established (q_conn->conn)) | ||
996 | { | ||
997 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
998 | "Failed to form connection to peer. mq not created\n"); | ||
999 | return GNUNET_NO; | ||
1000 | } | ||
1001 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1002 | "Handshake established with peer, sending our peer id\n"); | ||
993 | peer->conn = q_conn; | 1003 | peer->conn = q_conn; |
994 | /** | 1004 | /** |
995 | * Send our pid | 1005 | * Send our pid |
996 | */ | 1006 | */ |
997 | // quiche_conn_send (peer->conn->conn, ); | 1007 | GNUNET_memcpy (my_pid, &my_identity, PEERID_LEN); |
1008 | send_len = quiche_conn_stream_send (peer->conn->conn, STREAMID_BI, my_pid, | ||
1009 | PEERID_LEN, | ||
1010 | false); | ||
1011 | if (0 > send_len) | ||
1012 | { | ||
1013 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1014 | "Failed to write peer identity packet\n"); | ||
1015 | return GNUNET_NO; | ||
1016 | } | ||
1017 | flush_egress (peer->conn); | ||
1018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer identity sent to peer\n"); | ||
998 | /** | 1019 | /** |
999 | * Insert connection into hashmap | 1020 | * Insert peer into hashmap |
1000 | */ | 1021 | */ |
1001 | // struct GNUNET_HashCode key; | 1022 | struct GNUNET_HashCode key; |
1002 | // GNUNET_CRYPTO_hash (q_conn->cid, LOCAL_CONN_ID_LEN, &key); | 1023 | GNUNET_CRYPTO_hash (peer->address, peer->address_len, &key); |
1003 | // GNUNET_CONTAINER_multihashmap_put (conn_map, &key, q_conn, | 1024 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (addr_map, &key, peer, |
1004 | // GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1025 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
1026 | { | ||
1027 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1028 | "tried to add duplicate address into address map\n"); | ||
1029 | } | ||
1030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new peer to the addr map\n"); | ||
1005 | setup_peer_mq (peer); | 1031 | setup_peer_mq (peer); |
1006 | if (NULL == timeout_task) | 1032 | if (NULL == timeout_task) |
1007 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); | 1033 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); |
@@ -1123,7 +1149,7 @@ sock_read (void *cls) | |||
1123 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); | 1149 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); |
1124 | return; | 1150 | return; |
1125 | } | 1151 | } |
1126 | GNUNET_CRYPTO_hash ((struct sockaddr *) &sa, sizeof(struct sockaddr), | 1152 | GNUNET_CRYPTO_hash ((struct sockaddr *) &sa, salen, |
1127 | &addr_key); | 1153 | &addr_key); |
1128 | peer = GNUNET_CONTAINER_multihashmap_get (addr_map, &addr_key); | 1154 | peer = GNUNET_CONTAINER_multihashmap_get (addr_map, &addr_key); |
1129 | 1155 | ||
@@ -1147,7 +1173,7 @@ sock_read (void *cls) | |||
1147 | "tried to add duplicate address into address map\n"); | 1173 | "tried to add duplicate address into address map\n"); |
1148 | return; | 1174 | return; |
1149 | } | 1175 | } |
1150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "adding new peer to address map\n"); | 1176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "added new peer to address map\n"); |
1151 | } | 1177 | } |
1152 | 1178 | ||
1153 | /** | 1179 | /** |