4
4
5
5
namespace quic {
6
6
7
- Client::Client (Address remote, uv_loop_t * loop, std::optional<Address> local)
8
- : Endpoint{std::move (local), loop} {
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 (); }
10
+
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{};
14
+
15
+ Client::Client (Address remote, uv_loop_t * loop_, std::optional<Address> local_)
16
+ : Endpoint{std::move (local_), loop_} {
17
+
9
18
// Our UDP socket is now set up, so now we initiate contact with the remote QUIC
19
+ Path path{local, remote};
10
20
Debug (" Connecting to " , remote);
11
21
12
22
// TODO: need timers for:
@@ -20,28 +30,52 @@ Client::Client(Address remote, uv_loop_t* loop, std::optional<Address> local)
20
30
// - delay_stream_timer
21
31
22
32
23
- conns_iterator it = conns.end ();
24
- try {
25
- auto * s = dynamic_cast <Server*>(this );
26
- assert (s);
27
- auto [insit, ins] = conns.emplace (std::piecewise_construct,
28
- std::forward_as_tuple (local_cid),
29
- std::forward_as_tuple (*s, local_cid, hd, p.path ));
30
- if (!ins)
31
- Warn (" Internal error: duplicate connection id?" );
32
- else
33
- it = insit;
34
- } catch (const std::exception & e) {
35
- Warn (" Failed to create Connection: " , e.what ());
36
- }
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 );
44
+
45
+ Debug (" set crypto ctx" );
37
46
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{};
38
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);
59
+
60
+ auto x = ngtcp2_conn_get_max_data_left (conn);
61
+ Debug (" mdl = " , x);
62
+
63
+ conn.flush_streams ();
64
+
65
+ Debug (" Opening bidi stream" );
66
+ int64_t stream_id;
67
+ if (auto rv = ngtcp2_conn_open_bidi_stream (conn, &stream_id, nullptr );
68
+ rv != 0 ) {
69
+ Debug (" Opening bidi stream failed: " , ngtcp2_strerror (rv));
70
+ assert (rv == NGTCP2_ERR_STREAM_ID_BLOCKED);
71
+ }
72
+ else { Debug (" Opening bidi stream good" ); }
39
73
}
40
74
41
75
void Client::handle_packet (const Packet& p) {
42
76
version_info vi;
43
77
auto rv = ngtcp2_pkt_decode_version_cid (&vi.version , &vi.dcid , &vi.dcid_len , &vi.scid , &vi.scid_len ,
44
- reinterpret_cast < const uint8_t *> (p.data . data () ), p.data .size (), NGTCP2_MAX_CIDLEN);
78
+ u8data (p.data ), p.data .size (), NGTCP2_MAX_CIDLEN);
45
79
if (rv == 1 ) // 1 means Version Negotiation should be sent
46
80
return send_version_negotiation (vi, p.path .remote );
47
81
else if (rv != 0 ) {
@@ -55,3 +89,5 @@ void Client::handle_packet(const Packet& p) {
55
89
}
56
90
57
91
}
92
+
93
+ }
0 commit comments