Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 995aa87

Browse files
committed
Add echo example with raw QUIC transport
1 parent 7300af7 commit 995aa87

File tree

5 files changed

+199
-0
lines changed

5 files changed

+199
-0
lines changed

example/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CXX ?= "g++"
2+
3+
all: echo_client echo_server
4+
echo_client: QuicEchoClient.cc
5+
$(CXX) -std=c++11 -I../src/wrapper -c -o QuicEchoClient.o QuicEchoClient.cc && \
6+
$(CXX) -o echo_client QuicEchoClient.o -L/home/user/work/quic/qlib -ltestquic
7+
echo_server: QuicEchoServer.cc
8+
$(CXX) -std=c++11 -I../src/wrapper -c -o QuicEchoServer.o QuicEchoServer.cc && \
9+
$(CXX) -o echo_server QuicEchoServer.o -L/home/user/work/quic/qlib -ltestquic
10+
clean:
11+
rm *.o echo_*

example/QuicEchoClient.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <memory>
4+
#include <functional>
5+
#include <chrono>
6+
#include <thread>
7+
8+
#include "quic_raw_lib.h"
9+
10+
using namespace net;
11+
12+
std::string message;
13+
14+
class ClientListener : public RQuicListener {
15+
public:
16+
ClientListener(RQuicClientInterface* client) : client_(client) {}
17+
void onReady() override {
18+
std::cout << "Client Started." << std::endl;
19+
if (client_) {
20+
client_->send(message.c_str(), message.length());
21+
}
22+
}
23+
void onData(uint32_t session_id, uint32_t stream_id,
24+
char* data, uint32_t len) override {
25+
std::cout << "Stream: " << stream_id << " received: "
26+
<< std::string(data, len) << std::endl;
27+
if (client_) {
28+
client_->stop();
29+
}
30+
}
31+
private:
32+
RQuicClientInterface* client_;
33+
};
34+
35+
int main(int argc, char* argv[]) {
36+
if (argc < 4) {
37+
std::cout << "Usage: QuicEchoClient [ServerIP] [ServerPort] [message]" << std::endl;
38+
return 0;
39+
}
40+
int port = atoi(argv[2]);
41+
message = std::string(argv[3]);
42+
43+
std::shared_ptr<RQuicClientInterface> client(RQuicFactory::createQuicClient());
44+
ClientListener listener(client.get());
45+
client->setListener(&listener);
46+
47+
client->start(argv[1], port);
48+
client->waitForClose();
49+
return 0;
50+
}

example/QuicEchoServer.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <memory>
4+
#include <functional>
5+
#include <chrono>
6+
#include <thread>
7+
8+
#include "quic_raw_lib.h"
9+
10+
using namespace net;
11+
12+
int port = 6121;
13+
std::string unused_cert = "leaf_cert.pem";
14+
std::string unused_key = "leaf_cert.pkcs8";
15+
16+
class ServerListener : public RQuicListener {
17+
public:
18+
ServerListener(RQuicServerInterface* server) : server_(server) {}
19+
void onReady() override {
20+
std::cout << "Server Started." << std::endl;
21+
if (server_) {
22+
std::cout << "Listening Port: " << server_->getServerPort() << std::endl;
23+
}
24+
}
25+
void onData(uint32_t session_id, uint32_t stream_id,
26+
char* data, uint32_t len) override {
27+
std::cout << "Session: " << session_id << " stream: " << stream_id
28+
<< " received: " << std::string(data, len) << std::endl;
29+
if (server_) {
30+
server_->send(session_id, stream_id, data, len);
31+
}
32+
}
33+
private:
34+
RQuicServerInterface* server_;
35+
};
36+
37+
int main(int argc, char* argv[]) {
38+
if (argc > 1) {
39+
port = atoi(argv[1]);
40+
}
41+
if (argc > 3) {
42+
unused_cert = std::string(argv[2]);
43+
unused_key = std::string(argv[3]);
44+
}
45+
46+
std::shared_ptr<RQuicServerInterface> server(RQuicFactory::createQuicServer(
47+
unused_cert.c_str(), unused_key.c_str()));
48+
49+
ServerListener listener(server.get());
50+
server->setListener(&listener);
51+
52+
server->listen(port);
53+
server->waitForClose();
54+
return 0;
55+
}

