2
2
#include " client.h"
3
3
#include " log.h"
4
4
5
- namespace quic {
6
-
7
- // Cranks a value to 11, i.e. set it to its maximum
8
- template <typename T>
9
- void crank_to_eleven (T& val) { val = std::numeric_limits<T>::max (); }
5
+ #include < oxenmq/variant.h>
10
6
11
- static std::array<uint8_t , 32 > null_secret{};
12
- static std::array<uint8_t , 16 > null_iv{};
13
- static std::array<uint8_t , 4096 > null_data{};
7
+ namespace quic {
14
8
15
9
Client::Client (Address remote, uv_loop_t * loop_, std::optional<Address> local_)
16
10
: Endpoint{std::move (local_), loop_} {
@@ -30,38 +24,21 @@ Client::Client(Address remote, uv_loop_t* loop_, std::optional<Address> local_)
30
24
// - delay_stream_timer
31
25
32
26
33
- auto local_cid = ConnectionID::random (rng);
34
- auto [it, ins] = conns.emplace (std::piecewise_construct,
35
- std::forward_as_tuple (local_cid),
36
- std::forward_as_tuple (*this , local_cid, path));
37
- assert (ins);
38
- auto & conn = it->second ;
39
-
40
- // FIXME: likely need to move this crap info connection.cpp, or maybe a "null_crypto.cpp"?
41
- ngtcp2_crypto_ctx null_crypto{};
42
- crank_to_eleven (null_crypto.max_encryption );
43
- crank_to_eleven (null_crypto.max_decryption_failure );
27
+ auto connptr = std::make_shared<Connection>(*this , ConnectionID::random (rng), path);
28
+ auto & conn = *connptr;
29
+ conns.emplace (conn.base_cid , connptr);
44
30
45
- Debug (" set crypto ctx" );
31
+ /* Debug("set crypto ctx");
46
32
47
- ngtcp2_crypto_aead_ctx null_aead_ctx{};
48
- ngtcp2_crypto_aead retry_aead{0 , 16 }; // FIXME: 16 overhead is for AES-128-GCM AEAD, but do we need it?
49
- ngtcp2_crypto_cipher_ctx null_cipher_ctx{};
50
-
51
- ngtcp2_conn_set_initial_crypto_ctx (conn, &null_crypto);
52
- ngtcp2_conn_install_initial_key (conn, &null_aead_ctx, null_iv.data (), &null_cipher_ctx, &null_aead_ctx, null_iv.data (), &null_cipher_ctx, null_iv.size ());
53
- ngtcp2_conn_set_retry_aead (conn, &retry_aead, &null_aead_ctx);
54
- ngtcp2_conn_set_crypto_ctx (conn, &null_crypto);
55
- ngtcp2_conn_install_rx_handshake_key (conn, &null_aead_ctx, null_iv.data (), null_iv.size (), &null_cipher_ctx);
56
- ngtcp2_conn_install_tx_handshake_key (conn, &null_aead_ctx, null_iv.data (), null_iv.size (), &null_cipher_ctx);
57
- ngtcp2_conn_install_rx_key (conn, null_secret.data (), null_secret.size (), &null_aead_ctx, null_iv.data (), null_iv.size (), &null_cipher_ctx);
58
- ngtcp2_conn_install_tx_key (conn, null_secret.data (), null_secret.size (), &null_aead_ctx, null_iv.data (), null_iv.size (), &null_cipher_ctx);
33
+ null_crypto.client_initial(conn);
59
34
60
35
auto x = ngtcp2_conn_get_max_data_left(conn);
61
36
Debug("mdl = ", x);
37
+ */
62
38
63
- conn.flush_streams ();
39
+ conn.io_ready ();
64
40
41
+ /*
65
42
Debug("Opening bidi stream");
66
43
int64_t stream_id;
67
44
if (auto rv = ngtcp2_conn_open_bidi_stream(conn, &stream_id, nullptr);
@@ -70,24 +47,28 @@ Client::Client(Address remote, uv_loop_t* loop_, std::optional<Address> local_)
70
47
assert(rv == NGTCP2_ERR_STREAM_ID_BLOCKED);
71
48
}
72
49
else { Debug("Opening bidi stream good"); }
50
+ */
73
51
}
74
52
75
53
void Client::handle_packet (const Packet& p) {
76
- version_info vi;
77
- auto rv = ngtcp2_pkt_decode_version_cid (&vi.version , &vi.dcid , &vi.dcid_len , &vi.scid , &vi.scid_len ,
78
- u8data (p.data ), p.data .size (), NGTCP2_MAX_CIDLEN);
79
- if (rv == 1 ) // 1 means Version Negotiation should be sent
80
- return send_version_negotiation (vi, p.path .remote );
81
- else if (rv != 0 ) {
82
- Warn (" QUIC packet header decode failed: " , ngtcp2_strerror (rv));
83
- return ;
84
- }
85
-
86
- if (vi.dcid_len > ConnectionID::max_size ()) {
87
- Warn (" Internal error: destination ID is longer than should be allowed" );
54
+ Debug (" Handling incoming client packet: " , buffer_printer{p.data });
55
+ auto maybe_dcid = handle_packet_init (p);
56
+ if (!maybe_dcid) return ;
57
+ auto & dcid = *maybe_dcid;
58
+
59
+ Debug (" Incoming connection id " , dcid);
60
+ auto [connptr, alias] = get_conn (dcid);
61
+ if (!connptr) {
62
+ Debug (" CID is " , alias ? " expired alias" : " unknown/expired" , " ; dropping" );
88
63
return ;
89
64
}
65
+ auto & conn = *connptr;
66
+ if (alias)
67
+ Debug (" CID is alias for primary CID " , conn.base_cid );
68
+ else
69
+ Debug (" CID is primary CID" );
90
70
71
+ handle_conn_packet (conn, p);
91
72
}
92
73
93
74
}
0 commit comments