Attempt at fixing the Disconnection issue.

* Added DataRate accounting to Relay and Dht.
 * Rates are exposed through rsDht.h interface.
 * Added LastIncomingTS() to pqistreamer.
 * Turned HeartBeat reset() into a warning.
 * Added NoPacket in 60 sec reset().
 * Minor typos/errors corrected.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4818 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-01-19 16:23:57 +00:00
parent 7dc0cd6b0f
commit 4aec00a0c2
12 changed files with 212 additions and 9 deletions

View file

@ -67,6 +67,8 @@ UdpRelayReceiver::UdpRelayReceiver(UdpPublisher *pub)
mTmpSendPkt = malloc(MAX_RELAY_UDP_PACKET_SIZE);
mTmpSendSize = MAX_RELAY_UDP_PACKET_SIZE;
clearDataTransferred();
return;
}
@ -672,6 +674,40 @@ int UdpRelayReceiver::UdpPeersStatus(std::ostream &out)
}
void UdpRelayReceiver::clearDataTransferred()
{
{
RsStackMutex stack(relayMtx); /********** LOCK MUTEX *********/
mWriteBytes = 0;
mRelayBytes = 0;
}
{
RsStackMutex stack(udppeerMtx); /********** LOCK MUTEX *********/
mReadBytes = 0;
}
}
void UdpRelayReceiver::getDataTransferred(uint32_t &read, uint32_t &write, uint32_t &relay)
{
{
RsStackMutex stack(relayMtx); /********** LOCK MUTEX *********/
write = mWriteBytes;
relay = mRelayBytes;
}
{
RsStackMutex stack(udppeerMtx); /********** LOCK MUTEX *********/
read = mReadBytes;
}
clearDataTransferred();
}
#define UDP_RELAY_HEADER_SIZE 16
@ -723,6 +759,8 @@ int UdpRelayReceiver::recvPkt(void *data, int size, struct sockaddr_in &from)
/* do accounting */
rit->second.mLastTS = time(NULL);
rit->second.mDataSize += size;
mRelayBytes += size;
mPublisher->sendPkt(data, size, rit->first.mDestAddr, STD_RELAY_TTL);
return 1;
@ -745,6 +783,8 @@ int UdpRelayReceiver::recvPkt(void *data, int size, struct sockaddr_in &from)
std::cerr << pit->first;
std::cerr << std::endl;
#endif
mReadBytes += size;
/* remove the header */
void *pktdata = (void *) (((uint8_t *) data) + UDP_RELAY_HEADER_SIZE);
int pktsize = size - UDP_RELAY_HEADER_SIZE;
@ -797,6 +837,9 @@ int UdpRelayReceiver::sendPkt(const void *data, int size, const struct sockaddr_
std::cerr << "UdpRelayReceiver::sendPkt() to Relay: " << it->second;
std::cerr << std::endl;
#endif
mWriteBytes += size;
/* add a header to packet */
int finalPktSize = createRelayUdpPacket(data, size, mTmpSendPkt, MAX_RELAY_UDP_PACKET_SIZE, &(it->second));

View file

@ -159,8 +159,12 @@ virtual int sendPkt(const void *data, int size, const struct sockaddr_in &to, in
int status(std::ostream &out);
int UdpPeersStatus(std::ostream &out);
void getDataTransferred(uint32_t &read, uint32_t &write, uint32_t &relay);
private:
void clearDataTransferred();
int removeUdpRelay_relayLocked(UdpRelayAddrSet *addrs);
int installRelayClass_relayLocked(int &classIdx, uint32_t &bandwidth);
int removeRelayClass_relayLocked(int classIdx);
@ -177,6 +181,7 @@ int UdpPeersStatus(std::ostream &out);
RsMutex udppeerMtx; /* for all class data (below) */
std::map<struct sockaddr_in, UdpPeer *> mPeers; /* indexed by <dest> */
uint32_t mReadBytes;
RsMutex relayMtx; /* for all class data (below) */
@ -187,6 +192,9 @@ int UdpPeersStatus(std::ostream &out);
void *mTmpSendPkt;
uint32_t mTmpSendSize;
uint32_t mWriteBytes;
uint32_t mRelayBytes;
};
/* utility functions for creating / extracting UdpRelayPackets */