14
14
#include " net/third_party/quiche/src/quic/platform/api/quic_system_event_loop.h"
15
15
#include " owt/quic/web_transport_factory.h"
16
16
17
+ class WebTransportTestClientVisitor
18
+ : public owt::quic::WebTransportClientInterface::Visitor {
19
+ void OnConnected () override {
20
+ LOG (INFO) << " WebTransport client connected." ;
21
+ }
22
+ // Called when the connection state changed from connecting to failed.
23
+ void OnConnectionFailed () override {
24
+ LOG (INFO) << " WebTransport client connection failed." ;
25
+ }
26
+ // Called when an incoming stream is received.
27
+ void OnIncomingStream (owt::quic::WebTransportStreamInterface*) override {
28
+ LOG (INFO) << " WebTransport client received an incoming stream." ;
29
+ }
30
+ // Called when datagram is processed.
31
+ void OnDatagramProcessed (owt::quic::MessageStatus) override {
32
+ LOG (INFO) << " WebTransport client processed datagram." ;
33
+ }
34
+
35
+ void OnClosed (uint32_t code, const char * reason) override {
36
+ LOG (INFO) << " WebTransport client closed." ;
37
+ }
38
+ };
39
+
17
40
DEFINE_QUIC_COMMAND_LINE_FLAG (std::string,
18
41
fingerprint,
19
42
" " ,
20
43
" Certificate fingerprint." );
21
44
22
45
int main (int argc, char * argv[]) {
23
- QuicSystemEventLoop event_loop (" quic_client " );
46
+ QuicSystemEventLoop event_loop (" web_transport_test_client " );
24
47
const char * usage = " Usage: owt_web_transport_test_client [options] <url>" ;
25
48
26
49
// All non-flag arguments should be interpreted as URLs to fetch.
@@ -38,13 +61,20 @@ int main(int argc, char* argv[]) {
38
61
parameters.server_certificate_fingerprints_length = 0 ;
39
62
} else {
40
63
parameters.server_certificate_fingerprints_length = 1 ;
41
- auto * fingerprints = new owt::quic::CertificateFingerprint[1 ];
42
- fingerprints[0 ].fingerprint = fingerprint.c_str ();
43
- parameters.server_certificate_fingerprints = &fingerprints;
64
+ owt::quic::CertificateFingerprint** fingerprints =
65
+ new owt::quic::CertificateFingerprint*[1 ];
66
+ fingerprints[0 ] = new owt::quic::CertificateFingerprint ();
67
+ fingerprints[0 ]->fingerprint = fingerprint.c_str ();
68
+ parameters.server_certificate_fingerprints = fingerprints;
44
69
}
45
70
std::unique_ptr<owt::quic::WebTransportFactory> factory_ (
46
71
owt::quic::WebTransportFactory::CreateForTesting ());
47
72
std::unique_ptr<owt::quic::WebTransportClientInterface> client_ (
48
73
factory_->CreateWebTransportClient (urls[0 ].c_str (), parameters));
74
+ WebTransportTestClientVisitor client_visitor;
75
+ client_->SetVisitor (&client_visitor);
49
76
client_->Connect ();
77
+
78
+ base::RunLoop run_loop;
79
+ run_loop.Run ();
50
80
}
0 commit comments