Added Send/Recv accounting to Dht & UdpSocket in general.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4817 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-01-19 16:18:59 +00:00
parent 80a20b41a3
commit 7dc0cd6b0f
4 changed files with 73 additions and 1 deletions

View File

@ -72,10 +72,11 @@ UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, st
usedVersion = ""; /* blank it */
#endif
clearDataTransferred();
/* setup nodeManager */
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
mBitDhtManager = new bdNodeManager(id, usedVersion, bootstrapfile, fns);
}
@ -271,6 +272,7 @@ int UdpBitDht::recvPkt(void *data, int size, struct sockaddr_in &from)
if (mBitDhtManager->isBitDhtPacket((char *) data, size, from))
{
mReadBytes += size;
mBitDhtManager->incomingMsg(&from, (char *) data, size);
return 1;
}
@ -284,6 +286,29 @@ int UdpBitDht::status(std::ostream &out)
return 1;
}
void UdpBitDht::clearDataTransferred()
{
/* pass onto bitdht */
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
mReadBytes = 0;
mWriteBytes = 0;
}
void UdpBitDht::getDataTransferred(uint32_t &read, uint32_t &write)
{
{
/* pass onto bitdht */
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
read = mReadBytes;
write = mWriteBytes;
}
clearDataTransferred();
}
/*** Overloaded from iThread ***/
#define MAX_MSG_PER_TICK 100
#define TICK_PAUSE_USEC 20000 /* 20ms secs .. max messages = 50 x 100 = 5000 */
@ -323,6 +348,7 @@ int UdpBitDht::tick()
std::cerr << std::endl;
#endif
mWriteBytes += size;
sendPkt(data, size, toAddr, BITDHT_TTL);
// iterate

View File

@ -95,6 +95,8 @@ virtual uint32_t statsNetworkSize();
virtual uint32_t statsBDVersionSize();
virtual uint32_t setDhtMode(uint32_t dhtFlags);
void getDataTransferred(uint32_t &read, uint32_t &write);
/******************* Internals *************************/
/***** Iteration / Loop Management *****/
@ -111,9 +113,17 @@ virtual void run();
private:
void clearDataTransferred();
bdMutex dhtMtx; /* for all class data (below) */
bdNodeManager *mBitDhtManager;
bdDhtFunctions *mFns;
uint32_t mReadBytes;
uint32_t mWriteBytes;
};

View File

@ -394,6 +394,7 @@ int UdpLayer::openSocket()
std::cerr << "Setting TTL to " << UDP_DEF_TTL << std::endl;
#endif
setTTL(UDP_DEF_TTL);
clearDataTransferred(); // clear statistics.
// start up our thread.
{
@ -464,6 +465,28 @@ int UdpLayer::tick()
return 1;
}
void UdpLayer::getDataTransferred(uint32_t &read, uint32_t &write)
{
sockMtx.lock(); /********** LOCK MUTEX *********/
read = readBytes;
write = writeBytes;
sockMtx.unlock(); /******** UNLOCK MUTEX *********/
clearDataTransferred();
}
void UdpLayer::clearDataTransferred()
{
sockMtx.lock(); /********** LOCK MUTEX *********/
readBytes = 0;
writeBytes = 0;
sockMtx.unlock(); /******** UNLOCK MUTEX *********/
}
/******************* Internals *************************************/
int UdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_in &from)
@ -477,6 +500,11 @@ int UdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_in &from)
insize = bdnet_recvfrom(sockfd,data,insize,0,
(struct sockaddr*)&fromaddr,&fromsize);
if (0 < insize)
{
readBytes += insize;
}
sockMtx.unlock(); /******** UNLOCK MUTEX *********/
if (0 < insize)
@ -508,6 +536,8 @@ int UdpLayer::sendUdpPacket(const void *data, int size, const struct sockaddr_in
(struct sockaddr *) &(toaddr),
sizeof(toaddr));
writeBytes += size;
sockMtx.unlock(); /******** UNLOCK MUTEX *********/
return 1;
}

View File

@ -72,6 +72,7 @@ class UdpLayer: public bdThread
virtual ~UdpLayer() { return; }
int reset(struct sockaddr_in &local); /* calls join, close, openSocket */
void getDataTransferred(uint32_t &read, uint32_t &write);
int status(std::ostream &out);
@ -106,10 +107,15 @@ virtual int sendUdpPacket(const void *data, int size, const struct sockaddr_in &
/* low level */
private:
void clearDataTransferred();
UdpReceiver *recv;
struct sockaddr_in laddr; /* local addr */
uint32_t readBytes;
uint32_t writeBytes;
int errorState;
int sockfd;
int ttl;