Merged from /branches/v0.5-peernet/libbitdht:r4357-4397

Bugfixes and a couple of small improvements to the DHT code.
 * fixed up buggy overloading for the udplayer (for testing).
 * added processing multiple (5) remote processes per tick. 
     - (1 wasn't enough in testing, and led to dropped peers) 
 * removed unused variables from query data structure.
 * #defined out debugging in bdSpace, removed old functions.
 * More agressive attempts to find proxies for connections.
 * made "final query attempt" use exact peer address rather than midid.
     - mid id meant that the target wasn't always returned.
 * tweaked bdconnection debugging.
 * increase CONNECTION_MAX_TIMEOUT from 30 => 45. wasn't enough!
 * Limited bdQuery::QueryIdlePeriod to 15min (was unlimited).
 * added bdQuery::PotentialPeer cleanup functions - for more robust reporting.
 * fixed bdQuery debugging printouts.
 * Implemented BITDHT_QFLAGS_UPDATES flag.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4398 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-06 00:14:58 +00:00
parent 24351cb460
commit 5e691935fd
14 changed files with 202 additions and 131 deletions

View File

@ -34,8 +34,12 @@
#include "util/bdnet.h"
#include "util/bdrandom.h"
#define DEBUG_NODE_CONNECTION 1
/*
* #define DEBUG_NODE_CONNECTION 1
* #define DEBUG_NODE_CONNECTION_EXTRA 1
*/
#define DEBUG_NODE_CONNECTION 1
#define BITDHT_CR_PAUSE_BASE_PERIOD 5
@ -386,8 +390,10 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI
mNodeSpace->find_nearest_nodes_with_flags(target, number, excluding, nearest,
BITDHT_PEER_STATUS_DHT_FOF |
BITDHT_PEER_STATUS_DHT_FRIEND);
number = CONNECT_NUM_PROXY_ATTEMPTS - number;
// just ask for the same number of closest (above doesn't return anything atm)
//int nFound = nearest.size();
//number = CONNECT_NUM_PROXY_ATTEMPTS - nFound;
mNodeSpace->find_nearest_nodes_with_flags(target, number, excluding, nearest,
BITDHT_PEER_STATUS_DHT_ENGINE_VERSION );
@ -395,10 +401,15 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI
std::multimap<bdMetric, bdId>::iterator it;
for(it = nearest.begin(); it != nearest.end(); it++)
{
bdNodeId midId;
mFns->bdRandomMidId(target, &(it->second.id), &midId);
std::cerr << "bdConnectManager::requestConnection_proxy() is Entry it connected to Friend? : ";
mFns->bdPrintId(std::cerr, &(it->second));
std::cerr << std::endl;
//bdNodeId midId;
//mFns->bdRandomMidId(target, &(it->second.id), &midId);
/* trigger search */
mPub->send_query(&(it->second), &midId);
//mPub->send_query(&(it->second), &midId);
mPub->send_query(&(it->second), target);
}
}
@ -437,13 +448,13 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI
void bdConnectManager::addPotentialConnectionProxy(const bdId *srcId, const bdId *target)
{
#ifdef DEBUG_NODE_CONNECTION
//std::cerr << "bdConnectManager::addPotentialConnectionProxy() ";
//std::cerr << " srcId: ";
//bdStdPrintId(std::cerr, srcId);
//std::cerr << " target: ";
//bdStdPrintId(std::cerr, target);
//std::cerr << std::endl;
#ifdef DEBUG_NODE_CONNECTION_EXTRA
std::cerr << "bdConnectManager::addPotentialConnectionProxy() ";
std::cerr << " srcId: ";
bdStdPrintId(std::cerr, srcId);
std::cerr << " target: ";
bdStdPrintId(std::cerr, target);
std::cerr << std::endl;
#endif
if (!srcId)
@ -461,9 +472,9 @@ void bdConnectManager::addPotentialConnectionProxy(const bdId *srcId, const bdId
if (it == mConnectionRequests.end())
{
/* not one of our targets... drop it */
#ifdef DEBUG_NODE_CONNECTION
//std::cerr << "bdConnectManager::addPotentialConnectionProxy() Dropping Not one of Our Targets";
//std::cerr << std::endl;
#ifdef DEBUG_NODE_CONNECTION_EXTRA
std::cerr << "bdConnectManager::addPotentialConnectionProxy() Dropping Not one of Our Targets";
std::cerr << std::endl;
#endif
return;
}
@ -537,7 +548,7 @@ void bdConnectManager::updatePotentialConnectionProxy(const bdId *id, uint32_t m
{
if (mode & BITDHT_PEER_STATUS_DHT_ENGINE_VERSION)
{
#ifdef DEBUG_NODE_CONNECTION
#ifdef DEBUG_NODE_CONNECTION_EXTRA
std::cerr << "bdConnectManager::updatePotentialConnectionProxy() Peer is GOOD : ";
bdStdPrintId(std::cerr, id);
std::cerr << std::endl;
@ -574,11 +585,13 @@ void bdConnectManager::iterateConnectionRequests()
for(it = mConnectionRequests.begin(); it != mConnectionRequests.end(); it++)
{
bool erase = false;
#ifdef DEBUG_NODE_CONNECTION_EXTRA
std::cerr << "bdConnectManager::iterateConnectionAttempt() Request is:";
std::cerr << std::endl;
std::cerr << it->second;
std::cerr << std::endl;
#endif
/* check status of connection */
if (it->second.mState == BITDHT_CONNREQUEST_READY)
@ -586,8 +599,6 @@ void bdConnectManager::iterateConnectionRequests()
std::cerr << "bdConnectManager::iterateConnectionAttempt() Request is READY, starting";
std::cerr << std::endl;
/* kick off the connection if possible */
// goes to BITDHT_CONNREQUEST_INPROGRESS;
if (!startConnectionAttempt(&(it->second)))
@ -1761,9 +1772,10 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
bdConnection *conn = findExistingConnectionBySender(id, srcConnAddr, destConnAddr);
if (conn)
{
/* ERROR */
/* Likely ERROR: Warning */
#ifdef DEBUG_NODE_CONNECTION
std::cerr << "bdConnectManager::recvedConnectionRequest() ERROR EXISTING CONNECTION";
std::cerr << "bdConnectManager::recvedConnectionRequest() WARNING Existing Connection: ";
std::cerr << std::endl;
std::cerr << std::endl;
#endif
/* reply existing connection */

View File

@ -56,7 +56,7 @@ class bdNodePublisher;
#define BD_CONNECTION_START_RETRY_PERIOD 5 // Should only take a couple of seconds to get reply.
#define BD_CONNECTION_START_MAX_RETRY 3
#define BD_CONNECTION_MAX_TIMEOUT 30
#define BD_CONNECTION_MAX_TIMEOUT 45

View File

@ -272,9 +272,8 @@ class bdQuerySummary
#define BITDHT_QFLAGS_NONE 0x0000
#define BITDHT_QFLAGS_DISGUISE 0x0001
#define BITDHT_QFLAGS_DO_IDLE 0x0002
#define BITDHT_QFLAGS_INTERNAL 0x0004 // means it runs through startup.
#define BITDHT_QFLAGS_QUICK 0x0008 // ONE Request per peer.
#define BITDHT_QFLAGS_UPDATES 0x0010 // Do regular updates.
#define BITDHT_QFLAGS_INTERNAL 0x0004 // runs through startup.
#define BITDHT_QFLAGS_UPDATES 0x0008 // Do regular updates.
/* Connect Callback Flags */
#define BITDHT_CONNECT_CB_AUTH 1

View File

@ -63,6 +63,8 @@
// This is eventually what we want.
//#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_ENGINE_VERSION)
#define QUERY_UPDATE_PERIOD 59 // just under one minute... as that gets called every minute...
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
:bdNode(id, dhtVersion, bootfile, fns)
@ -170,6 +172,8 @@ void bdNodeManager::addFindNode(bdNodeId *id, uint32_t qflags)
peer.mDhtAddr.sin_addr.s_addr = 0;
peer.mDhtAddr.sin_port = 0;
peer.mCallbackTS = 0;
mActivePeers[*id] = peer;
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::addFindNode() Added QueryPeer as READY....";
@ -312,7 +316,7 @@ void bdNodeManager::iteration()
break;
case BITDHT_MGR_STATE_ACTIVE:
if (modeAge > MAX_REFRESH_TIME)
if (modeAge >= MAX_REFRESH_TIME)
{
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::iteration(): ACTIVE -> REFRESH";
@ -620,7 +624,7 @@ int bdNodeManager::checkStatus()
std::map<bdNodeId, bdQueryStatus> queryStatus;
mQueryMgr->QueryStatus(queryStatus);
mQueryMgr->QueryStatus(queryStatus);
for(it = queryStatus.begin(); it != queryStatus.end(); it++)
{
@ -740,14 +744,40 @@ int bdNodeManager::checkStatus()
if (pit->second.mStatus == it->second.mStatus)
{
/* status is unchanged */
doPing = false;
doCallback = false;
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::checkStatus() Status unchanged for : ";
mFns->bdPrintNodeId(std::cerr, &(it->first));
std::cerr << " status: " << it->second.mStatus;
std::cerr << std::endl;
#endif
time_t now = time(NULL);
/* now we check if we've done a callback before... */
if (it->second.mQFlags & BITDHT_QFLAGS_UPDATES)
{
if (now - pit->second.mCallbackTS > QUERY_UPDATE_PERIOD)
{
// keep flags.
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::checkStatus() Doing Update Callback for";
mFns->bdPrintNodeId(std::cerr, &(it->first));
std::cerr << " status: " << it->second.mStatus;
std::cerr << std::endl;
#endif
}
else
{
/* no callback this time */
doPing = false;
doCallback = false;
}
}
else
{
doPing = false;
doCallback = false;
}
}
else
{
@ -795,6 +825,9 @@ int bdNodeManager::checkStatus()
mFns->bdPrintNodeId(std::cerr, &(it->first));
std::cerr << std::endl;
#endif
time_t now = time(NULL);
pit->second.mCallbackTS = now;
bdId id(it->first,pit->second.mDhtAddr);
doPeerCallback(&id, callbackStatus);
}

View File

@ -65,9 +65,10 @@ class bdQueryPeer
bdId mId;
uint32_t mStatus;
uint32_t mQFlags;
time_t mLastQuery;
time_t mLastFound;
//time_t mLastQuery;
//time_t mLastFound;
struct sockaddr_in mDhtAddr;
time_t mCallbackTS; // for UPDATES flag.
};

View File

@ -45,7 +45,9 @@
#define BITDHT_QUERY_START_PEERS 10
#define BITDHT_QUERY_NEIGHBOUR_PEERS 8
#define BITDHT_MAX_REMOTE_QUERY_AGE 10
#define MAX_REMOTE_PROCESS_PER_CYCLE 5
/****
* #define USE_HISTORY 1
@ -477,11 +479,13 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
}
/************************************ Process Remote Query *************************/
/* increased the allowed processing rate from 1/sec => 5/sec */
void bdNode::processRemoteQuery()
{
bool processed = false;
int nProcessed = 0;
time_t oldTS = time(NULL) - BITDHT_MAX_REMOTE_QUERY_AGE;
while(!processed)
while(nProcessed < MAX_REMOTE_PROCESS_PER_CYCLE)
{
/* extra exit clause */
if (mRemoteQueries.size() < 1) return;
@ -492,7 +496,7 @@ void bdNode::processRemoteQuery()
if (query.mQueryTS > oldTS)
{
/* recent enough to process! */
processed = true;
nProcessed++;
switch(query.mQueryType)
{
@ -541,7 +545,7 @@ void bdNode::processRemoteQuery()
{
/* drop */
/* unprocess! */
processed = false;
nProcessed--;
break;
}
}
@ -551,10 +555,10 @@ void bdNode::processRemoteQuery()
}
else
{
#ifdef DEBUG_NODE_MSGS
std::cerr << "bdNode::processRemoteQuery() Query Too Old: Discarding: ";
mFns->bdPrintId(std::cerr, &(query.mId));
std::cerr << std::endl;
#ifdef DEBUG_NODE_MSGS
#endif
}

View File

@ -400,14 +400,13 @@ int bdSpace::find_exactnode(const bdId *id, bdPeer &peer)
mFns->bdDistance(&(id->id), &(mOwnId), &dist);
int buckno = mFns->bdBucketDistance(&dist);
#ifdef DEBUG_BD_SPACE
std::cerr << "bdSpace::find_exactnode(Id:";
mFns->bdPrintId(std::cerr, id);
std::cerr << ")";
std::cerr << " Bucket #: " << buckno;
std::cerr << std::endl;
#ifdef DEBUG_BD_SPACE
#endif
bdBucket &buck = buckets[buckno];
@ -418,94 +417,24 @@ int bdSpace::find_exactnode(const bdId *id, bdPeer &peer)
{
if (*id == eit->mPeerId)
{
#ifdef DEBUG_BD_SPACE
std::cerr << "bdSpace::find_exactnode() Found Matching Peer: ";
mFns->bdPrintId(std::cerr, &(eit->mPeerId));
std::cerr << " withFlags: " << eit->mPeerFlags;
std::cerr << std::endl;
#endif
peer = (*eit);
return 1;
}
}
std::cerr << "bdSpace::find_exactnode() ERROR Failed to find Matching Peer: ";
#ifdef DEBUG_BD_SPACE
std::cerr << "bdSpace::find_exactnode() WARNING Failed to find Matching Peer: ";
std::cerr << std::endl;
return 0;
}
#if 0
int bdSpace::out_of_date_peer(bdId &id)
{
/*
*
*/
std::map<bdMetric, bdId> closest;
std::map<bdMetric, bdId>::iterator mit;
std::vector<bdBucket>::iterator it;
std::list<bdPeer>::iterator eit;
time_t ts = time(NULL);
/* iterate through the buckets, and sort by distance */
for(it = buckets.begin(); it != buckets.end(); it++)
{
for(eit = it->entries.begin(); eit != it->entries.end(); )
{
/* timeout on last send time! */
if (ts - eit->mLastSendTime > BITDHT_MAX_SEND_PERIOD )
{
/* We want to ping a peer iff:
* 1) They are out-of-date: mLastRecvTime is too old.
* 2) They don't have 0x0001 flag (we haven't received a PONG) and never sent.
*/
if ((ts - eit->mLastRecvTime > BITDHT_MAX_SEND_PERIOD ) ||
!(eit->mPeerFlags & BITDHT_PEER_STATUS_RECV_PONG))
{
id = eit->mPeerId;
eit->mLastSendTime = ts;
return 1;
}
}
/* we also want to remove very old entries (should it happen here?)
* which are not pushed out by newer entries (will happen in for closer buckets)
*/
bool discard = false;
/* discard very old entries */
if (ts - eit->mLastRecvTime > BITDHT_DISCARD_PERIOD)
{
discard = true;
}
/* discard peers which have not responded to anything (ie have no flags set) */
if ((ts - eit->mFoundTime > BITDHT_MAX_RESPONSE_PERIOD ) &&
(eit->mPeerFlags == 0))
{
discard = true;
}
/* INCREMENT */
if (discard)
{
eit = it->entries.erase(eit);
}
else
{
eit++;
}
}
}
return 0;
}
#endif
return 0;
}
#define BITDHT_ATTACHED_SEND_PERIOD 17

View File

@ -36,9 +36,9 @@
* #define DEBUG_QUERY 1
**/
#define EXPECTED_REPLY 10 // Speed up queries
#define QUERY_IDLE_RETRY_PEER_PERIOD 300 // 5min = (mFns->bdNodesPerBucket() * 30)
#define MAX_QUERY_IDLE_PERIOD 900 // 15min.
/************************************************************
@ -83,6 +83,7 @@ bdQuery::bdQuery(const bdNodeId *id, std::list<bdId> &startList, uint32_t queryF
mQueryTS = now;
mSearchTime = 0;
mClosestListSize = (int) (1.5 * mFns->bdNodesPerBucket());
mPotPeerCleanTS = now;
mQueryIdlePeerRetryPeriod = QUERY_IDLE_RETRY_PEER_PERIOD;
mRequiredPeerFlags = BITDHT_PEER_STATUS_DHT_ENGINE_VERSION; // XXX to update later.
@ -125,6 +126,10 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
if ((now - mQueryTS) / 2 > mQueryIdlePeerRetryPeriod)
{
mQueryIdlePeerRetryPeriod = (now-mQueryTS) / 2;
if (mQueryIdlePeerRetryPeriod > MAX_QUERY_IDLE_PERIOD)
{
mQueryIdlePeerRetryPeriod = MAX_QUERY_IDLE_PERIOD;
}
}
bool notFinished = false;
@ -218,7 +223,7 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
if (age > BITDHT_MAX_QUERY_AGE)
{
#ifdef DEBUG_QUERY
fprintf(stderr, "NextQuery() under Min Time: Query not finished / No Query\n");
fprintf(stderr, "NextQuery() over Max Time: Query force to Finish\n");
#endif
/* fall through and stop */
}
@ -242,6 +247,8 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
mSearchTime = now - mQueryTS;
}
/* cleanup PotentialPeers before doing the final State */;
removeOldPotentialPeers();
/* check if we found the node */
if (mClosest.size() > 0)
{
@ -483,9 +490,9 @@ int bdQuery::worthyPotentialPeer(const bdId *id)
mFns->bdDistance(&mId, &(id->id), &dist);
#ifdef DEBUG_QUERY
fprintf(stderr, "bdQuery::addPotentialPeer(");
std::cerr << "bdQuery::worthyPotentialPeer(";
mFns->bdPrintId(std::cerr, id);
fprintf(stderr, ", %u)\n", mode);
std::cerr << std::endl;
#endif
/* we check if this is a worthy potential peer....
@ -678,6 +685,60 @@ int bdQuery::trimPotentialPeers_toClosest()
}
/* as Potential Peeers are to determine if a peer is CLOSEST or UNREACHABLE
* we need to drop ones that we haven't heard about in ages.
*
* only do this in IDLE mode...
* The timeout period is dependent on our RetryPeriod.
*/
#define POT_PEER_CLEAN_PERIOD 60
#define POT_PEER_RECV_TIMEOUT_PERIOD (mQueryIdlePeerRetryPeriod + EXPECTED_REPLY)
int bdQuery::removeOldPotentialPeers()
{
if (!(mQueryFlags & BITDHT_QFLAGS_DO_IDLE))
{
return 0;
}
time_t now = time(NULL);
if (now - mPotPeerCleanTS < POT_PEER_CLEAN_PERIOD)
{
return 0;
}
mPotPeerCleanTS = now;
/* painful loop */
std::multimap<bdMetric, bdPeer>::iterator it;
for(it = mPotentialPeers.begin(); it != mPotentialPeers.end();)
{
/* which timestamp do we care about? */
if (now - it->second.mLastRecvTime > POT_PEER_RECV_TIMEOUT_PERIOD)
{
#ifdef DEBUG_QUERY
std::cerr << "bdQuery::removeOldPotentialPeers() removing: ";
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
fprintf(stderr, "\n");
#endif
std::multimap<bdMetric, bdPeer>::iterator it2 = it;
++it2 ;
mPotentialPeers.erase(it);
it = it2 ;
// Unfortunately have to start again... as pointers invalidated.
//it = mPotentialPeers.begin();
}
else
{
++it;
}
}
return 1 ;
}
/*******************************************************************************************
******************************** Potential Proxies ****************************************
@ -926,7 +987,7 @@ int bdQuery::printQuery()
}
fprintf(stderr, "\nClosest Potential Peers:\n");
for(it = mPotentialClosest.begin(); it != mPotentialClosest.end(); it++)
for(it = mPotentialPeers.begin(); it != mPotentialPeers.end(); it++)
{
fprintf(stderr, "Id: ");
mFns->bdPrintId(std::cerr, &(it->second.mPeerId));
@ -938,8 +999,8 @@ int bdQuery::printQuery()
}
std::list<bdPeer>::iterator lit;
fprintf(stderr, "\nPotential Proxies:\n");
for(lit = mPotentialProxies.begin(); lit != mPotentialProxies.end(); lit++)
fprintf(stderr, "\nProxies Flagged:\n");
for(lit = mProxiesFlagged.begin(); lit != mProxiesFlagged.end(); lit++)
{
fprintf(stderr, "ProxyId: ");
mFns->bdPrintId(std::cerr, &(lit->mPeerId));
@ -948,6 +1009,18 @@ int bdQuery::printQuery()
fprintf(stderr," LastRecv: %ld ago", ts-lit->mLastRecvTime);
fprintf(stderr, "\n");
}
fprintf(stderr, "\nProxies Unknown:\n");
for(lit = mProxiesUnknown.begin(); lit != mProxiesUnknown.end(); lit++)
{
fprintf(stderr, "ProxyId: ");
mFns->bdPrintId(std::cerr, &(lit->mPeerId));
fprintf(stderr," Found: %ld ago", ts-lit->mFoundTime);
fprintf(stderr," LastSent: %ld ago", ts-lit->mLastSendTime);
fprintf(stderr," LastRecv: %ld ago", ts-lit->mLastRecvTime);
fprintf(stderr, "\n");
}
#else
// shortened version.
fprintf(stderr, "Closest Available Peer: ");

View File

@ -34,7 +34,7 @@
/* Query result flags are in bdiface.h */
#define BITDHT_MIN_QUERY_AGE 10
#define BITDHT_MAX_QUERY_AGE 1800 /* 30 minutes */
#define BITDHT_MAX_QUERY_AGE 300 /* Query Should take <1 minute, so 5 minutes sounds reasonable */
class bdQuery
{
@ -74,6 +74,7 @@ int worthyPotentialPeer(const bdId *id);
int updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType);
int trimPotentialPeers_FixedLength();
int trimPotentialPeers_toClosest();
int removeOldPotentialPeers();
// Proxy Handling Fns.
int addProxy(const bdId *id, const bdId *src, uint32_t srcmode);
@ -85,6 +86,7 @@ int trimProxies();
// closest peers.
std::multimap<bdMetric, bdPeer> mClosest;
std::multimap<bdMetric, bdPeer> mPotentialPeers;
time_t mPotPeerCleanTS; // periodic cleanup of PotentialPeers.
uint32_t mRequiredPeerFlags;
std::list<bdPeer> mProxiesUnknown;
@ -92,6 +94,7 @@ int trimProxies();
int mClosestListSize;
bdDhtFunctions *mFns;
};
#if 0

View File

@ -26,6 +26,7 @@
#include "bitdht/bdquerymgr.h"
#include "bitdht/bdnode.h"
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -51,7 +51,9 @@
// Original RS 0.5.0/0.5.1 version, is un-numbered.
#define BITDHT_VERSION "00" // First Release of BitDHT with Connections (Proxy Support + Dht Stun)
//#define BITDHT_VERSION "01" // Potentially... Connections + Full DHT implementation. (TBD)
//#define BITDHT_VERSION "01" // Full Connections
//#define BITDHT_VERSION "02" // Full DHT implementation.
/*************************************/
UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, bdDhtFunctions *fns)

View File

@ -539,7 +539,7 @@ int LossyUdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_in &f
std::cerr << "LossyUdpLayer::receiveUdpPacket() Packet Dropped!";
std::cerr << std::endl;
size = 0;
*size = 0;
return -1;
}
@ -548,7 +548,7 @@ int LossyUdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_in &f
return -1;
}
int LossyUdpLayer::sendUdpPacket(const void *data, int size, struct sockaddr_in &to)
int LossyUdpLayer::sendUdpPacket(const void *data, int size, const struct sockaddr_in &to)
{
double prob = (1.0 * (rand() / (RAND_MAX + 1.0)));
@ -625,19 +625,25 @@ int RestrictedUdpLayer::receiveUdpPacket(void *data, int *size, struct sockaddr_
//std::cerr << std::endl;
#endif
size = 0;
*size = 0;
return -1;
}
}
#ifdef DEBUG_UDP_LAYER
std::cerr << "RestrictedUdpLayer::receiveUdpPacket() Accepting packet";
std::cerr << ", Port(" << inPort << ") in Okay range!";
std::cerr << std::endl;
#endif
/* acceptable port */
return *size;
}
return -1;
}
int RestrictedUdpLayer::sendUdpPacket(const void *data, int size, struct sockaddr_in &to)
int RestrictedUdpLayer::sendUdpPacket(const void *data, int size, const struct sockaddr_in &to)
{
/* check the port against list */
uint16_t outPort = ntohs(to.sin_port);
@ -661,6 +667,12 @@ int RestrictedUdpLayer::sendUdpPacket(const void *data, int size, struct sockadd
}
#ifdef DEBUG_UDP_LAYER
std::cerr << "RestrictedUdpLayer::sendUdpPacket() Sending packet";
std::cerr << ", Port(" << outPort << ") in Okay range!";
std::cerr << std::endl;
#endif
// otherwise read normally;
return UdpLayer::sendUdpPacket(data, size, to);

View File

@ -129,7 +129,7 @@ virtual ~LossyUdpLayer();
protected:
virtual int receiveUdpPacket(void *data, int *size, struct sockaddr_in &from);
virtual int sendUdpPacket(const void *data, int size, struct sockaddr_in &to);
virtual int sendUdpPacket(const void *data, int size, const struct sockaddr_in &to);
double lossFraction;
};
@ -159,7 +159,7 @@ void addRestrictedPortRange(int lp, int up);
protected:
virtual int receiveUdpPacket(void *data, int *size, struct sockaddr_in &from);
virtual int sendUdpPacket(const void *data, int size, struct sockaddr_in &to);
virtual int sendUdpPacket(const void *data, int size, const struct sockaddr_in &to);
std::list<PortRange> mLostPorts;
};

View File

@ -25,12 +25,14 @@
#include "util/bdbloom.h"
#include <stdlib.h>
#include <sstream>
#include <iomanip>
#if defined(_WIN32) || defined(__MINGW32__)
#include <malloc.h>
#include <malloc.h>
#endif
/* Bloom Filter implementation */