Compare commits
1 Commits
v11.0.9
...
bug/docker
Author | SHA1 | Date | |
---|---|---|---|
|
e31b913280 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,4 +7,3 @@ 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")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -gz")
|
||||||
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++11 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
|
* $ clang++ --std=c++14 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
|
||||||
* $ ./a.out
|
* $ ./a.out
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -44,12 +44,10 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -60,16 +58,13 @@ 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");
|
||||||
|
|
||||||
// Display a prompt
|
while (true)
|
||||||
std::cout << "> " << std::flush;
|
|
||||||
|
|
||||||
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);
|
std::string text;
|
||||||
std::cout << "> " << std::flush;
|
std::cout << "> " << std::flush;
|
||||||
|
std::getline(std::cin, text);
|
||||||
|
|
||||||
|
webSocket.send(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
7
build.sh
Normal file
7
build.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/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,39 +1,25 @@
|
|||||||
FROM alpine:3.12 as build
|
# Build time
|
||||||
|
#
|
||||||
|
# Build with
|
||||||
|
# docker build --ssh default -t ws .
|
||||||
|
#
|
||||||
|
# focal == ubuntu 2020.04
|
||||||
|
# groovy == ubuntu 2020.10
|
||||||
|
FROM ubuntu:groovy
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apt update
|
||||||
gcc g++ musl-dev linux-headers \
|
|
||||||
cmake mbedtls-dev make zlib-dev python3-dev ninja git
|
|
||||||
|
|
||||||
RUN addgroup -S app && \
|
RUN apt-get -y install g++ cmake make automake ccache libtool flex bison pkg-config git python3 jq
|
||||||
adduser -S -G app app && \
|
RUN apt-get -y install libjemalloc-dev libssl-dev libmcrypt-dev mcrypt zlib1g lua5.1-dev uuid-dev libz-dev binutils-dev
|
||||||
chown -R app:app /opt && \
|
RUN apt-get -y install libboost-dev libboost-test-dev libboost-program-options-dev libboost-all-dev libboost-regex-dev
|
||||||
chown -R app:app /usr/local
|
RUN apt-get -y install ninja-build
|
||||||
|
|
||||||
# There is a bug in CMake where we cannot build from the root top folder
|
COPY . /opt
|
||||||
# So we build from /opt
|
|
||||||
COPY --chown=app:app . /opt
|
|
||||||
WORKDIR /opt
|
WORKDIR /opt
|
||||||
|
|
||||||
USER app
|
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||||
RUN make -f makefile.dev ws_mbedtls_install && \
|
RUN rm -rf build
|
||||||
sh tools/trim_repo_for_docker.sh
|
RUN --mount=type=ssh ./build.sh
|
||||||
|
|
||||||
FROM alpine:3.12 as runtime
|
COPY /opt/build/ws/ws /usr/local/bin/ws
|
||||||
|
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,10 +2,6 @@
|
|||||||
|
|
||||||
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,15 +263,6 @@ 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,11 +56,6 @@ 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,7 +58,6 @@ 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,29 +175,30 @@ namespace ix
|
|||||||
//
|
//
|
||||||
void WebSocketServer::makeBroadcastServer()
|
void WebSocketServer::makeBroadcastServer()
|
||||||
{
|
{
|
||||||
setOnClientMessageCallback([this](std::shared_ptr<ConnectionState> connectionState,
|
setOnClientMessageCallback(
|
||||||
WebSocket& webSocket,
|
[this](std::shared_ptr<ConnectionState> connectionState,
|
||||||
const WebSocketMessagePtr& msg) {
|
WebSocket& webSocket,
|
||||||
auto remoteIp = connectionState->getRemoteIp();
|
const WebSocketMessagePtr& msg) {
|
||||||
if (msg->type == ix::WebSocketMessageType::Message)
|
auto remoteIp = connectionState->getRemoteIp();
|
||||||
{
|
if (msg->type == ix::WebSocketMessageType::Message)
|
||||||
for (auto&& client : getClients())
|
|
||||||
{
|
{
|
||||||
if (client.get() != &webSocket)
|
for (auto&& client : getClients())
|
||||||
{
|
{
|
||||||
client->send(msg->str, msg->binary);
|
if (client.get() != &webSocket)
|
||||||
|
|
||||||
// Make sure the OS send buffer is flushed before moving on
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
client->send(msg->str, msg->binary);
|
||||||
std::chrono::duration<double, std::milli> duration(500);
|
|
||||||
std::this_thread::sleep_for(duration);
|
// Make sure the OS send buffer is flushed before moving on
|
||||||
} while (client->bufferedAmount() != 0);
|
do
|
||||||
|
{
|
||||||
|
size_t bufferedAmount = client->bufferedAmount();
|
||||||
|
std::chrono::duration<double, std::milli> duration(500);
|
||||||
|
std::this_thread::sleep_for(duration);
|
||||||
|
} while (client->bufferedAmount() != 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebSocketServer::listenAndStart()
|
int WebSocketServer::listenAndStart()
|
||||||
|
@@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "11.0.9"
|
#define IX_WEBSOCKET_VERSION "11.0.8"
|
||||||
|
15
main.cpp
15
main.cpp
@@ -35,12 +35,10 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -51,16 +49,13 @@ 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");
|
||||||
|
|
||||||
// Display a prompt
|
while (true)
|
||||||
std::cout << "> " << std::flush;
|
|
||||||
|
|
||||||
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);
|
std::string text;
|
||||||
std::cout << "> " << std::flush;
|
std::cout << "> " << std::flush;
|
||||||
|
std::getline(std::cin, text);
|
||||||
|
|
||||||
|
webSocket.send(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -33,7 +33,11 @@ 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, [] { return false; });
|
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
||||||
|
[]
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
});
|
||||||
std::cerr << "Error message: " << errMsg << std::endl;
|
std::cerr << "Error message: " << errMsg << std::endl;
|
||||||
REQUIRE(res == nullptr);
|
REQUIRE(res == nullptr);
|
||||||
}
|
}
|
||||||
@@ -44,7 +48,11 @@ 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, [] { return true; });
|
struct addrinfo* res = dnsLookup->resolve(errMsg,
|
||||||
|
[]
|
||||||
|
{
|
||||||
|
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 ? "Connecting"
|
readyState == ReadyState::Connecting
|
||||||
: readyState == ReadyState::Closing ? "Closing"
|
? "Connecting"
|
||||||
: "Closed";
|
: readyState == ReadyState::Closing ? "Closing" : "Closed";
|
||||||
size_t bufferedAmount = client->bufferedAmount();
|
size_t bufferedAmount = client->bufferedAmount();
|
||||||
|
|
||||||
spdlog::info(
|
spdlog::info(
|
||||||
|
Reference in New Issue
Block a user