Clean-ups, bump copyright date
This commit is contained in:
@@ -8,7 +8,7 @@ prefix ?= /usr/local
|
|||||||
|
|
||||||
# WITH_PROXY enables PROXY Protocol v2 support
|
# WITH_PROXY enables PROXY Protocol v2 support
|
||||||
ifeq ($(WITH_PROXY),1)
|
ifeq ($(WITH_PROXY),1)
|
||||||
override CXXFLAGS += -DWITH_PROXY
|
override CXXFLAGS += -DUWS_WITH_PROXY
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# WITH_OPENSSL=1 enables OpenSSL 1.1+ support
|
# WITH_OPENSSL=1 enables OpenSSL 1.1+ support
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
|
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
|
||||||
|
|
||||||
@@ -10,8 +9,6 @@ int main() {
|
|||||||
.cert_file_name = "../misc/cert.pem",
|
.cert_file_name = "../misc/cert.pem",
|
||||||
.passphrase = "1234"
|
.passphrase = "1234"
|
||||||
}).get("/*", [](auto *res, auto *req) {
|
}).get("/*", [](auto *res, auto *req) {
|
||||||
std::cout << res->getRemoteAddressAsText() << std::endl;
|
|
||||||
std::cout << res->getProxiedRemoteAddressAsText() << std::endl;
|
|
||||||
res->end("Hello world!");
|
res->end("Hello world!");
|
||||||
}).listen(3000, [](auto *token) {
|
}).listen(3000, [](auto *token) {
|
||||||
if (token) {
|
if (token) {
|
||||||
|
|||||||
+1
-1
@@ -127,7 +127,7 @@ private:
|
|||||||
// how far did we read then? we need to know to continue with websocket parsing data? or?
|
// how far did we read then? we need to know to continue with websocket parsing data? or?
|
||||||
|
|
||||||
void *proxyParser = nullptr;
|
void *proxyParser = nullptr;
|
||||||
#ifdef WITH_PROXY
|
#ifdef UWS_WITH_PROXY
|
||||||
proxyParser = &httpResponseData->proxyParser;
|
proxyParser = &httpResponseData->proxyParser;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
+1
-1
@@ -183,7 +183,7 @@ private:
|
|||||||
/* How much data we CONSUMED (to throw away) */
|
/* How much data we CONSUMED (to throw away) */
|
||||||
int consumedTotal = 0;
|
int consumedTotal = 0;
|
||||||
|
|
||||||
#ifdef WITH_PROXY
|
#ifdef UWS_WITH_PROXY
|
||||||
/* ProxyParser is passed as reserved parameter */
|
/* ProxyParser is passed as reserved parameter */
|
||||||
ProxyParser *pp = (ProxyParser *) reserved;
|
ProxyParser *pp = (ProxyParser *) reserved;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -168,7 +168,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/* If we have proxy support; returns the proxed source address as reported by the proxy. */
|
/* If we have proxy support; returns the proxed source address as reported by the proxy. */
|
||||||
#ifdef WITH_PROXY
|
#ifdef UWS_WITH_PROXY
|
||||||
std::string_view getProxiedRemoteAddress() {
|
std::string_view getProxiedRemoteAddress() {
|
||||||
return getHttpResponseData()->proxyParser.getSourceAddress();
|
return getHttpResponseData()->proxyParser.getSourceAddress();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,10 @@
|
|||||||
|
|
||||||
#include "HttpParser.h"
|
#include "HttpParser.h"
|
||||||
#include "AsyncSocketData.h"
|
#include "AsyncSocketData.h"
|
||||||
|
#include "ProxyParser.h"
|
||||||
|
|
||||||
#include "f2/function2.hpp"
|
#include "f2/function2.hpp"
|
||||||
|
|
||||||
#include "ProxyParser.h"
|
|
||||||
|
|
||||||
namespace uWS {
|
namespace uWS {
|
||||||
|
|
||||||
template <bool SSL>
|
template <bool SSL>
|
||||||
@@ -53,8 +52,7 @@ private:
|
|||||||
/* Current state (content-length sent, status sent, write called, etc */
|
/* Current state (content-length sent, status sent, write called, etc */
|
||||||
int state = 0;
|
int state = 0;
|
||||||
|
|
||||||
#ifdef WITH_PROXY
|
#ifdef UWS_WITH_PROXY
|
||||||
// proxy protocol
|
|
||||||
ProxyParser proxyParser;
|
ProxyParser proxyParser;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
+45
-17
@@ -1,11 +1,28 @@
|
|||||||
//
|
/*
|
||||||
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
// implements PROXY v2 protocol
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
|
||||||
#ifndef PROXY_PARSER
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#define PROXY_PARSER
|
|
||||||
|
|
||||||
#ifdef WITH_PROXY
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This module implements The PROXY Protocol v2 */
|
||||||
|
|
||||||
|
#ifndef UWS_PROXY_PARSER_H
|
||||||
|
#define UWS_PROXY_PARSER_H
|
||||||
|
|
||||||
|
#ifdef UWS_WITH_PROXY
|
||||||
|
|
||||||
|
namespace uWS {
|
||||||
|
|
||||||
struct proxy_hdr_v2 {
|
struct proxy_hdr_v2 {
|
||||||
uint8_t sig[12]; /* hex 0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A */
|
uint8_t sig[12]; /* hex 0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A */
|
||||||
@@ -30,6 +47,7 @@ union proxy_addr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Byte swap for little-endian systems */
|
/* Byte swap for little-endian systems */
|
||||||
|
/* Todo: This functions should be shared with the one in WebSocketProtocol.h! */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T _cond_byte_swap(T value) {
|
T _cond_byte_swap(T value) {
|
||||||
uint32_t endian_test = 1;
|
uint32_t endian_test = 1;
|
||||||
@@ -52,7 +70,7 @@ struct ProxyParser {
|
|||||||
private:
|
private:
|
||||||
union proxy_addr addr;
|
union proxy_addr addr;
|
||||||
|
|
||||||
// we should have "unset" where the return value is "" from proxied ip!
|
/* Default family of 0 signals no proxy address */
|
||||||
uint8_t family = 0;
|
uint8_t family = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -94,6 +112,7 @@ public:
|
|||||||
return {false, 0};
|
return {false, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Header is 16 bytes */
|
||||||
struct proxy_hdr_v2 header;
|
struct proxy_hdr_v2 header;
|
||||||
memcpy(&header, data.data(), 16);
|
memcpy(&header, data.data(), 16);
|
||||||
|
|
||||||
@@ -102,34 +121,43 @@ public:
|
|||||||
return {false, 0};
|
return {false, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have version 2 */
|
/* We only support version 2 */
|
||||||
|
if ((header.ver_cmd & 0xf0) >> 4 != 2) {
|
||||||
|
return {false, 0};
|
||||||
|
}
|
||||||
|
|
||||||
printf("Version: %d\n", (header.ver_cmd & 0xf0) >> 4);
|
//printf("Version: %d\n", (header.ver_cmd & 0xf0) >> 4);
|
||||||
printf("Command: %d\n", (header.ver_cmd & 0x0f));
|
//printf("Command: %d\n", (header.ver_cmd & 0x0f));
|
||||||
|
|
||||||
|
/* We get length in network byte order (todo: share this function with the rest) */
|
||||||
uint16_t hostLength = _cond_byte_swap<uint16_t>(header.len);
|
uint16_t hostLength = _cond_byte_swap<uint16_t>(header.len);
|
||||||
|
|
||||||
|
/* We must have all the data available */
|
||||||
if (data.length() < 16 + hostLength) {
|
if (data.length() < 16 + hostLength) {
|
||||||
return {false, 0};
|
return {false, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Length: %d\n", hostLength);
|
/* Payload cannot be more than sizeof proxy_addr */
|
||||||
|
if (sizeof(proxy_addr) < hostLength) {
|
||||||
|
return {false, 0};
|
||||||
|
}
|
||||||
|
|
||||||
printf("Family: %d\n", (header.fam & 0xf0) >> 4);
|
//printf("Family: %d\n", (header.fam & 0xf0) >> 4);
|
||||||
printf("Transport: %d\n", (header.fam & 0x0f));
|
//printf("Transport: %d\n", (header.fam & 0x0f));
|
||||||
|
|
||||||
|
/* We have 0 family by default, and UNSPEC is 0 as well */
|
||||||
family = header.fam;
|
family = header.fam;
|
||||||
|
|
||||||
// copy source ip
|
/* Copy payload */
|
||||||
memcpy(&addr, data.data() + 16, hostLength);
|
memcpy(&addr, data.data() + 16, hostLength);
|
||||||
|
|
||||||
|
/* We consumed everything */
|
||||||
|
|
||||||
return {true, 16 + hostLength};
|
return {true, 16 + hostLength};
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // UWS_PROXY_PARSER_H
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Authored by Alex Hultman, 2018-2019.
|
* Authored by Alex Hultman, 2018-2020.
|
||||||
* Intellectual property of third-party.
|
* Intellectual property of third-party.
|
||||||
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
Reference in New Issue
Block a user