Wrap more h3, bump uSockets, remove old stuff, add SSL cert
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
/* Tentative example of simple Http3 server */
|
||||
int main() {
|
||||
uWS::H3App({
|
||||
.key_file_name = "../misc/key.pem",
|
||||
.cert_file_name = "../misc/cert.pem",
|
||||
.key_file_name = "misc/key.pem",
|
||||
.cert_file_name = "misc/cert.pem",
|
||||
.passphrase = "1234"
|
||||
}).get("/*", [](auto *res, auto *req) {
|
||||
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
TEMPLATE = app
|
||||
CONFIG += console c++1z
|
||||
CONFIG -= app_bundle
|
||||
CONFIG -= qt
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
../uSockets/src/eventing/epoll.c \
|
||||
../uSockets/src/context.c \
|
||||
../uSockets/src/socket.c \
|
||||
../uSockets/src/eventing/libuv.c \
|
||||
../uSockets/src/ssl.c \
|
||||
../uSockets/src/loop.c
|
||||
|
||||
HEADERS += \
|
||||
../src/HttpRouter.h \
|
||||
../src/HttpParser.h \
|
||||
../src/libwshandshake.hpp \
|
||||
../src/WebSocketProtocol.h \
|
||||
../src/HttpContext.h \
|
||||
../src/HttpContextData.h \
|
||||
../src/HttpResponseData.h \
|
||||
../src/HttpResponse.h \
|
||||
../src/LoopData.h \
|
||||
../src/AsyncSocket.h \
|
||||
../src/AsyncSocketData.h \
|
||||
../src/Loop.h \
|
||||
../src/App.h \
|
||||
../src/Utilities.h \
|
||||
../src/WebSocket.h \
|
||||
../src/WebSocketData.h \
|
||||
../src/WebSocketContext.h \
|
||||
../src/WebSocketContextData.h \
|
||||
../src/WebSocketExtensions.h \
|
||||
../src/PerMessageDeflate.h \
|
||||
../src/TopicTree.h
|
||||
|
||||
INCLUDEPATH += ../uSockets/src ../src
|
||||
QMAKE_CXXFLAGS += -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-parameter -fsanitize=address
|
||||
QMAKE_CFLAGS += -Wno-unused-parameter -Wno-unused-variable
|
||||
LIBS += -lasan -pthread -lssl -lcrypto -lz -lstdc++fs
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 53 KiB |
-19
@@ -1,19 +0,0 @@
|
||||
## Build systems
|
||||
Q:
|
||||
```
|
||||
Hi Alex,
|
||||
I've used your library and I like it, however, to integrate it in my process it needs to use cmake and conan. I have written those for my own project, would you like me to submit a pull request?
|
||||
|
||||
Regards,
|
||||
Ioannis
|
||||
```
|
||||
A:
|
||||
```
|
||||
Hi Ioannis,
|
||||
|
||||
This is a very common request. I don't accept any specific build systems because I know from experience that doing so opens up hell. People simply cannot agree on which build system to use, or even how to use one particular build system.
|
||||
|
||||
That's why I no longer accept any such PRs. I've had too many CMake PRs dragging in completely different directions to know this is the only solution.
|
||||
|
||||
You'll have to clone the repo and create a new project in whatever build system you want to use.
|
||||
```
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 460 KiB |
@@ -0,0 +1,21 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDXTCCAkWgAwIBAgIJAKLdQVPy90jjMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
|
||||
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
|
||||
aWRnaXRzIFB0eSBMdGQwHhcNMTkwMjAzMTQ0OTM1WhcNMjAwMjAzMTQ0OTM1WjBF
|
||||
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
|
||||
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
||||
CgKCAQEA7i7IIEdICTiSTVx+ma6xHxOtcbd6wGW3nkxlCkJ1UuV8NmY5ovMsGnGD
|
||||
hJJtUQ2j5ig5BcJUf3tezqCNW4tKnSOgSISfEAKvpn2BPvaFq3yx2Yjz0ruvcGKp
|
||||
DMZBXmB/AAtGyN/UFXzkrcfppmLHJTaBYGG6KnmU43gPkSDy4iw46CJFUOupc51A
|
||||
FIz7RsE7mbT1plCM8e75gfqaZSn2k+Wmy+8n1HGyYHhVISRVvPqkS7gVLSVEdTea
|
||||
UtKP1Vx/818/HDWk3oIvDVWI9CFH73elNxBkMH5zArSNIBTehdnehyAevjY4RaC/
|
||||
kK8rslO3e4EtJ9SnA4swOjCiqAIQEwIDAQABo1AwTjAdBgNVHQ4EFgQUv5rc9Smm
|
||||
9c4YnNf3hR49t4rH4yswHwYDVR0jBBgwFoAUv5rc9Smm9c4YnNf3hR49t4rH4ysw
|
||||
DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEATcL9CAAXg0u//eYUAlQa
|
||||
L+l8yKHS1rsq1sdmx7pvsmfZ2g8ONQGfSF3TkzkI2OOnCBokeqAYuyT8awfdNUtE
|
||||
EHOihv4ZzhK2YZVuy0fHX2d4cCFeQpdxno7aN6B37qtsLIRZxkD8PU60Dfu9ea5F
|
||||
DDynnD0TUabna6a0iGn77yD8GPhjaJMOz3gMYjQFqsKL252isDVHEDbpVxIzxPmN
|
||||
w1+WK8zRNdunAcHikeoKCuAPvlZ83gDQHp07dYdbuZvHwGj0nfxBLc9qt90XsBtC
|
||||
4IYR7c/bcLMmKXYf0qoQ4OzngsnPI5M+v9QEHvYWaKVwFY4CTcSNJEwfXw+BAeO5
|
||||
OA==
|
||||
-----END CERTIFICATE-----
|
||||
Binary file not shown.
@@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDuLsggR0gJOJJN
|
||||
XH6ZrrEfE61xt3rAZbeeTGUKQnVS5Xw2Zjmi8ywacYOEkm1RDaPmKDkFwlR/e17O
|
||||
oI1bi0qdI6BIhJ8QAq+mfYE+9oWrfLHZiPPSu69wYqkMxkFeYH8AC0bI39QVfOSt
|
||||
x+mmYsclNoFgYboqeZTjeA+RIPLiLDjoIkVQ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I5
|
||||
V9gTMHJ5jnKd4gYDnaA99eiOcBhgS+9PbgKSAyuUlWwR2ciL/4uDzaVeDQKBgDym
|
||||
vRSeTRn99bSQMMZuuD5N6wkD/RxeCbEnpKrw2aZVN63eGCtkj0v9LCu4gptjseOu
|
||||
7+a4Qplqw3B/SXN5/otqPbEOKv8Shl/PT6RBv06PiFKZClkEU2T3iH27sws2EGru
|
||||
w3C3GaiVMxcVewdg1YOvh5vH8ZVlxApxIzuFlDvnAoGAN5w+gukxd5QnP/7hcLDZ
|
||||
F+vesAykJX71AuqFXB4Wh/qFY92CSm7ImexWA/L9z461+NKeJwb64Nc53z59oA10
|
||||
/3o2OcIe44kddZXQVP6KTZBd7ySVhbtOiK3/pCy+BQRsrC7d71W914DxNWadwZ+a
|
||||
jtwwKjDzmPwdIXDSQarCx0U=
|
||||
-----END PRIVATE KEY-----
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
#include "App.h"
|
||||
|
||||
//#include "../examples/helpers/AsyncFileReader.h"
|
||||
//#include "../examples/helpers/AsyncFileStreamer.h"
|
||||
|
||||
us_listen_socket *token;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
struct PerSocketData {
|
||||
char pad[256];
|
||||
int hello;
|
||||
};
|
||||
|
||||
auto app = uWS::/*SSL*/App({
|
||||
.key_file_name = "/home/alexhultman/key.pem",
|
||||
.cert_file_name = "/home/alexhultman/cert.pem",
|
||||
.passphrase = "1234"
|
||||
}).any("/anything", [](auto *res, auto *req) {
|
||||
std::cout << "Any route with method: " << req->getMethod() << std::endl;
|
||||
res->end("Hello Any route!");
|
||||
}).get("/exit", [](auto *res, auto *req) {
|
||||
|
||||
if (!token) {
|
||||
res->end("Server already closed down!");
|
||||
return;
|
||||
}
|
||||
|
||||
res->end("Closing down server now");
|
||||
|
||||
/* Use this route to signal stop listening */
|
||||
us_listen_socket_close(token);
|
||||
token = nullptr;
|
||||
}).ws<PerSocketData>("/*", {
|
||||
/* Settings */
|
||||
.compression = uWS::DEDICATED_COMPRESSOR,
|
||||
.maxPayloadLength = 16 * 1024 * 1024,
|
||||
.idleTimeout = 10,
|
||||
/* Handlers */
|
||||
.open = [](auto *ws) {
|
||||
std::cout << "WebSocket connected" << std::endl;
|
||||
/* Access per socket data */
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
perSocketData->hello = 13;
|
||||
},
|
||||
.message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
||||
ws->send(message, opCode, true);
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
std::cout << "OK per socket data: " << (perSocketData->hello == 13) << std::endl;
|
||||
},
|
||||
.drain = [](auto *ws) {
|
||||
std::cout << "Drainage: " << ws->getBufferedAmount() << std::endl;
|
||||
},
|
||||
.ping = [](auto *ws) {
|
||||
std::cout << "Ping" << std::endl;
|
||||
},
|
||||
.pong = [](auto *ws) {
|
||||
std::cout << "Pong" << std::endl;
|
||||
},
|
||||
.close = [](auto *ws, int code, std::string_view message) {
|
||||
std::cout << "WebSocket disconnected: " << code << "[" << message << "]" << std::endl;
|
||||
/* Access per socket data */
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
std::cout << "OK per socket data: " << (perSocketData->hello == 13) << std::endl;
|
||||
}
|
||||
}).listen(9001, [](auto *token) {
|
||||
::token = token;
|
||||
if (token) {
|
||||
std::cout << "Listening on port " << 3000 << std::endl;
|
||||
}
|
||||
}).run();
|
||||
|
||||
|
||||
std::cout << "Everything fine, falling through" << std::endl;
|
||||
|
||||
// return 0;
|
||||
|
||||
// AsyncFileStreamer *asyncFileStreamer = new AsyncFileStreamer("/home/alexhultman/v0.15/public");
|
||||
|
||||
// uWS::/*SSL*/App(/*{
|
||||
// .key_file_name = "/home/alexhultman/uWebSockets/misc/ssl/key.pem",
|
||||
// .cert_file_name = "/home/alexhultman/uWebSockets/misc/ssl/cert.pem",
|
||||
// .dh_params_file_name = "/home/alexhultman/dhparams.pem",
|
||||
// .passphrase = "1234"
|
||||
// }*/)/*.get("/*", [](auto *res, auto *req) {
|
||||
|
||||
// res->end("GET /WILDCARD");
|
||||
|
||||
// })*/.get("/:param1/:param2", [](auto *res, auto *req) {
|
||||
|
||||
// res->write("GET /:param1/:param2 = ");
|
||||
// res->write(req->getParameter(0));
|
||||
// res->write(" and ");
|
||||
// res->end(req->getParameter(1));
|
||||
|
||||
// }).post("/hello", [asyncFileStreamer](auto *res, auto *req) {
|
||||
|
||||
// // depending on the file type we want to also add mime!
|
||||
// //asyncFileStreamer->streamFile(res, req->getUrl());
|
||||
|
||||
// res->end("POST /hello");
|
||||
|
||||
// }).get("/hello", [](auto *res, auto *req) {
|
||||
|
||||
// res->end("GET /hello");
|
||||
|
||||
// }).unhandled([](auto *res, auto *req) {
|
||||
|
||||
// res->writeStatus("404 Not Found");
|
||||
// res->writeHeader("Content-Type", "text/html; charset=utf-8");
|
||||
// res->end("<h1>404 Not Found</h1><i>µWebSockets v0.15</i>");
|
||||
|
||||
// }).listen(3000, [](auto *token) {
|
||||
// if (token) {
|
||||
// std::cout << "Listening on port " << 3000 << std::endl;
|
||||
// }
|
||||
// }).run();
|
||||
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 39 KiB |
Binary file not shown.
@@ -1,94 +0,0 @@
|
||||
#include "HttpParser.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
// todo: random test of chunked http parsing of randomly generated requests
|
||||
void testHttpParser() {
|
||||
|
||||
char headers[] = "GET /hello.htm HTTP/1.1\r\n"
|
||||
"User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)\r\n"
|
||||
"Host: www.tutorialspoint.com\r\n"
|
||||
"Accept-Language: en-us\r\n"
|
||||
"Accept-Encoding: gzip, deflate\r\n"
|
||||
"Connection: Keep-Alive\r\n"
|
||||
"Content-length: 1048576\r\n\r\n";
|
||||
|
||||
const int requestLength = sizeof(headers) - 1 + 1048576;
|
||||
char *request = (char *) malloc(requestLength + 32);
|
||||
memset(request, 0, requestLength);
|
||||
memcpy(request, headers, sizeof(headers) - 1);
|
||||
|
||||
char *data = (char *) malloc(requestLength * 10);
|
||||
int length = requestLength * 10;
|
||||
|
||||
int maxChunkSize = 10000;
|
||||
char *paddedBuffer = (char *) malloc(maxChunkSize + 32);
|
||||
|
||||
// dela upp dessa 10 i 5 segment
|
||||
HttpParser httpParser;
|
||||
int validRequests = 0, numDataEmits = 0, numChunks = 0;
|
||||
size_t dataBytes = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
memcpy(data + requestLength * i, request, requestLength);
|
||||
}
|
||||
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
for (int currentOffset = 0; currentOffset != length; ) {
|
||||
|
||||
int chunkSize = rand() % 10000;
|
||||
if (currentOffset + chunkSize > length) {
|
||||
chunkSize = length - currentOffset;
|
||||
}
|
||||
|
||||
memcpy(paddedBuffer, data + currentOffset, chunkSize);
|
||||
|
||||
httpParser.consumePostPadded(paddedBuffer, chunkSize, nullptr, [&validRequests](void *user, HttpRequest *req) {
|
||||
validRequests++;
|
||||
|
||||
if (req->getUrl() != "/hello.htm") {
|
||||
std::cout << "WRONG URL!" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
}, [&dataBytes, &numDataEmits](void *, std::string_view data) {
|
||||
numDataEmits++;
|
||||
dataBytes += data.length();
|
||||
}, [](void *) {
|
||||
|
||||
std::cout << "Error!" << std::endl;
|
||||
return;
|
||||
});
|
||||
|
||||
numChunks++;
|
||||
|
||||
currentOffset += chunkSize;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "validRequests: " << validRequests << std::endl;
|
||||
std::cout << "Data bytes: " << dataBytes << std::endl;
|
||||
std::cout << "Data emits: " << numDataEmits << std::endl;
|
||||
std::cout << "Chunks parsed: " << numChunks << std::endl;
|
||||
|
||||
validRequests = 0;
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < 10000000; i++) {
|
||||
httpParser.consumePostPadded(request, requestLength, nullptr, [&validRequests](void *user, HttpRequest *req) {
|
||||
validRequests++;
|
||||
}, [](void *, std::string_view data) {
|
||||
|
||||
}, [](void *) {
|
||||
|
||||
});
|
||||
}
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
|
||||
std::cout << "Parsed " << validRequests << " in " << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count() << "ms" << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
testHttpParser();
|
||||
}
|
||||
+8
-1
@@ -10,8 +10,15 @@ namespace uWS {
|
||||
Http3Context *http3Context;
|
||||
|
||||
H3App(SocketContextOptions options = {}) {
|
||||
/* This conversion should not be needed */
|
||||
us_quic_socket_context_options_t h3options = {};
|
||||
|
||||
h3options.key_file_name = strdup(options.key_file_name);
|
||||
h3options.cert_file_name = strdup(options.cert_file_name);
|
||||
h3options.passphrase = strdup(options.passphrase);
|
||||
|
||||
/* Create the http3 context */
|
||||
http3Context = Http3Context::create((us_loop_t *)Loop::get(), {});
|
||||
http3Context = Http3Context::create((us_loop_t *)Loop::get(), h3options);
|
||||
|
||||
http3Context->init();
|
||||
}
|
||||
|
||||
+18
-1
@@ -2,6 +2,8 @@ extern "C" {
|
||||
#include "quic.h"
|
||||
}
|
||||
|
||||
#include "Http3ResponseData.h"
|
||||
|
||||
namespace uWS {
|
||||
|
||||
/* Is a quic stream */
|
||||
@@ -11,9 +13,24 @@ namespace uWS {
|
||||
|
||||
}
|
||||
|
||||
void writeHeader() {
|
||||
|
||||
}
|
||||
|
||||
void tryEnd() {
|
||||
|
||||
}
|
||||
|
||||
void write() {
|
||||
|
||||
}
|
||||
|
||||
void end(std::string_view data) {
|
||||
|
||||
// Http3ResponseData *responseData = us_quic_stream_ext(this);
|
||||
Http3ResponseData *responseData = (Http3ResponseData *) us_quic_stream_ext((us_quic_stream_t *) this);
|
||||
|
||||
printf("Wrapper responseData is %p\n", responseData);
|
||||
printf("%s\n", responseData);
|
||||
|
||||
// if not already written status then write status
|
||||
|
||||
|
||||
+12
-1
@@ -1,5 +1,16 @@
|
||||
#ifndef UWS_H3RESPONSEDATA_H
|
||||
#define UWS_H3RESPONSEDATA_H
|
||||
|
||||
namespace uWS {
|
||||
struct Http3ResponseData {
|
||||
|
||||
|
||||
// will need onWritable
|
||||
// onData
|
||||
|
||||
// hasWrittenStatus
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+1
-1
Submodule uSockets updated: 4528c2f9dd...f78aba50c0
Reference in New Issue
Block a user