mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Fixed Dsdv debugging and cleanup of old entries.
Added PRIORITIES for BanListItems and DsdvItems. Increased Dsdv Max Distance to 5... Its almost ready for network-wide test! git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4698 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5268391f2e
commit
02b03d1a0f
@ -73,3 +73,12 @@ const uint8_t QOS_PRIORITY_RS_STATUS_ITEM = 2 ;
|
|||||||
//
|
//
|
||||||
const uint8_t QOS_PRIORITY_RS_VOIP_PING = 9 ;
|
const uint8_t QOS_PRIORITY_RS_VOIP_PING = 9 ;
|
||||||
|
|
||||||
|
// BanList
|
||||||
|
//
|
||||||
|
const uint8_t QOS_PRIORITY_RS_BANLIST_ITEM = 2 ;
|
||||||
|
|
||||||
|
// Dsdv Routing
|
||||||
|
//
|
||||||
|
const uint8_t QOS_PRIORITY_RS_DSDV_ROUTE = 4 ;
|
||||||
|
const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
|
||||||
|
|
||||||
|
@ -43,7 +43,11 @@ class RsBanListItem: public RsItem
|
|||||||
RsBanListItem()
|
RsBanListItem()
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST,
|
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST,
|
||||||
RS_PKT_SUBTYPE_BANLIST_ITEM)
|
RS_PKT_SUBTYPE_BANLIST_ITEM)
|
||||||
{ return; }
|
{
|
||||||
|
setPriorityLevel(QOS_PRIORITY_RS_BANLIST_ITEM);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~RsBanListItem();
|
virtual ~RsBanListItem();
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
@ -45,7 +45,10 @@ class RsDsdvRouteItem: public RsItem
|
|||||||
RsDsdvRouteItem()
|
RsDsdvRouteItem()
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DSDV,
|
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DSDV,
|
||||||
RS_PKT_SUBTYPE_DSDV_ROUTE)
|
RS_PKT_SUBTYPE_DSDV_ROUTE)
|
||||||
{ return; }
|
{
|
||||||
|
setPriorityLevel(QOS_PRIORITY_RS_DSDV_ROUTE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
virtual ~RsDsdvRouteItem();
|
virtual ~RsDsdvRouteItem();
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||||
@ -53,14 +56,16 @@ std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
|||||||
RsTlvDsdvEntrySet routes;
|
RsTlvDsdvEntrySet routes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class RsDsdvDataItem: public RsItem
|
class RsDsdvDataItem: public RsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsDsdvDataItem()
|
RsDsdvDataItem()
|
||||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DSDV,
|
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_DSDV,
|
||||||
RS_PKT_SUBTYPE_DSDV_DATA), data(TLV_TYPE_BIN_GENERIC)
|
RS_PKT_SUBTYPE_DSDV_DATA), data(TLV_TYPE_BIN_GENERIC)
|
||||||
{ return; }
|
{
|
||||||
|
setPriorityLevel(QOS_PRIORITY_RS_DSDV_DATA);
|
||||||
|
return;
|
||||||
|
}
|
||||||
virtual ~RsDsdvDataItem();
|
virtual ~RsDsdvDataItem();
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||||
|
@ -108,6 +108,7 @@ int p3Dsdv::sendTables()
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
selectStableRoutes();
|
selectStableRoutes();
|
||||||
|
clearOldRoutes();
|
||||||
|
|
||||||
generateRoutingTables(false);
|
generateRoutingTables(false);
|
||||||
|
|
||||||
@ -140,6 +141,8 @@ void p3Dsdv::advanceLocalSequenceNumbers()
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
|
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
std::map<std::string, RsDsdvTableEntry>::iterator it;
|
std::map<std::string, RsDsdvTableEntry>::iterator it;
|
||||||
for(it = mTable.begin(); it != mTable.end(); it++)
|
for(it = mTable.begin(); it != mTable.end(); it++)
|
||||||
{
|
{
|
||||||
@ -147,6 +150,7 @@ void p3Dsdv::advanceLocalSequenceNumbers()
|
|||||||
if (v.mOwnSource)
|
if (v.mOwnSource)
|
||||||
{
|
{
|
||||||
v.mStableRoute.mSequence += RSDSDV_SEQ_INCREMENT;
|
v.mStableRoute.mSequence += RSDSDV_SEQ_INCREMENT;
|
||||||
|
v.mStableRoute.mReceived = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,6 +302,13 @@ int p3Dsdv::handleDSDV(RsDsdvRouteItem *dsdv)
|
|||||||
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::handleDSDV() Received Pkt from: " << dsdv->PeerId();
|
||||||
|
std::cerr << std::endl;
|
||||||
|
dsdv->print(std::cerr);
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::list<RsTlvDsdvEntry>::iterator it;
|
std::list<RsTlvDsdvEntry>::iterator it;
|
||||||
for(it = dsdv->routes.entries.begin(); it != dsdv->routes.entries.end(); it++)
|
for(it = dsdv->routes.entries.begin(); it != dsdv->routes.entries.end(); it++)
|
||||||
{
|
{
|
||||||
@ -305,11 +316,17 @@ int p3Dsdv::handleDSDV(RsDsdvRouteItem *dsdv)
|
|||||||
RsTlvDsdvEntry &entry = *it;
|
RsTlvDsdvEntry &entry = *it;
|
||||||
uint32_t realDistance = entry.distance + 1; // metric.
|
uint32_t realDistance = entry.distance + 1; // metric.
|
||||||
|
|
||||||
|
|
||||||
/* find the entry */
|
/* find the entry */
|
||||||
std::map<std::string, RsDsdvTableEntry>::iterator tit;
|
std::map<std::string, RsDsdvTableEntry>::iterator tit;
|
||||||
tit = mTable.find(entry.endPoint.serviceId);
|
tit = mTable.find(entry.endPoint.serviceId);
|
||||||
if (tit == mTable.end())
|
if (tit == mTable.end())
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::handleDSDV() Adding Entry for New ServiceId: ";
|
||||||
|
std::cerr << entry.endPoint.serviceId;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
/* new entry! */
|
/* new entry! */
|
||||||
RsDsdvTableEntry v;
|
RsDsdvTableEntry v;
|
||||||
v.mDest.mIdType = entry.endPoint.idType;
|
v.mDest.mIdType = entry.endPoint.idType;
|
||||||
@ -340,6 +357,11 @@ int p3Dsdv::handleDSDV(RsDsdvRouteItem *dsdv)
|
|||||||
RsDsdvTableEntry &v = tit->second;
|
RsDsdvTableEntry &v = tit->second;
|
||||||
if (v.mOwnSource)
|
if (v.mOwnSource)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::handleDSDV() Ignoring OwnSource Entry:";
|
||||||
|
std::cerr << entry.endPoint.serviceId;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
continue; // Ignore if we are source.
|
continue; // Ignore if we are source.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,14 +382,29 @@ int p3Dsdv::handleDSDV(RsDsdvRouteItem *dsdv)
|
|||||||
v.mAllRoutes[dsdv->PeerId()] = newRoute;
|
v.mAllRoutes[dsdv->PeerId()] = newRoute;
|
||||||
|
|
||||||
/* if we've just added it in - can't be stable one */
|
/* if we've just added it in - can't be stable one */
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::handleDSDV() Adding NewRoute Entry:";
|
||||||
|
std::cerr << entry.endPoint.serviceId;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (rit->second.mSequence >= entry.sequence)
|
if (rit->second.mSequence >= entry.sequence)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::handleDSDV() Ignoring OLDSEQ Entry:";
|
||||||
|
std::cerr << entry.endPoint.serviceId;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
/* ignore same/old sequence number??? */
|
/* ignore same/old sequence number??? */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::handleDSDV() Updating Entry:";
|
||||||
|
std::cerr << entry.endPoint.serviceId;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* update seq,dist,etc */
|
/* update seq,dist,etc */
|
||||||
if (rit->second.mSequence + 2 < entry.sequence)
|
if (rit->second.mSequence + 2 < entry.sequence)
|
||||||
@ -416,11 +453,16 @@ int p3Dsdv::selectStableRoutes()
|
|||||||
{
|
{
|
||||||
|
|
||||||
#ifdef DEBUG_DSDV
|
#ifdef DEBUG_DSDV
|
||||||
std::cerr << "p3Dsdv::selectStableRoutes() For Entry: " << tit->second;
|
std::cerr << "p3Dsdv::selectStableRoutes() For Entry: ";
|
||||||
|
std::cerr << tit->second;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (tit->second.mOwnSource)
|
if (tit->second.mOwnSource)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::selectStableRoutes() OwnSource... Ignoring";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
continue; // Ignore if we are source.
|
continue; // Ignore if we are source.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +477,8 @@ int p3Dsdv::selectStableRoutes()
|
|||||||
for(rit = tit->second.mAllRoutes.begin();
|
for(rit = tit->second.mAllRoutes.begin();
|
||||||
rit != tit->second.mAllRoutes.end(); rit++)
|
rit != tit->second.mAllRoutes.end(); rit++)
|
||||||
{
|
{
|
||||||
if (rit->second.mSequence >= newest)
|
if ((now - rit->second.mReceived <= DSDV_DISCARD_PERIOD) &&
|
||||||
|
(rit->second.mSequence >= newest))
|
||||||
{
|
{
|
||||||
newest = rit->second.mSequence;
|
newest = rit->second.mSequence;
|
||||||
newestId = rit->first;
|
newestId = rit->first;
|
||||||
@ -447,6 +490,16 @@ int p3Dsdv::selectStableRoutes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (closest == RSDSDV_MAX_DISTANCE)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "\tNo Suitable Route";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
tit->second.mIsStable = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t currseq = newest - (newest % 2); // remove 'kill'=ODD Seq.
|
uint32_t currseq = newest - (newest % 2); // remove 'kill'=ODD Seq.
|
||||||
|
|
||||||
#ifdef DEBUG_DSDV
|
#ifdef DEBUG_DSDV
|
||||||
@ -514,24 +567,60 @@ int p3Dsdv::selectStableRoutes()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closest == RSDSDV_MAX_DISTANCE)
|
tit->second.mIsStable = true;
|
||||||
{
|
rit = tit->second.mAllRoutes.find(closestId);
|
||||||
|
tit->second.mStableRoute = rit->second;
|
||||||
|
tit->second.mFlags &= ~RSDSDV_FLAGS_NEW_ROUTE;
|
||||||
|
|
||||||
#ifdef DEBUG_DSDV
|
#ifdef DEBUG_DSDV
|
||||||
std::cerr << "\tNo Suitable Route";
|
std::cerr << "\tStable Route: " << tit->second.mStableRoute;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
tit->second.mIsStable = false;
|
}
|
||||||
}
|
return 1;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
tit->second.mIsStable = true;
|
|
||||||
rit = tit->second.mAllRoutes.find(closestId);
|
|
||||||
tit->second.mStableRoute = rit->second;
|
|
||||||
|
int p3Dsdv::clearOldRoutes()
|
||||||
|
{
|
||||||
|
/* iterate over the entries */
|
||||||
|
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
|
||||||
|
|
||||||
#ifdef DEBUG_DSDV
|
#ifdef DEBUG_DSDV
|
||||||
std::cerr << "\tStable Route: " << tit->second.mStableRoute;
|
std::cerr << "p3Dsdv::clearOldRoutes()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* find the entry */
|
||||||
|
std::map<std::string, RsDsdvTableEntry>::iterator it, it2;
|
||||||
|
for(it = mTable.begin(); it != mTable.end(); it++)
|
||||||
|
{
|
||||||
|
if (it->second.mOwnSource)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (it->second.mIsStable)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it->second.mFlags & RSDSDV_FLAGS_NEW_ROUTE)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* backstep iterator for loop, and delete original */
|
||||||
|
it2 = it;
|
||||||
|
it--;
|
||||||
|
|
||||||
|
#ifdef DEBUG_DSDV
|
||||||
|
std::cerr << "p3Dsdv::clearOldRoutes() Deleting OLD ServiceId: " << it2->first;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
mTable.erase(it2);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -641,6 +730,7 @@ int p3Dsdv::addDsdvId(RsDsdvId *id, std::string realHash)
|
|||||||
v.mStableRoute.mValidSince = now;
|
v.mStableRoute.mValidSince = now;
|
||||||
v.mStableRoute.mSequence = 0;
|
v.mStableRoute.mSequence = 0;
|
||||||
v.mStableRoute.mDistance = 0;
|
v.mStableRoute.mDistance = 0;
|
||||||
|
v.mIsStable = true;
|
||||||
|
|
||||||
v.mFlags = RSDSDV_FLAGS_OWN_SERVICE;
|
v.mFlags = RSDSDV_FLAGS_OWN_SERVICE;
|
||||||
v.mOwnSource = true;
|
v.mOwnSource = true;
|
||||||
@ -760,8 +850,11 @@ std::ostream &operator<<(std::ostream &out, const RsDsdvId &id)
|
|||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const RsDsdvRoute &route)
|
std::ostream &operator<<(std::ostream &out, const RsDsdvRoute &route)
|
||||||
{
|
{
|
||||||
|
time_t now = time(NULL);
|
||||||
out << "< Seq: " << route.mSequence << " Dist: " << route.mDistance;
|
out << "< Seq: " << route.mSequence << " Dist: " << route.mDistance;
|
||||||
out << " NextHop: " << route.mNextHop << " recvd: " << route.mReceived;
|
out << " NextHop: " << route.mNextHop;
|
||||||
|
out << " recvd: " << now-route.mReceived;
|
||||||
|
out << " validSince: " << now-route.mValidSince;
|
||||||
out << " >";
|
out << " >";
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
@ -770,19 +863,30 @@ std::ostream &operator<<(std::ostream &out, const RsDsdvRoute &route)
|
|||||||
std::ostream &operator<<(std::ostream &out, const RsDsdvTableEntry &entry)
|
std::ostream &operator<<(std::ostream &out, const RsDsdvTableEntry &entry)
|
||||||
{
|
{
|
||||||
out << "DSDV Route for: " << entry.mDest << std::endl;
|
out << "DSDV Route for: " << entry.mDest << std::endl;
|
||||||
out << "\tStable: " << entry.mStableRoute << std::endl;
|
if (entry.mIsStable)
|
||||||
out << "\tOwnSource: " << entry.mOwnSource;
|
|
||||||
out << " Flags: " << entry.mFlags << std::endl;
|
|
||||||
if (entry.mMatched)
|
|
||||||
{
|
{
|
||||||
out << "Matched: " << entry.mMatchedHash;
|
out << "\tStable: " << entry.mStableRoute << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out << "Non Matched";
|
out << "\tNo Stable Route" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
out << "\tOwnSource: " << entry.mOwnSource;
|
||||||
|
out << " Flags: " << entry.mFlags;
|
||||||
|
if (entry.mMatched)
|
||||||
|
{
|
||||||
|
out << " Matched: " << entry.mMatchedHash;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out << " Non Matched";
|
||||||
}
|
}
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
out << "\tAll Routes:" << std::endl;
|
if (entry.mAllRoutes.size() > 0)
|
||||||
|
{
|
||||||
|
out << "\tAll Routes:" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
std::map<std::string, RsDsdvRoute>::const_iterator it;
|
std::map<std::string, RsDsdvRoute>::const_iterator it;
|
||||||
for(it = entry.mAllRoutes.begin(); it != entry.mAllRoutes.end(); it++)
|
for(it = entry.mAllRoutes.begin(); it != entry.mAllRoutes.end(); it++)
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
class p3LinkMgr;
|
class p3LinkMgr;
|
||||||
|
|
||||||
|
|
||||||
#define RSDSDV_MAX_DISTANCE 3
|
#define RSDSDV_MAX_DISTANCE 5
|
||||||
#define RSDSDV_MAX_SEND_TABLE 100
|
#define RSDSDV_MAX_SEND_TABLE 100
|
||||||
|
|
||||||
//!The RS DSDV service.
|
//!The RS DSDV service.
|
||||||
@ -68,7 +68,7 @@ int sendTables();
|
|||||||
void advanceLocalSequenceNumbers();
|
void advanceLocalSequenceNumbers();
|
||||||
void clearSignificantChangesFlags();
|
void clearSignificantChangesFlags();
|
||||||
|
|
||||||
int selectStableRoutes();
|
|
||||||
int generateRoutingTables(bool incremental);
|
int generateRoutingTables(bool incremental);
|
||||||
int generateRoutingTable(const std::string &peerId, bool incremental);
|
int generateRoutingTable(const std::string &peerId, bool incremental);
|
||||||
|
|
||||||
@ -76,6 +76,8 @@ int processIncoming();
|
|||||||
|
|
||||||
int handleDSDV(RsDsdvRouteItem *dsdv);
|
int handleDSDV(RsDsdvRouteItem *dsdv);
|
||||||
|
|
||||||
|
int selectStableRoutes();
|
||||||
|
int clearOldRoutes();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user