Compare commits
2 Commits
v8.0.0
...
feature/ss
Author | SHA1 | Date | |
---|---|---|---|
22118d68d2 | |||
4c15964d43 |
@ -1,6 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All changes to this project will be documented in this file.
|
All changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [7.9.6] - 2020-01-22
|
||||||
|
|
||||||
|
(ws) add a dnslookup sub-command, to get the ip address of a remote host
|
||||||
|
|
||||||
## [7.9.5] - 2020-01-14
|
## [7.9.5] - 2020-01-14
|
||||||
|
|
||||||
(windows) fix #144, get rid of stubbed/un-implemented windows schannel ssl backend
|
(windows) fix #144, get rid of stubbed/un-implemented windows schannel ssl backend
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sstream>
|
||||||
#define socketerrno errno
|
#define socketerrno errno
|
||||||
|
|
||||||
#include <Security/SecureTransport.h>
|
#include <Security/SecureTransport.h>
|
||||||
@ -31,12 +32,17 @@ namespace ix
|
|||||||
, _sslContext(nullptr)
|
, _sslContext(nullptr)
|
||||||
, _tlsOptions(tlsOptions)
|
, _tlsOptions(tlsOptions)
|
||||||
{
|
{
|
||||||
;
|
_sslContext = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType);
|
||||||
|
SSLSetIOFuncs(
|
||||||
|
_sslContext, SocketAppleSSL::readFromSocket, SocketAppleSSL::writeToSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketAppleSSL::~SocketAppleSSL()
|
SocketAppleSSL::~SocketAppleSSL()
|
||||||
{
|
{
|
||||||
SocketAppleSSL::close();
|
CFRelease(_sslContext);
|
||||||
|
_sslContext = nullptr;
|
||||||
|
|
||||||
|
Socket::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SocketAppleSSL::getSSLErrorDescription(OSStatus status)
|
std::string SocketAppleSSL::getSSLErrorDescription(OSStatus status)
|
||||||
@ -177,14 +183,16 @@ namespace ix
|
|||||||
_sockfd = SocketConnect::connect(host, port, errMsg, isCancellationRequested);
|
_sockfd = SocketConnect::connect(host, port, errMsg, isCancellationRequested);
|
||||||
if (_sockfd == -1) return false;
|
if (_sockfd == -1) return false;
|
||||||
|
|
||||||
_sslContext = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType);
|
|
||||||
|
|
||||||
SSLSetIOFuncs(
|
|
||||||
_sslContext, SocketAppleSSL::readFromSocket, SocketAppleSSL::writeToSocket);
|
|
||||||
SSLSetConnection(_sslContext, (SSLConnectionRef)(long) _sockfd);
|
SSLSetConnection(_sslContext, (SSLConnectionRef)(long) _sockfd);
|
||||||
SSLSetProtocolVersionMin(_sslContext, kTLSProtocol12);
|
SSLSetProtocolVersionMin(_sslContext, kTLSProtocol12);
|
||||||
SSLSetPeerDomainName(_sslContext, host.c_str(), host.size());
|
SSLSetPeerDomainName(_sslContext, host.c_str(), host.size());
|
||||||
|
|
||||||
|
// Record a peer id, which speed up SSL connection when reconnecting to the same host
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << host << ":" << port;
|
||||||
|
_peerId = ss.str();
|
||||||
|
SSLSetPeerID(_sslContext, (void*) _peerId.c_str(), _peerId.size());
|
||||||
|
|
||||||
if (_tlsOptions.isPeerVerifyDisabled())
|
if (_tlsOptions.isPeerVerifyDisabled())
|
||||||
{
|
{
|
||||||
Boolean option(1);
|
Boolean option(1);
|
||||||
@ -227,12 +235,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_mutex);
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
|
||||||
if (_sslContext == nullptr) return;
|
|
||||||
|
|
||||||
SSLClose(_sslContext);
|
SSLClose(_sslContext);
|
||||||
CFRelease(_sslContext);
|
|
||||||
_sslContext = nullptr;
|
|
||||||
|
|
||||||
Socket::close();
|
Socket::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@ namespace ix
|
|||||||
mutable std::mutex _mutex; // AppleSSL routines are not thread-safe
|
mutable std::mutex _mutex; // AppleSSL routines are not thread-safe
|
||||||
|
|
||||||
SocketTLSOptions _tlsOptions;
|
SocketTLSOptions _tlsOptions;
|
||||||
|
|
||||||
|
std::string _peerId;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
@ -19,10 +19,12 @@
|
|||||||
#include <linux/tcp.h>
|
#include <linux/tcp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// This function can be cancelled every 50 ms
|
// This function can be cancelled every 10 ms
|
||||||
// This is important so that we don't block the main UI thread when shutting down a
|
// This is important so that we don't block the main UI thread when shutting down a
|
||||||
// connection which is already trying to reconnect, and can be blocked waiting for
|
// connection which is already trying to reconnect, and can be blocked waiting for
|
||||||
// ::connect to respond.
|
// ::connect to respond.
|
||||||
@ -44,8 +46,15 @@ namespace ix
|
|||||||
// block us for too long
|
// block us for too long
|
||||||
SocketConnect::configure(fd);
|
SocketConnect::configure(fd);
|
||||||
|
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
int res = ::connect(fd, address->ai_addr, address->ai_addrlen);
|
int res = ::connect(fd, address->ai_addr, address->ai_addrlen);
|
||||||
|
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
|
||||||
|
auto ms = milliseconds.count();
|
||||||
|
std::cout << "tcp connection completed in " << ms << "ms" << std::endl;
|
||||||
|
|
||||||
if (res == -1 && !Socket::isWaitNeeded())
|
if (res == -1 && !Socket::isWaitNeeded())
|
||||||
{
|
{
|
||||||
errMsg = strerror(Socket::getErrno());
|
errMsg = strerror(Socket::getErrno());
|
||||||
@ -98,11 +107,19 @@ namespace ix
|
|||||||
std::string& errMsg,
|
std::string& errMsg,
|
||||||
const CancellationRequest& isCancellationRequested)
|
const CancellationRequest& isCancellationRequested)
|
||||||
{
|
{
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
//
|
//
|
||||||
// First do DNS resolution
|
// First do DNS resolution
|
||||||
//
|
//
|
||||||
auto dnsLookup = std::make_shared<DNSLookup>(hostname, port);
|
auto dnsLookup = std::make_shared<DNSLookup>(hostname, port);
|
||||||
struct addrinfo* res = dnsLookup->resolve(errMsg, isCancellationRequested);
|
struct addrinfo* res = dnsLookup->resolve(errMsg, isCancellationRequested);
|
||||||
|
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
|
||||||
|
auto ms = milliseconds.count();
|
||||||
|
std::cout << "dns resolution completed in " << ms << "ms" << std::endl;
|
||||||
|
|
||||||
if (res == nullptr)
|
if (res == nullptr)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
{
|
{
|
||||||
@ -97,8 +100,16 @@ namespace ix
|
|||||||
auto isCancellationRequested =
|
auto isCancellationRequested =
|
||||||
makeCancellationRequestWithTimeout(timeoutSecs, _requestInitCancellation);
|
makeCancellationRequestWithTimeout(timeoutSecs, _requestInitCancellation);
|
||||||
|
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
std::string errMsg;
|
std::string errMsg;
|
||||||
bool success = _socket->connect(host, port, errMsg, isCancellationRequested);
|
bool success = _socket->connect(host, port, errMsg, isCancellationRequested);
|
||||||
|
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
|
||||||
|
auto ms = milliseconds.count();
|
||||||
|
std::cout << "connection completed in " << ms << "ms" << std::endl;
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -151,7 +151,18 @@ namespace ix
|
|||||||
|
|
||||||
std::string errorMsg;
|
std::string errorMsg;
|
||||||
bool tls = protocol == "wss";
|
bool tls = protocol == "wss";
|
||||||
_socket = createSocket(tls, -1, errorMsg, _socketTLSOptions);
|
|
||||||
|
if (_host == host)
|
||||||
|
{
|
||||||
|
_socket->close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_socket = createSocket(tls, -1, errorMsg, _socketTLSOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record the host for later
|
||||||
|
_host = host;
|
||||||
|
|
||||||
if (!_socket)
|
if (!_socket)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +107,7 @@ namespace ix
|
|||||||
size_t bufferedAmount() const;
|
size_t bufferedAmount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _url;
|
std::string _host;
|
||||||
|
|
||||||
struct wsheader_type
|
struct wsheader_type
|
||||||
{
|
{
|
||||||
|
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define IX_WEBSOCKET_VERSION "7.9.5"
|
#define IX_WEBSOCKET_VERSION "7.9.6"
|
||||||
|
@ -65,6 +65,7 @@ add_executable(ws
|
|||||||
ws_autobahn.cpp
|
ws_autobahn.cpp
|
||||||
ws_proxy_server.cpp
|
ws_proxy_server.cpp
|
||||||
ws_sentry_minidump_upload.cpp
|
ws_sentry_minidump_upload.cpp
|
||||||
|
ws_dns_lookup.cpp
|
||||||
ws.cpp)
|
ws.cpp)
|
||||||
|
|
||||||
target_link_libraries(ws ixsnake)
|
target_link_libraries(ws ixsnake)
|
||||||
|
@ -338,6 +338,9 @@ int main(int argc, char** argv)
|
|||||||
minidumpApp->add_option("--key", key, "Sentry Key")->required();
|
minidumpApp->add_option("--key", key, "Sentry Key")->required();
|
||||||
minidumpApp->add_flag("-v", verbose, "Verbose");
|
minidumpApp->add_flag("-v", verbose, "Verbose");
|
||||||
|
|
||||||
|
CLI::App* dnsLookupApp = app.add_subcommand("dnslookup", "DNS lookup");
|
||||||
|
dnsLookupApp->add_option("host", hostname, "Hostname")->required();
|
||||||
|
|
||||||
CLI11_PARSE(app, argc, argv);
|
CLI11_PARSE(app, argc, argv);
|
||||||
|
|
||||||
// pid file handling
|
// pid file handling
|
||||||
@ -509,6 +512,10 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
ret = ix::ws_sentry_minidump_upload(metadata, minidump, project, key, verbose);
|
ret = ix::ws_sentry_minidump_upload(metadata, minidump, project, key, verbose);
|
||||||
}
|
}
|
||||||
|
else if (app.got_subcommand("dnslookup"))
|
||||||
|
{
|
||||||
|
ret = ix::ws_dns_lookup(hostname);
|
||||||
|
}
|
||||||
else if (version)
|
else if (version)
|
||||||
{
|
{
|
||||||
spdlog::info("ws {}", ix::userAgent());
|
spdlog::info("ws {}", ix::userAgent());
|
||||||
|
2
ws/ws.h
2
ws/ws.h
@ -163,4 +163,6 @@ namespace ix
|
|||||||
const std::string& project,
|
const std::string& project,
|
||||||
const std::string& key,
|
const std::string& key,
|
||||||
bool verbose);
|
bool verbose);
|
||||||
|
|
||||||
|
int ws_dns_lookup(const std::string& hostname);
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
34
ws/ws_dns_lookup.cpp
Normal file
34
ws/ws_dns_lookup.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* ws_dns_lookup.cpp
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
|
#include <ixwebsocket/IXDNSLookup.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace ix
|
||||||
|
{
|
||||||
|
int ws_dns_lookup(const std::string& hostname)
|
||||||
|
{
|
||||||
|
auto dnsLookup = std::make_shared<DNSLookup>(hostname, 80);
|
||||||
|
|
||||||
|
std::string errMsg;
|
||||||
|
struct addrinfo* res;
|
||||||
|
|
||||||
|
res = dnsLookup->resolve(errMsg, [] { return false; });
|
||||||
|
|
||||||
|
auto addr = res->ai_addr;
|
||||||
|
|
||||||
|
char str[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET, &addr, str, INET_ADDRSTRLEN);
|
||||||
|
|
||||||
|
spdlog::info("host: {} ip: {}", hostname, str);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace ix
|
Reference in New Issue
Block a user