Merge branch 'master' into feature/no_automatic_reconnection
This commit is contained in:
commit
21c155339e
42
Dockerfile
42
Dockerfile
@ -1,42 +0,0 @@
|
|||||||
FROM fedora:30 as build
|
|
||||||
|
|
||||||
RUN yum install -y gcc-g++
|
|
||||||
RUN yum install -y cmake
|
|
||||||
RUN yum install -y make
|
|
||||||
RUN yum install -y openssl-devel
|
|
||||||
|
|
||||||
RUN yum install -y wget
|
|
||||||
RUN mkdir -p /tmp/cmake
|
|
||||||
WORKDIR /tmp/cmake
|
|
||||||
RUN wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-Linux-x86_64.tar.gz
|
|
||||||
RUN tar zxf cmake-3.14.0-Linux-x86_64.tar.gz
|
|
||||||
|
|
||||||
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-Linux-x86_64/bin
|
|
||||||
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
|
||||||
|
|
||||||
RUN yum install -y python
|
|
||||||
RUN yum install -y libtsan
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
# RUN ["make", "test"]
|
|
||||||
RUN ["make"]
|
|
||||||
|
|
||||||
# Runtime
|
|
||||||
FROM fedora:30 as runtime
|
|
||||||
|
|
||||||
RUN yum install -y libtsan
|
|
||||||
|
|
||||||
RUN groupadd app && useradd -g app app
|
|
||||||
COPY --chown=app:app --from=build /usr/local/bin/ws /usr/local/bin/ws
|
|
||||||
RUN chmod +x /usr/local/bin/ws
|
|
||||||
RUN ldd /usr/local/bin/ws
|
|
||||||
|
|
||||||
# Now run in usermode
|
|
||||||
USER app
|
|
||||||
WORKDIR /home/app
|
|
||||||
|
|
||||||
COPY --chown=app:app ws/snake/appsConfig.json .
|
|
||||||
COPY --chown=app:app ws/cobraMetricsSample.json .
|
|
||||||
|
|
||||||
ENTRYPOINT ["ws"]
|
|
||||||
CMD ["--help"]
|
|
1
Dockerfile
Symbolic link
1
Dockerfile
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
docker/Dockerfile.fedora
|
52
docker/Dockerfile.debian
Normal file
52
docker/Dockerfile.debian
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# Build time
|
||||||
|
FROM debian:buster as build
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get -y install wget
|
||||||
|
RUN mkdir -p /tmp/cmake
|
||||||
|
WORKDIR /tmp/cmake
|
||||||
|
RUN wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
RUN tar zxf cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
|
||||||
|
RUN apt-get -y install g++
|
||||||
|
RUN apt-get -y install libssl-dev
|
||||||
|
RUN apt-get -y install libz-dev
|
||||||
|
RUN apt-get -y install make
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-Linux-x86_64/bin
|
||||||
|
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
||||||
|
|
||||||
|
RUN ["make"]
|
||||||
|
|
||||||
|
# Runtime
|
||||||
|
FROM debian:buster as runtime
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
RUN apt-get update
|
||||||
|
# Runtime
|
||||||
|
RUN apt-get install -y libssl1.1
|
||||||
|
RUN apt-get install -y ca-certificates
|
||||||
|
RUN ["update-ca-certificates"]
|
||||||
|
|
||||||
|
# Debugging
|
||||||
|
RUN apt-get install -y strace
|
||||||
|
RUN apt-get install -y procps
|
||||||
|
RUN apt-get install -y htop
|
||||||
|
|
||||||
|
RUN adduser --disabled-password --gecos '' app
|
||||||
|
COPY --chown=app:app --from=build /usr/local/bin/ws /usr/local/bin/ws
|
||||||
|
RUN chmod +x /usr/local/bin/ws
|
||||||
|
RUN ldd /usr/local/bin/ws
|
||||||
|
|
||||||
|
# Now run in usermode
|
||||||
|
USER app
|
||||||
|
WORKDIR /home/app
|
||||||
|
|
||||||
|
COPY --chown=app:app ws/snake/appsConfig.json .
|
||||||
|
COPY --chown=app:app ws/cobraMetricsSample.json .
|
||||||
|
|
||||||
|
ENTRYPOINT ["ws"]
|
||||||
|
CMD ["--help"]
|
42
docker/Dockerfile.fedora
Normal file
42
docker/Dockerfile.fedora
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
FROM fedora:30 as build
|
||||||
|
|
||||||
|
RUN yum install -y gcc-g++
|
||||||
|
RUN yum install -y cmake
|
||||||
|
RUN yum install -y make
|
||||||
|
RUN yum install -y openssl-devel
|
||||||
|
|
||||||
|
RUN yum install -y wget
|
||||||
|
RUN mkdir -p /tmp/cmake
|
||||||
|
WORKDIR /tmp/cmake
|
||||||
|
RUN wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
RUN tar zxf cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
|
||||||
|
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-Linux-x86_64/bin
|
||||||
|
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
||||||
|
|
||||||
|
RUN yum install -y python
|
||||||
|
RUN yum install -y libtsan
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
# RUN ["make", "test"]
|
||||||
|
RUN ["make"]
|
||||||
|
|
||||||
|
# Runtime
|
||||||
|
FROM fedora:30 as runtime
|
||||||
|
|
||||||
|
RUN yum install -y libtsan
|
||||||
|
|
||||||
|
RUN groupadd app && useradd -g app app
|
||||||
|
COPY --chown=app:app --from=build /usr/local/bin/ws /usr/local/bin/ws
|
||||||
|
RUN chmod +x /usr/local/bin/ws
|
||||||
|
RUN ldd /usr/local/bin/ws
|
||||||
|
|
||||||
|
# Now run in usermode
|
||||||
|
USER app
|
||||||
|
WORKDIR /home/app
|
||||||
|
|
||||||
|
COPY --chown=app:app ws/snake/appsConfig.json .
|
||||||
|
COPY --chown=app:app ws/cobraMetricsSample.json .
|
||||||
|
|
||||||
|
ENTRYPOINT ["ws"]
|
||||||
|
CMD ["--help"]
|
24
docker/Dockerfile.ubuntu_xenial
Normal file
24
docker/Dockerfile.ubuntu_xenial
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Build time
|
||||||
|
FROM ubuntu:xenial as build
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get -y install wget
|
||||||
|
RUN mkdir -p /tmp/cmake
|
||||||
|
WORKDIR /tmp/cmake
|
||||||
|
RUN wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
RUN tar zxf cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
|
||||||
|
RUN apt-get -y install g++
|
||||||
|
RUN apt-get -y install libssl-dev
|
||||||
|
RUN apt-get -y install libz-dev
|
||||||
|
RUN apt-get -y install make
|
||||||
|
RUN apt-get -y install python
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-Linux-x86_64/bin
|
||||||
|
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
||||||
|
|
||||||
|
# RUN ["make"]
|
||||||
|
RUN ["make", "test"]
|
@ -17,28 +17,26 @@ namespace ix
|
|||||||
std::atomic<uint64_t> DNSLookup::_nextId(0);
|
std::atomic<uint64_t> DNSLookup::_nextId(0);
|
||||||
std::set<uint64_t> DNSLookup::_activeJobs;
|
std::set<uint64_t> DNSLookup::_activeJobs;
|
||||||
std::mutex DNSLookup::_activeJobsMutex;
|
std::mutex DNSLookup::_activeJobsMutex;
|
||||||
std::mutex DNSLookup::_resMutex;
|
|
||||||
|
|
||||||
DNSLookup::DNSLookup(const std::string& hostname, int port, int64_t wait) :
|
DNSLookup::DNSLookup(const std::string& hostname, int port, int64_t wait) :
|
||||||
_hostname(hostname),
|
|
||||||
_port(port),
|
_port(port),
|
||||||
_wait(wait),
|
_wait(wait),
|
||||||
_res(nullptr),
|
_res(nullptr),
|
||||||
_done(false),
|
_done(false),
|
||||||
_id(_nextId++)
|
_id(_nextId++)
|
||||||
{
|
{
|
||||||
;
|
setHostname(hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
DNSLookup::~DNSLookup()
|
DNSLookup::~DNSLookup()
|
||||||
{
|
{
|
||||||
// Remove this job from the active jobs list
|
// Remove this job from the active jobs list
|
||||||
std::unique_lock<std::mutex> lock(_activeJobsMutex);
|
std::lock_guard<std::mutex> lock(_activeJobsMutex);
|
||||||
_activeJobs.erase(_id);
|
_activeJobs.erase(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we want hostname to be copied, not passed as a const reference
|
// we want hostname to be copied, not passed as a const reference
|
||||||
struct addrinfo* DNSLookup::getAddrInfo(std::string hostname,
|
struct addrinfo* DNSLookup::getAddrInfo(const std::string& hostname,
|
||||||
int port,
|
int port,
|
||||||
std::string& errMsg)
|
std::string& errMsg)
|
||||||
{
|
{
|
||||||
@ -81,7 +79,7 @@ namespace ix
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAddrInfo(_hostname, _port, errMsg);
|
return getAddrInfo(getHostname(), _port, errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct addrinfo* DNSLookup::resolveAsync(std::string& errMsg,
|
struct addrinfo* DNSLookup::resolveAsync(std::string& errMsg,
|
||||||
@ -99,7 +97,7 @@ namespace ix
|
|||||||
|
|
||||||
// Record job in the active Job set
|
// Record job in the active Job set
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(_activeJobsMutex);
|
std::lock_guard<std::mutex> lock(_activeJobsMutex);
|
||||||
_activeJobs.insert(_id);
|
_activeJobs.insert(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +105,7 @@ namespace ix
|
|||||||
// Good resource on thread forced termination
|
// Good resource on thread forced termination
|
||||||
// https://www.bo-yang.net/2017/11/19/cpp-kill-detached-thread
|
// https://www.bo-yang.net/2017/11/19/cpp-kill-detached-thread
|
||||||
//
|
//
|
||||||
_thread = std::thread(&DNSLookup::run, this, _id, _hostname, _port);
|
_thread = std::thread(&DNSLookup::run, this, _id, getHostname(), _port);
|
||||||
_thread.detach();
|
_thread.detach();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(_conditionVariableMutex);
|
std::unique_lock<std::mutex> lock(_conditionVariableMutex);
|
||||||
@ -137,13 +135,8 @@ namespace ix
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_errMsg.empty())
|
errMsg = getErrMsg();
|
||||||
{
|
return getRes();
|
||||||
errMsg = _errMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_lock<std::mutex> rlock(_resMutex);
|
|
||||||
return _res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNSLookup::run(uint64_t id, const std::string& hostname, int port) // thread runner
|
void DNSLookup::run(uint64_t id, const std::string& hostname, int port) // thread runner
|
||||||
@ -155,21 +148,55 @@ namespace ix
|
|||||||
struct addrinfo* res = getAddrInfo(hostname, port, errMsg);
|
struct addrinfo* res = getAddrInfo(hostname, port, errMsg);
|
||||||
|
|
||||||
// if this isn't an active job, and the control thread is gone
|
// if this isn't an active job, and the control thread is gone
|
||||||
// there is not thing to do, and we don't want to touch the defunct
|
// there is nothing to do, and we don't want to touch the defunct
|
||||||
// object data structure such as _errMsg or _condition
|
// object data structure such as _errMsg or _condition
|
||||||
std::unique_lock<std::mutex> lock(_activeJobsMutex);
|
std::lock_guard<std::mutex> lock(_activeJobsMutex);
|
||||||
if (_activeJobs.count(id) == 0)
|
if (_activeJobs.count(id) == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy result into the member variables
|
// Copy result into the member variables
|
||||||
{
|
setRes(res);
|
||||||
std::unique_lock<std::mutex> rlock(_resMutex);
|
setErrMsg(errMsg);
|
||||||
_res = res;
|
|
||||||
}
|
|
||||||
_errMsg = errMsg;
|
|
||||||
_condition.notify_one();
|
_condition.notify_one();
|
||||||
_done = true;
|
_done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DNSLookup::setHostname(const std::string& hostname)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_hostnameMutex);
|
||||||
|
_hostname = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& DNSLookup::getHostname()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_hostnameMutex);
|
||||||
|
return _hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DNSLookup::setErrMsg(const std::string& errMsg)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_errMsgMutex);
|
||||||
|
_errMsg = errMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& DNSLookup::getErrMsg()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_errMsgMutex);
|
||||||
|
return _errMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DNSLookup::setRes(struct addrinfo* addr)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_resMutex);
|
||||||
|
_res = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct addrinfo* DNSLookup::getRes()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_resMutex);
|
||||||
|
return _res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,18 +39,32 @@ namespace ix
|
|||||||
struct addrinfo* resolveBlocking(std::string& errMsg,
|
struct addrinfo* resolveBlocking(std::string& errMsg,
|
||||||
const CancellationRequest& isCancellationRequested);
|
const CancellationRequest& isCancellationRequested);
|
||||||
|
|
||||||
static struct addrinfo* getAddrInfo(std::string hostname,
|
static struct addrinfo* getAddrInfo(const std::string& hostname,
|
||||||
int port,
|
int port,
|
||||||
std::string& errMsg);
|
std::string& errMsg);
|
||||||
|
|
||||||
void run(uint64_t id, const std::string& hostname, int port); // thread runner
|
void run(uint64_t id, const std::string& hostname, int port); // thread runner
|
||||||
|
|
||||||
|
void setHostname(const std::string& hostname);
|
||||||
|
const std::string& getHostname();
|
||||||
|
|
||||||
|
void setErrMsg(const std::string& errMsg);
|
||||||
|
const std::string& getErrMsg();
|
||||||
|
|
||||||
|
void setRes(struct addrinfo* addr);
|
||||||
|
struct addrinfo* getRes();
|
||||||
|
|
||||||
std::string _hostname;
|
std::string _hostname;
|
||||||
|
std::mutex _hostnameMutex;
|
||||||
int _port;
|
int _port;
|
||||||
|
|
||||||
int64_t _wait;
|
int64_t _wait;
|
||||||
std::string _errMsg;
|
|
||||||
struct addrinfo* _res;
|
struct addrinfo* _res;
|
||||||
static std::mutex _resMutex;
|
std::mutex _resMutex;
|
||||||
|
|
||||||
|
std::string _errMsg;
|
||||||
|
std::mutex _errMsgMutex;
|
||||||
|
|
||||||
std::atomic<bool> _done;
|
std::atomic<bool> _done;
|
||||||
std::thread _thread;
|
std::thread _thread;
|
||||||
|
@ -38,6 +38,7 @@ namespace ix
|
|||||||
WebSocket::WebSocket() :
|
WebSocket::WebSocket() :
|
||||||
_onMessageCallback(OnMessageCallback()),
|
_onMessageCallback(OnMessageCallback()),
|
||||||
_stop(false),
|
_stop(false),
|
||||||
|
_backgroundThreadRunning(false),
|
||||||
_automaticReconnection(true),
|
_automaticReconnection(true),
|
||||||
_handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs),
|
_handshakeTimeoutSecs(kDefaultHandShakeTimeoutSecs),
|
||||||
_enablePong(kDefaultEnablePong),
|
_enablePong(kDefaultEnablePong),
|
||||||
@ -135,6 +136,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
if (_thread.joinable()) return; // we've already been started
|
if (_thread.joinable()) return; // we've already been started
|
||||||
|
|
||||||
|
_backgroundThreadRunning = true;
|
||||||
_thread = std::thread(&WebSocket::run, this);
|
_thread = std::thread(&WebSocket::run, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +157,7 @@ namespace ix
|
|||||||
|
|
||||||
_stop = true;
|
_stop = true;
|
||||||
_thread.join();
|
_thread.join();
|
||||||
|
_backgroundThreadRunning = false;
|
||||||
_stop = false;
|
_stop = false;
|
||||||
|
|
||||||
_automaticReconnection = automaticReconnection;
|
_automaticReconnection = automaticReconnection;
|
||||||
|
@ -154,6 +154,7 @@ namespace ix
|
|||||||
static OnTrafficTrackerCallback _onTrafficTrackerCallback;
|
static OnTrafficTrackerCallback _onTrafficTrackerCallback;
|
||||||
|
|
||||||
std::atomic<bool> _stop;
|
std::atomic<bool> _stop;
|
||||||
|
std::atomic<bool> _backgroundThreadRunning;
|
||||||
std::atomic<bool> _automaticReconnection;
|
std::atomic<bool> _automaticReconnection;
|
||||||
std::thread _thread;
|
std::thread _thread;
|
||||||
std::mutex _writeMutex;
|
std::mutex _writeMutex;
|
||||||
|
@ -119,7 +119,7 @@ namespace ix
|
|||||||
|
|
||||||
// Tells whether we should mask the data we send.
|
// Tells whether we should mask the data we send.
|
||||||
// client should mask but server should not
|
// client should mask but server should not
|
||||||
bool _useMask;
|
std::atomic<bool> _useMask;
|
||||||
|
|
||||||
// Buffer for reading from our socket. That buffer is never resized.
|
// Buffer for reading from our socket. That buffer is never resized.
|
||||||
std::vector<uint8_t> _readbuf;
|
std::vector<uint8_t> _readbuf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user