mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-20 01:40:29 +00:00
nice rendering of IPs
This commit is contained in:
@ -92,21 +92,20 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
hubGroup->onConnection([&](uWS::WebSocket<uWS::SERVER> *ws, uWS::HttpRequest req) {
|
hubGroup->onConnection([&](uWS::WebSocket<uWS::SERVER> *ws, uWS::HttpRequest req) {
|
||||||
std::string addr = ws->getAddress().address;
|
|
||||||
uint64_t connId = nextConnectionId++;
|
uint64_t connId = nextConnectionId++;
|
||||||
|
|
||||||
|
Connection *c = new Connection(ws, connId);
|
||||||
|
c->ipAddr = ws->getAddressBytes();
|
||||||
|
ws->setUserData((void*)c);
|
||||||
|
connIdToConnection.emplace(connId, c);
|
||||||
|
|
||||||
bool compEnabled, compSlidingWindow;
|
bool compEnabled, compSlidingWindow;
|
||||||
ws->getCompressionState(compEnabled, compSlidingWindow);
|
ws->getCompressionState(compEnabled, compSlidingWindow);
|
||||||
LI << "[" << connId << "] Connect from " << addr
|
LI << "[" << connId << "] Connect from " << renderIP(c->ipAddr)
|
||||||
<< " compression=" << (compEnabled ? 'Y' : 'N')
|
<< " compression=" << (compEnabled ? 'Y' : 'N')
|
||||||
<< " sliding=" << (compSlidingWindow ? 'Y' : 'N')
|
<< " sliding=" << (compSlidingWindow ? 'Y' : 'N')
|
||||||
;
|
;
|
||||||
|
|
||||||
Connection *c = new Connection(ws, connId);
|
|
||||||
c->ipAddr = addr;
|
|
||||||
ws->setUserData((void*)c);
|
|
||||||
connIdToConnection.emplace(connId, c);
|
|
||||||
|
|
||||||
if (cfg().relay__enableTcpKeepalive) {
|
if (cfg().relay__enableTcpKeepalive) {
|
||||||
int optval = 1;
|
int optval = 1;
|
||||||
if (setsockopt(ws->getFd(), SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval))) {
|
if (setsockopt(ws->getFd(), SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval))) {
|
||||||
@ -122,7 +121,7 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
|
|||||||
auto upComp = renderPercent(1.0 - (double)c->stats.bytesUpCompressed / c->stats.bytesUp);
|
auto upComp = renderPercent(1.0 - (double)c->stats.bytesUpCompressed / c->stats.bytesUp);
|
||||||
auto downComp = renderPercent(1.0 - (double)c->stats.bytesDownCompressed / c->stats.bytesDown);
|
auto downComp = renderPercent(1.0 - (double)c->stats.bytesDownCompressed / c->stats.bytesDown);
|
||||||
|
|
||||||
LI << "[" << connId << "] Disconnect from " << c->ipAddr
|
LI << "[" << connId << "] Disconnect from " << renderIP(c->ipAddr)
|
||||||
<< " UP: " << renderSize(c->stats.bytesUp) << " (" << upComp << " compressed)"
|
<< " UP: " << renderSize(c->stats.bytesUp) << " (" << upComp << " compressed)"
|
||||||
<< " DN: " << renderSize(c->stats.bytesDown) << " (" << downComp << " compressed)"
|
<< " DN: " << renderSize(c->stats.bytesDown) << " (" << downComp << " compressed)"
|
||||||
;
|
;
|
||||||
@ -139,7 +138,7 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
|
|||||||
c.stats.bytesDown += length;
|
c.stats.bytesDown += length;
|
||||||
c.stats.bytesDownCompressed += compressedSize;
|
c.stats.bytesDownCompressed += compressedSize;
|
||||||
|
|
||||||
tpIngester.dispatch(c.connId, MsgIngester{MsgIngester::ClientMessage{c.connId, std::string(message, length), ws->getAddressBytes()}});
|
tpIngester.dispatch(c.connId, MsgIngester{MsgIngester::ClientMessage{c.connId, c.ipAddr, std::string(message, length)}});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,3 +10,6 @@ using namespace phmap;
|
|||||||
|
|
||||||
quadrable::Quadrable getQdbInstance(lmdb::txn &txn);
|
quadrable::Quadrable getQdbInstance(lmdb::txn &txn);
|
||||||
quadrable::Quadrable getQdbInstance();
|
quadrable::Quadrable getQdbInstance();
|
||||||
|
|
||||||
|
|
||||||
|
std::string renderIP(std::string_view ipBytes);
|
||||||
|
17
src/misc.cpp
Normal file
17
src/misc.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include "golpe.h"
|
||||||
|
|
||||||
|
std::string renderIP(std::string_view ipBytes) {
|
||||||
|
char buf[128];
|
||||||
|
|
||||||
|
if (ipBytes.size() == 4) {
|
||||||
|
inet_ntop(AF_INET, ipBytes.data(), buf, sizeof(buf));
|
||||||
|
} else if (ipBytes.size() == 16) {
|
||||||
|
inet_ntop(AF_INET6, ipBytes.data(), buf, sizeof(buf));
|
||||||
|
} else {
|
||||||
|
throw herr("invalid size of ipBytes, unable to render IP");
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(buf);
|
||||||
|
}
|
Reference in New Issue
Block a user