example/leaf_cert.pem

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Certificate:
2+
Data:
3+
Version: 3 (0x2)
4+
Serial Number: 1 (0x1)
5+
Signature Algorithm: sha256WithRSAEncryption
6+
Issuer: CN=QUIC Server Root CA
7+
Validity
8+
Not Before: Apr 10 02:21:26 2019 GMT
9+
Not After : Apr 13 02:21:26 2019 GMT
10+
Subject: C=US, ST=California, L=Mountain View, O=QUIC Server, CN=127.0.0.1
11+
Subject Public Key Info:
12+
Public Key Algorithm: rsaEncryption
13+
Public-Key: (2048 bit)
14+
Modulus:
15+
00:b8:dc:04:43:13:b6:f8:2a:43:e1:25:e2:ae:fd:
16+
65:b8:8d:0a:5b:ae:f2:81:77:f1:b0:5d:b0:b6:35:
17+
c7:f8:f6:7a:41:ee:f4:2c:5b:ff:32:fd:25:e2:6b:
18+
ff:d8:20:32:62:f4:21:2c:05:62:2c:b7:96:d5:31:
19+
0a:01:6e:75:e0:15:c6:24:d9:d1:6d:48:64:4c:e5:
20+
1e:5e:0b:b2:38:5d:0b:6e:4c:b3:52:00:fc:bf:63:
21+
e3:65:fa:ee:56:8d:bf:e6:7b:72:06:08:f6:0a:7d:
22+
69:c6:36:02:cb:ea:61:5d:4d:c6:c9:82:d7:18:e2:
23+
78:d5:70:81:0b:bf:b5:e6:54:b0:83:0a:7d:f2:d6:
24+
ed:0e:9b:03:e9:ec:9a:43:c0:f5:f9:64:92:a2:e5:
25+
ee:5f:8c:b5:8e:aa:c3:a8:0f:84:b5:b0:c2:fc:5d:
26+
e2:93:72:a6:c3:4f:d0:1d:27:57:31:ce:30:7c:85:
27+
76:61:3a:6a:b7:57:9c:99:dd:5d:96:82:40:9e:d7:
28+
e7:bb:9b:79:db:7a:f9:fa:6c:a4:fa:f2:0f:24:61:
29+
1f:e3:6d:2c:61:1a:8b:d1:c1:a0:6e:c8:6c:c0:46:
30+
40:d0:9c:c2:45:f6:38:fd:c0:17:90:de:b7:c6:0d:
31+
7a:14:bc:c4:68:1d:2c:74:7a:b6:54:c8:02:d8:40:
32+
d8:b9
33+
Exponent: 65537 (0x10001)
34+
X509v3 extensions:
35+
X509v3 Basic Constraints: critical
36+
CA:FALSE
37+
X509v3 Subject Key Identifier:
38+
59:9C:02:B1:85:0E:4B:D1:29:50:60:62:8F:8E:DB:A8:65:84:3D:45
39+
X509v3 Authority Key Identifier:
40+
keyid:14:3B:F7:F9:BF:31:FC:99:72:F8:61:B9:F9:DD:F1:F4:67:E2:42:38
41+
42+
X509v3 Extended Key Usage:
43+
TLS Web Server Authentication, TLS Web Client Authentication
44+
X509v3 Subject Alternative Name:
45+
DNS:www.example.org, DNS:mail.example.org, DNS:mail.example.com, IP Address:127.0.0.1
46+
Signature Algorithm: sha256WithRSAEncryption
47+
2c:92:af:5e:38:10:26:61:f3:77:7c:27:2b:6e:7c:ee:4a:f5:
48+
f3:20:96:e0:52:03:20:fe:af:89:47:dc:cf:1d:74:eb:20:19:
49+
93:9d:4d:b5:61:fb:08:9c:1f:ee:3b:b2:af:43:d6:9e:27:41:
50+
19:54:82:c2:d4:09:71:d8:5a:e6:c4:50:bf:fc:00:37:c6:f4:
51+
b3:9f:18:1f:28:ac:3b:5f:69:14:93:f4:8a:61:01:b4:f8:fa:
52+
5e:8c:10:8d:9e:60:ce:80:52:d6:c8:54:a5:44:01:66:0c:89:
53+
ef:9a:34:20:2a:19:30:11:57:b5:94:2b:cb:bd:82:cc:58:21:
54+
c7:dc:ee:1c:31:ba:8f:18:0d:1c:ea:81:85:d9:c0:22:f9:4f:
55+
7f:a1:00:e1:f2:6c:9f:fb:6b:3b:f8:e8:4b:b6:59:d0:04:eb:
56+
15:db:d2:7c:8a:15:44:62:12:cb:50:df:f0:f2:a9:5c:58:e8:
57+
ea:e9:8f:10:34:68:a4:a1:e5:a3:5d:53:57:1a:a2:e6:70:4e:
58+
37:6f:1e:61:c5:b7:2c:b6:c6:72:09:a3:21:e5:3b:97:38:ad:
59+
61:4a:2b:4c:c9:9b:d6:6a:76:70:4f:0b:d3:30:73:4b:af:a0:
60+
47:a9:8d:27:25:8a:e5:0d:46:0a:56:0e:2b:a1:74:37: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ID
78+
IP6viUfczx106yAZk51NtWH7CJwf7juyr0PWnidBGVSCwtQJcdha5sRQv/wAN8b0
79+
s58YHyisO19pFJP0imEBtPj6XowQjZ5gzoBS1shUpUQBZgyJ75o0ICoZMBFXtZQr
80+
y72CzFghx9zuHDG6jxgNHOqBhdnAIvlPf6EA4fJsn/trO/joS7ZZ0ATrFdvSfIoV
81+
RGISy1Df8PKpXFjo6umPEDRopKHlo11TVxqi5nBON28eYcW3LLbGcgmjIeU7lzit
82+
YUorTMmb1mp2cE8L0zBzS6+gR6mNJyWK5Q1GClYOK6F0N40k0eYJ+g==
83+
-----END CERTIFICATE-----

example/leaf_cert.pkcs8

1.19 KB
Binary file not shown.

0 commit comments

Comments
 (0)