diff options
author | marshall <stmr@umich.edu> | 2023-06-16 15:36:30 -0400 |
---|---|---|
committer | marshall <stmr@umich.edu> | 2023-07-18 11:12:16 -0400 |
commit | 45d61aeb6ef93edfebfd634bd396ac49a99a235b (patch) | |
tree | e1b7546565a1d372d544f78fd17fbe7f79d27676 | |
parent | 83d3916a4c8b193e868ab02fafe05923ecc7ba3e (diff) | |
download | gnunet-45d61aeb6ef93edfebfd634bd396ac49a99a235b.tar.gz gnunet-45d61aeb6ef93edfebfd634bd396ac49a99a235b.zip |
transport (quic): mint_token for generating tokens
-rw-r--r-- | src/transport/gnunet-communicator-quic.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/transport/gnunet-communicator-quic.c b/src/transport/gnunet-communicator-quic.c index 201f84238..ff5d36b24 100644 --- a/src/transport/gnunet-communicator-quic.c +++ b/src/transport/gnunet-communicator-quic.c | |||
@@ -109,9 +109,10 @@ gen_cid(uint8_t *cid, size_t cid_len) | |||
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Given a quiche connection and buffer, recv data from streams and store into buffer | 111 | * Given a quiche connection and buffer, recv data from streams and store into buffer |
112 | * ASSUMES: connection is established to peer | ||
112 | */ | 113 | */ |
113 | static void | 114 | static void |
114 | recv_from_streams(quiche_conn *conn, char buf[]) | 115 | recv_from_streams(quiche_conn *conn, char stream_buf[]) |
115 | { | 116 | { |
116 | uint64_t s = 0; | 117 | uint64_t s = 0; |
117 | quiche_stream_iter *readable = quiche_conn_readable(conn); | 118 | quiche_stream_iter *readable = quiche_conn_readable(conn); |
@@ -119,24 +120,36 @@ recv_from_streams(quiche_conn *conn, char buf[]) | |||
119 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "stream %" PRIu64 " is readable\n", s); | 120 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "stream %" PRIu64 " is readable\n", s); |
120 | bool fin = false; | 121 | bool fin = false; |
121 | ssize_t recv_len = quiche_conn_stream_recv(conn, s, | 122 | ssize_t recv_len = quiche_conn_stream_recv(conn, s, |
122 | (uint8_t *) buf, sizeof(buf), | 123 | stream_buf, sizeof(stream_buf), |
123 | &fin); | 124 | &fin); |
124 | if (recv_len < 0) { | 125 | if (recv_len < 0) { |
125 | break; | 126 | break; |
126 | } | 127 | } |
127 | /** | 128 | /** |
128 | * Received and processed plaintext from peer: send to core/transport service | 129 | * Received and processed plaintext from peer: send to core/transport service |
129 | */ | 130 | */ |
130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "msg received: %s\n", buf); | 131 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "msg received: %s\n", stream_buf); |
131 | if (fin) { | 132 | if (fin) { |
132 | static const char *resp = "byez\n"; | 133 | static const char *resp = "byez\n"; |
133 | quiche_conn_stream_send(conn, s, (uint8_t *) resp, | 134 | quiche_conn_stream_send(conn, s, resp, |
134 | 5, true); | 135 | 5, true); |
135 | } | 136 | } |
136 | } | 137 | } |
137 | quiche_stream_iter_free(readable); | 138 | quiche_stream_iter_free(readable); |
138 | } | 139 | } |
139 | 140 | ||
141 | static void | ||
142 | mint_token (const uint8_t *dcid, size_t dcid_len, | ||
143 | struct sockaddr_storage *addr, socklen_t addr_len, | ||
144 | uint8_t *token, size_t *token_len) | ||
145 | { | ||
146 | GNUNET_memcpy(token, "quiche", sizeof("quiche") - 1); | ||
147 | GNUNET_memcpy(token + sizeof("quiche") - 1, addr, addr_len); | ||
148 | GNUNET_memcpy(token + sizeof("quiche") - 1 + addr_len, dcid, dcid_len); | ||
149 | |||
150 | *token_len = sizeof("quiche") - 1 + addr_len + dcid_len; | ||
151 | } | ||
152 | |||
140 | /** | 153 | /** |
141 | * Shutdown the UNIX communicator. | 154 | * Shutdown the UNIX communicator. |
142 | * | 155 | * |
@@ -374,9 +387,9 @@ sock_read (void *cls) | |||
374 | /* look for connection in hashtable */ | 387 | /* look for connection in hashtable */ |
375 | /* each connection to the peer should have a unique incoming DCID */ | 388 | /* each connection to the peer should have a unique incoming DCID */ |
376 | /* check against a conn SCID */ | 389 | /* check against a conn SCID */ |
377 | struct GNUNET_HashCode *conn_key; | 390 | struct GNUNET_HashCode conn_key; |
378 | GNUNET_CRYPTO_hash(dcid, sizeof(dcid), conn_key); | 391 | GNUNET_CRYPTO_hash(dcid, sizeof(dcid), &conn_key); |
379 | conn = GNUNET_CONTAINER_multihashmap_get(conn_map, conn_key); | 392 | conn = GNUNET_CONTAINER_multihashmap_get(conn_map, &conn_key); |
380 | 393 | ||
381 | /** | 394 | /** |
382 | * New QUIC connection with peer | 395 | * New QUIC connection with peer |
@@ -411,18 +424,19 @@ sock_read (void *cls) | |||
411 | if (0 == token_len) | 424 | if (0 == token_len) |
412 | { | 425 | { |
413 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "quic stateless retry\n"); | 426 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "quic stateless retry\n"); |
414 | // mint_token(dcid, dcid_len, &sa, salen, | 427 | mint_token(dcid, dcid_len, &sa, salen, |
415 | // token, &token_len); | 428 | token, &token_len); |
416 | 429 | ||
417 | // uint8_t new_cid[LOCAL_CONN_ID_LEN]; | 430 | uint8_t new_cid[LOCAL_CONN_ID_LEN]; |
418 | // gen_cid(new_cid, LOCAL_CONN_ID_LEN); | 431 | gen_cid(new_cid, LOCAL_CONN_ID_LEN); |
419 | 432 | ||
420 | // ssize_t written = quiche_retry(scid, scid_len, | 433 | ssize_t written = quiche_retry(scid, scid_len, |
421 | // dcid, dcid_len, | 434 | dcid, dcid_len, |
422 | // new_cid, LOCAL_CONN_ID_LEN, | 435 | new_cid, LOCAL_CONN_ID_LEN, |
423 | // token, token_len, | 436 | token, token_len, |
424 | // version, out, sizeof(out)); | 437 | version, out, sizeof(out)); |
425 | } | 438 | } |
439 | |||
426 | } // null connection | 440 | } // null connection |
427 | char *bindto; | 441 | char *bindto; |
428 | socklen_t in_len; | 442 | socklen_t in_len; |
@@ -465,8 +479,15 @@ sock_read (void *cls) | |||
465 | if (quiche_conn_is_established(conn)) | 479 | if (quiche_conn_is_established(conn)) |
466 | { | 480 | { |
467 | // Check for data on all available streams | 481 | // Check for data on all available streams |
468 | recv_from_streams(conn, buf); | 482 | char stream_buf[UINT16_MAX]; |
483 | recv_from_streams(conn, stream_buf); | ||
469 | } | 484 | } |
485 | |||
486 | /** | ||
487 | * Connection cleanup, check for closed connections, delete entries, print stats | ||
488 | */ | ||
489 | |||
490 | |||
470 | // if (rcvd > sizeof(struct UDPRekey)) | 491 | // if (rcvd > sizeof(struct UDPRekey)) |
471 | // { | 492 | // { |
472 | // const struct UDPRekey *rekey; | 493 | // const struct UDPRekey *rekey; |