Browse Source

Add bytessent, bytesrecv and syncnode to getpeerinfo

miguelfreitas
Pieter Wuille 12 years ago
parent
commit
86648a8d16
  1. 5
      src/net.cpp
  2. 7
      src/net.h
  3. 4
      src/rpcnet.cpp

5
src/net.cpp

@ -619,6 +619,9 @@ void CNode::copyStats(CNodeStats &stats)
X(nReleaseTime); X(nReleaseTime);
X(nStartingHeight); X(nStartingHeight);
X(nMisbehavior); X(nMisbehavior);
X(nSendBytes);
X(nRecvBytes);
stats.fSyncNode = (this == pnodeSync);
} }
#undef X #undef X
@ -713,6 +716,7 @@ void SocketSendData(CNode *pnode)
int nBytes = send(pnode->hSocket, &data[pnode->nSendOffset], data.size() - pnode->nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT); int nBytes = send(pnode->hSocket, &data[pnode->nSendOffset], data.size() - pnode->nSendOffset, MSG_NOSIGNAL | MSG_DONTWAIT);
if (nBytes > 0) { if (nBytes > 0) {
pnode->nLastSend = GetTime(); pnode->nLastSend = GetTime();
pnode->nSendBytes += nBytes;
pnode->nSendOffset += nBytes; pnode->nSendOffset += nBytes;
if (pnode->nSendOffset == data.size()) { if (pnode->nSendOffset == data.size()) {
pnode->nSendOffset = 0; pnode->nSendOffset = 0;
@ -976,6 +980,7 @@ void ThreadSocketHandler()
if (!pnode->ReceiveMsgBytes(pchBuf, nBytes)) if (!pnode->ReceiveMsgBytes(pchBuf, nBytes))
pnode->CloseSocketDisconnect(); pnode->CloseSocketDisconnect();
pnode->nLastRecv = GetTime(); pnode->nLastRecv = GetTime();
pnode->nRecvBytes += nBytes;
} }
else if (nBytes == 0) else if (nBytes == 0)
{ {

7
src/net.h

@ -102,6 +102,9 @@ public:
int64 nReleaseTime; int64 nReleaseTime;
int nStartingHeight; int nStartingHeight;
int nMisbehavior; int nMisbehavior;
uint64 nSendBytes;
uint64 nRecvBytes;
bool fSyncNode;
}; };
@ -156,12 +159,14 @@ public:
CDataStream ssSend; CDataStream ssSend;
size_t nSendSize; // total size of all vSendMsg entries size_t nSendSize; // total size of all vSendMsg entries
size_t nSendOffset; // offset inside the first vSendMsg already sent size_t nSendOffset; // offset inside the first vSendMsg already sent
uint64 nSendBytes;
std::deque<CSerializeData> vSendMsg; std::deque<CSerializeData> vSendMsg;
CCriticalSection cs_vSend; CCriticalSection cs_vSend;
std::deque<CInv> vRecvGetData; std::deque<CInv> vRecvGetData;
std::deque<CNetMessage> vRecvMsg; std::deque<CNetMessage> vRecvMsg;
CCriticalSection cs_vRecvMsg; CCriticalSection cs_vRecvMsg;
uint64 nRecvBytes;
int nRecvVersion; int nRecvVersion;
int64 nLastSend; int64 nLastSend;
@ -223,6 +228,8 @@ public:
nRecvVersion = MIN_PROTO_VERSION; nRecvVersion = MIN_PROTO_VERSION;
nLastSend = 0; nLastSend = 0;
nLastRecv = 0; nLastRecv = 0;
nSendBytes = 0;
nRecvBytes = 0;
nLastSendEmpty = GetTime(); nLastSendEmpty = GetTime();
nTimeConnected = GetTime(); nTimeConnected = GetTime();
addr = addrIn; addr = addrIn;

4
src/rpcnet.cpp

@ -51,6 +51,8 @@ Value getpeerinfo(const Array& params, bool fHelp)
obj.push_back(Pair("services", strprintf("%08"PRI64x, stats.nServices))); obj.push_back(Pair("services", strprintf("%08"PRI64x, stats.nServices)));
obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend)); obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend));
obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv)); obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv));
obj.push_back(Pair("bytessent", (boost::int64_t)stats.nSendBytes));
obj.push_back(Pair("bytesrecv", (boost::int64_t)stats.nRecvBytes));
obj.push_back(Pair("conntime", (boost::int64_t)stats.nTimeConnected)); obj.push_back(Pair("conntime", (boost::int64_t)stats.nTimeConnected));
obj.push_back(Pair("version", stats.nVersion)); obj.push_back(Pair("version", stats.nVersion));
obj.push_back(Pair("subver", stats.strSubVer)); obj.push_back(Pair("subver", stats.strSubVer));
@ -58,6 +60,8 @@ Value getpeerinfo(const Array& params, bool fHelp)
obj.push_back(Pair("releasetime", (boost::int64_t)stats.nReleaseTime)); obj.push_back(Pair("releasetime", (boost::int64_t)stats.nReleaseTime));
obj.push_back(Pair("startingheight", stats.nStartingHeight)); obj.push_back(Pair("startingheight", stats.nStartingHeight));
obj.push_back(Pair("banscore", stats.nMisbehavior)); obj.push_back(Pair("banscore", stats.nMisbehavior));
if (stats.fSyncNode)
obj.push_back(Pair("syncnode", true));
ret.push_back(obj); ret.push_back(obj);
} }

Loading…
Cancel
Save