Compare commits
6 Commits
bug/docker
...
v11.0.9
Author | SHA1 | Date | |
---|---|---|---|
f090c7659b | |||
7c195219cd | |||
d739662a7c | |||
e7f7e470e2 | |||
d239738ec6 | |||
c61975bf75 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ ws/.certs/
|
|||||||
ws/.srl
|
ws/.srl
|
||||||
ixhttpd
|
ixhttpd
|
||||||
makefile
|
makefile
|
||||||
|
a.out
|
||||||
|
@ -17,7 +17,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -gz")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||||
@ -191,7 +191,7 @@ if (USE_TLS)
|
|||||||
target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES})
|
target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES})
|
||||||
elseif (USE_SECURE_TRANSPORT)
|
elseif (USE_SECURE_TRANSPORT)
|
||||||
message(STATUS "TLS configured to use secure transport")
|
message(STATUS "TLS configured to use secure transport")
|
||||||
target_link_libraries(ixwebsocket "-framework foundation" "-framework security")
|
target_link_libraries(ixwebsocket "-framework Foundation" "-framework Security")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
19
README.md
19
README.md
@ -15,8 +15,8 @@ A bad security bug affecting users compiling with SSL enabled and OpenSSL as the
|
|||||||
* Super simple standalone example. See ws folder, unittest and doc/usage.md for more.
|
* Super simple standalone example. See ws folder, unittest and doc/usage.md for more.
|
||||||
*
|
*
|
||||||
* On macOS
|
* On macOS
|
||||||
* $ mkdir -p build ; cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install
|
* $ mkdir -p build ; (cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install)
|
||||||
* $ clang++ --std=c++14 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
|
* $ clang++ --std=c++11 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
|
||||||
* $ ./a.out
|
* $ ./a.out
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -44,10 +44,12 @@ int main()
|
|||||||
if (msg->type == ix::WebSocketMessageType::Message)
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
{
|
{
|
||||||
std::cout << "received message: " << msg->str << std::endl;
|
std::cout << "received message: " << msg->str << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
else if (msg->type == ix::WebSocketMessageType::Open)
|
else if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
{
|
{
|
||||||
std::cout << "Connection established" << std::endl;
|
std::cout << "Connection established" << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -58,13 +60,16 @@ int main()
|
|||||||
// Send a message to the server (default to TEXT mode)
|
// Send a message to the server (default to TEXT mode)
|
||||||
webSocket.send("hello world");
|
webSocket.send("hello world");
|
||||||
|
|
||||||
while (true)
|
// Display a prompt
|
||||||
{
|
std::cout << "> " << std::flush;
|
||||||
std::string text;
|
|
||||||
std::cout << "> " << std::flush;
|
|
||||||
std::getline(std::cin, text);
|
|
||||||
|
|
||||||
|
std::string text;
|
||||||
|
// Read text from the console and send messages in text mode.
|
||||||
|
// Exit with Ctrl-D on Unix or Ctrl-Z on Windows.
|
||||||
|
while (std::getline(std::cin, text))
|
||||||
|
{
|
||||||
webSocket.send(text);
|
webSocket.send(text);
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
7
build.sh
7
build.sh
@ -1,7 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
rm -rf build
|
|
||||||
mkdir -p build
|
|
||||||
cd build
|
|
||||||
cmake -GNinja -DCMAKE_UNITY_BUILD=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DUSE_TLS=1 -DUSE_WS=1 -DUSE_TEST=OFF ..
|
|
||||||
ninja
|
|
@ -1,25 +1,39 @@
|
|||||||
# Build time
|
FROM alpine:3.12 as build
|
||||||
#
|
|
||||||
# Build with
|
|
||||||
# docker build --ssh default -t ws .
|
|
||||||
#
|
|
||||||
# focal == ubuntu 2020.04
|
|
||||||
# groovy == ubuntu 2020.10
|
|
||||||
FROM ubuntu:groovy
|
|
||||||
|
|
||||||
RUN apt update
|
RUN apk add --no-cache \
|
||||||
|
gcc g++ musl-dev linux-headers \
|
||||||
|
cmake mbedtls-dev make zlib-dev python3-dev ninja git
|
||||||
|
|
||||||
RUN apt-get -y install g++ cmake make automake ccache libtool flex bison pkg-config git python3 jq
|
RUN addgroup -S app && \
|
||||||
RUN apt-get -y install libjemalloc-dev libssl-dev libmcrypt-dev mcrypt zlib1g lua5.1-dev uuid-dev libz-dev binutils-dev
|
adduser -S -G app app && \
|
||||||
RUN apt-get -y install libboost-dev libboost-test-dev libboost-program-options-dev libboost-all-dev libboost-regex-dev
|
chown -R app:app /opt && \
|
||||||
RUN apt-get -y install ninja-build
|
chown -R app:app /usr/local
|
||||||
|
|
||||||
COPY . /opt
|
# There is a bug in CMake where we cannot build from the root top folder
|
||||||
|
# So we build from /opt
|
||||||
|
COPY --chown=app:app . /opt
|
||||||
WORKDIR /opt
|
WORKDIR /opt
|
||||||
|
|
||||||
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
|
USER app
|
||||||
RUN rm -rf build
|
RUN make -f makefile.dev ws_mbedtls_install && \
|
||||||
RUN --mount=type=ssh ./build.sh
|
sh tools/trim_repo_for_docker.sh
|
||||||
|
|
||||||
COPY /opt/build/ws/ws /usr/local/bin/ws
|
FROM alpine:3.12 as runtime
|
||||||
CMD ["/usr/local/bin/ws"]
|
|
||||||
|
RUN apk add --no-cache libstdc++ mbedtls ca-certificates python3 strace && \
|
||||||
|
addgroup -S app && \
|
||||||
|
adduser -S -G app app
|
||||||
|
|
||||||
|
COPY --chown=app:app --from=build /usr/local/bin/ws /usr/local/bin/ws
|
||||||
|
|
||||||
|
# COPY --chown=app:app --from=build /opt /opt
|
||||||
|
|
||||||
|
RUN chmod +x /usr/local/bin/ws && \
|
||||||
|
ldd /usr/local/bin/ws
|
||||||
|
|
||||||
|
# Now run in usermode
|
||||||
|
USER app
|
||||||
|
WORKDIR /home/app
|
||||||
|
|
||||||
|
ENTRYPOINT ["ws"]
|
||||||
|
EXPOSE 8008
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [11.0.9] - 2021-03-07
|
||||||
|
|
||||||
|
(ixwebsocket) Expose setHandshakeTimeout method
|
||||||
|
|
||||||
## [11.0.8] - 2020-12-25
|
## [11.0.8] - 2020-12-25
|
||||||
|
|
||||||
(ws) trim ws dependencies no more ixcrypto and ixcore deps
|
(ws) trim ws dependencies no more ixcrypto and ixcore deps
|
||||||
|
@ -263,6 +263,15 @@ webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s
|
|||||||
uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries();
|
uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Handshake timeout
|
||||||
|
|
||||||
|
You can control how long to wait until timing out while waiting for the websocket handshake to be performed.
|
||||||
|
|
||||||
|
```
|
||||||
|
int handshakeTimeoutSecs = 1;
|
||||||
|
setHandshakeTimeout(handshakeTimeoutSecs);
|
||||||
|
```
|
||||||
|
|
||||||
## WebSocket server API
|
## WebSocket server API
|
||||||
|
|
||||||
### Legacy api
|
### Legacy api
|
||||||
|
@ -56,6 +56,11 @@ namespace ix
|
|||||||
_url = url;
|
_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebSocket::setHandshakeTimeout(int handshakeTimeoutSecs)
|
||||||
|
{
|
||||||
|
_handshakeTimeoutSecs = handshakeTimeoutSecs;
|
||||||
|
}
|
||||||
|
|
||||||
void WebSocket::setExtraHeaders(const WebSocketHttpHeaders& headers)
|
void WebSocket::setExtraHeaders(const WebSocketHttpHeaders& headers)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_configMutex);
|
std::lock_guard<std::mutex> lock(_configMutex);
|
||||||
|
@ -58,6 +58,7 @@ namespace ix
|
|||||||
void enablePerMessageDeflate();
|
void enablePerMessageDeflate();
|
||||||
void disablePerMessageDeflate();
|
void disablePerMessageDeflate();
|
||||||
void addSubProtocol(const std::string& subProtocol);
|
void addSubProtocol(const std::string& subProtocol);
|
||||||
|
void setHandshakeTimeout(int handshakeTimeoutSecs);
|
||||||
|
|
||||||
// Run asynchronously, by calling start and stop.
|
// Run asynchronously, by calling start and stop.
|
||||||
void start();
|
void start();
|
||||||
|
@ -175,30 +175,29 @@ namespace ix
|
|||||||
//
|
//
|
||||||
void WebSocketServer::makeBroadcastServer()
|
void WebSocketServer::makeBroadcastServer()
|
||||||
{
|
{
|
||||||
setOnClientMessageCallback(
|
setOnClientMessageCallback([this](std::shared_ptr<ConnectionState> connectionState,
|
||||||
[this](std::shared_ptr<ConnectionState> connectionState,
|
WebSocket& webSocket,
|
||||||
WebSocket& webSocket,
|
const WebSocketMessagePtr& msg) {
|
||||||
const WebSocketMessagePtr& msg) {
|
auto remoteIp = connectionState->getRemoteIp();
|
||||||
auto remoteIp = connectionState->getRemoteIp();
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
if (msg->type == ix::WebSocketMessageType::Message)
|
{
|
||||||
|
for (auto&& client : getClients())
|
||||||
{
|
{
|
||||||
for (auto&& client : getClients())
|
if (client.get() != &webSocket)
|
||||||
{
|
{
|
||||||
if (client.get() != &webSocket)
|
client->send(msg->str, msg->binary);
|
||||||
{
|
|
||||||
client->send(msg->str, msg->binary);
|
|
||||||
|
|
||||||
// Make sure the OS send buffer is flushed before moving on
|
// Make sure the OS send buffer is flushed before moving on
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
size_t bufferedAmount = client->bufferedAmount();
|
||||||
std::chrono::duration<double, std::milli> duration(500);
|
std::chrono::duration<double, std::milli> duration(500);
|
||||||
std::this_thread::sleep_for(duration);
|
std::this_thread::sleep_for(duration);
|
||||||
} while (client->bufferedAmount() != 0);
|
} while (client->bufferedAmount() != 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebSocketServer::listenAndStart()
|
int WebSocketServer::listenAndStart()
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "11.0.8"
|
#define IX_WEBSOCKET_VERSION "11.0.9"
|
||||||
|
15
main.cpp
15
main.cpp
@ -35,10 +35,12 @@ int main()
|
|||||||
if (msg->type == ix::WebSocketMessageType::Message)
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
{
|
{
|
||||||
std::cout << "received message: " << msg->str << std::endl;
|
std::cout << "received message: " << msg->str << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
else if (msg->type == ix::WebSocketMessageType::Open)
|
else if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
{
|
{
|
||||||
std::cout << "Connection established" << std::endl;
|
std::cout << "Connection established" << std::endl;
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -49,13 +51,16 @@ int main()
|
|||||||
// Send a message to the server (default to TEXT mode)
|
// Send a message to the server (default to TEXT mode)
|
||||||
webSocket.send("hello world");
|
webSocket.send("hello world");
|
||||||
|
|
||||||
while (true)
|
// Display a prompt
|
||||||
{
|
std::cout << "> " << std::flush;
|
||||||
std::string text;
|
|
||||||
std::cout << "> " << std::flush;
|
|
||||||
std::getline(std::cin, text);
|
|
||||||
|
|
||||||
|
std::string text;
|
||||||
|
// Read text from the console and send messages in text mode.
|
||||||
|
// Exit with Ctrl-D on Unix or Ctrl-Z on Windows.
|
||||||
|
while (std::getline(std::cin, text))
|
||||||
|
{
|
||||||
webSocket.send(text);
|
webSocket.send(text);
|
||||||
|
std::cout << "> " << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -33,11 +33,7 @@ TEST_CASE("dns", "[net]")
|
|||||||
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
|
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
|
||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return false; });
|
||||||
[]
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
std::cerr << "Error message: " << errMsg << std::endl;
|
std::cerr << "Error message: " << errMsg << std::endl;
|
||||||
REQUIRE(res == nullptr);
|
REQUIRE(res == nullptr);
|
||||||
}
|
}
|
||||||
@ -48,11 +44,7 @@ TEST_CASE("dns", "[net]")
|
|||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
// The callback returning true means we are requesting cancellation
|
// The callback returning true means we are requesting cancellation
|
||||||
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return true; });
|
||||||
[]
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
std::cerr << "Error message: " << errMsg << std::endl;
|
std::cerr << "Error message: " << errMsg << std::endl;
|
||||||
REQUIRE(res == nullptr);
|
REQUIRE(res == nullptr);
|
||||||
}
|
}
|
||||||
|
@ -2378,9 +2378,9 @@ namespace ix
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string readyStateString =
|
std::string readyStateString =
|
||||||
readyState == ReadyState::Connecting
|
readyState == ReadyState::Connecting ? "Connecting"
|
||||||
? "Connecting"
|
: readyState == ReadyState::Closing ? "Closing"
|
||||||
: readyState == ReadyState::Closing ? "Closing" : "Closed";
|
: "Closed";
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
size_t bufferedAmount = client->bufferedAmount();
|
||||||
|
|
||||||
spdlog::info(
|
spdlog::info(
|
||||||
|
Reference in New Issue
Block a user