Changes to enable a LAN Relay Test Environment.

NB: Reverse Most of these changes - before adding to Trunk!!!!

 * Added missing BitDht callback functions for test/example code.
 * Switch tests/example to OSX compile.
 * DISABLE_BAD_PEER_FILTER (as it doesn't like local net)
 * Reduced Minimum Peer Counts for DHT to be considered active.
 * Added LOCALNET_TESTING to rsinit.cc 
	- new Commandline Option -R <lport-uport> to restrict UDP ports.
	- Enables LocalNet in UdpStunner.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4756 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-01-07 11:28:00 +00:00
parent 73471b2618
commit af5f23e0e7
8 changed files with 129 additions and 18 deletions

View File

@ -58,7 +58,7 @@
* #define DEBUG_MGR_PKT 1 * #define DEBUG_MGR_PKT 1
***/ ***/
//#define DEBUG_MGR 1 #define DEBUG_MGR 1
//#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_APPL) //#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_APPL)
#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_ENGINE) #define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_ENGINE)
@ -312,11 +312,11 @@ void bdNodeManager::iteration()
*/ */
#define TRANSITION_OP_SPACE_SIZE 50 /* 1 query / sec, should take 12-15 secs */ #define TRANSITION_OP_SPACE_SIZE 50 /* 1 query / sec, should take 12-15 secs */
#define MAX_FINDSELF_TIME 30 //#define MAX_FINDSELF_TIME 30
#define MIN_OP_SPACE_SIZE 10 //#define MIN_OP_SPACE_SIZE 10
// testing parameters. // testing parameters.
//#define MAX_FINDSELF_TIME 10 #define MAX_FINDSELF_TIME 10
//#define MIN_OP_SPACE_SIZE 2 // for testing. self + oneother. #define MIN_OP_SPACE_SIZE 2 // for testing. self + oneother.
{ {
uint32_t nodeSpaceSize = mNodeSpace.calcSpaceSize(); uint32_t nodeSpaceSize = mNodeSpace.calcSpaceSize();
@ -403,7 +403,8 @@ void bdNodeManager::iteration()
/* run a random search for ourselves, from own App DHT peer */ /* run a random search for ourselves, from own App DHT peer */
QueryRandomLocalNet(); QueryRandomLocalNet();
#define SEARCH_MAX_SIZE 10 //#define SEARCH_MAX_SIZE 10
#define SEARCH_MAX_SIZE 0
if (mBdNetworkSize < SEARCH_MAX_SIZE) if (mBdNetworkSize < SEARCH_MAX_SIZE)
{ {
#ifdef DEBUG_MGR #ifdef DEBUG_MGR
@ -1434,3 +1435,26 @@ int bdDebugCallback::dhtConnectCallback(const bdId *srcId, const bdId *proxyId,
return 1; return 1;
} }
int bdDebugCallback::dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info)
{
/* remove unused parameter warnings */
(void) id;
(void) type;
(void) flags;
(void) info;
#ifdef DEBUG_MGR
std::cerr << "bdDebugCallback::dhtInfoCallback() Type: " << type;
std::cerr << " Id: ";
bdStdPrintId(std::cerr, id);
std::cerr << " flags: " << flags;
std::cerr << " info: " << info;
std::cerr << std::endl;
#endif
return 1;
}

View File

@ -201,6 +201,7 @@ virtual int dhtPeerCallback(const bdId *id, uint32_t status);
virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t status); virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t status);
virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId, virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
uint32_t mode, uint32_t point, uint32_t param, uint32_t cbtype, uint32_t errcode); uint32_t mode, uint32_t point, uint32_t param, uint32_t cbtype, uint32_t errcode);
virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info);
}; };

View File

@ -462,7 +462,7 @@ void bdNode::send_connect_msg(bdId *id, int msgtype, bdId *srcAddr, bdId *destAd
//#define DISABLE_BAD_PEER_FILTER 1 #define DISABLE_BAD_PEER_FILTER 1
void bdNode::checkPotentialPeer(bdId *id, bdId *src) void bdNode::checkPotentialPeer(bdId *id, bdId *src)
{ {
@ -488,6 +488,7 @@ void bdNode::checkPotentialPeer(bdId *id, bdId *src)
{ {
if (knownAddr.sin_addr.s_addr != id->addr.sin_addr.s_addr) if (knownAddr.sin_addr.s_addr != id->addr.sin_addr.s_addr)
{ {
#ifndef DISABLE_BAD_PEER_FILTER
std::cerr << "bdNode::checkPotentialPeer("; std::cerr << "bdNode::checkPotentialPeer(";
mFns->bdPrintId(std::cerr, id); mFns->bdPrintId(std::cerr, id);
std::cerr << ") MASQARADING AS KNOWN PEER - FLAGGING AS BAD"; std::cerr << ") MASQARADING AS KNOWN PEER - FLAGGING AS BAD";
@ -496,7 +497,6 @@ void bdNode::checkPotentialPeer(bdId *id, bdId *src)
// Stores in queue for later callback and desemination around the network. // Stores in queue for later callback and desemination around the network.
mBadPeerQueue.queuePeer(id, 0); mBadPeerQueue.queuePeer(id, 0);
#ifndef DISABLE_BAD_PEER_FILTER
mFilterPeers->addPeerToFilter(id, 0); mFilterPeers->addPeerToFilter(id, 0);
std::list<struct sockaddr_in> filteredIPs; std::list<struct sockaddr_in> filteredIPs;
@ -574,6 +574,7 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
{ {
if (knownAddr.sin_addr.s_addr != id->addr.sin_addr.s_addr) if (knownAddr.sin_addr.s_addr != id->addr.sin_addr.s_addr)
{ {
#ifndef DISABLE_BAD_PEER_FILTER
std::cerr << "bdNode::addPeer("; std::cerr << "bdNode::addPeer(";
mFns->bdPrintId(std::cerr, id); mFns->bdPrintId(std::cerr, id);
std::cerr << ", " << std::hex << peerflags << std::dec; std::cerr << ", " << std::hex << peerflags << std::dec;
@ -584,13 +585,11 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
// Stores in queue for later callback and desemination around the network. // Stores in queue for later callback and desemination around the network.
mBadPeerQueue.queuePeer(id, peerflags); mBadPeerQueue.queuePeer(id, peerflags);
#ifndef DISABLE_BAD_PEER_FILTER
mFilterPeers->addPeerToFilter(id, peerflags); mFilterPeers->addPeerToFilter(id, peerflags);
std::list<struct sockaddr_in> filteredIPs; std::list<struct sockaddr_in> filteredIPs;
mFilterPeers->filteredIPs(filteredIPs); mFilterPeers->filteredIPs(filteredIPs);
mStore.filterIpList(filteredIPs); mStore.filterIpList(filteredIPs);
#endif
// DO WE EXPLICITLY NEED TO DO THIS, OR WILL THEY JUST BE DROPPED? // DO WE EXPLICITLY NEED TO DO THIS, OR WILL THEY JUST BE DROPPED?
//mNodeSpace.remove_badpeer(id); //mNodeSpace.remove_badpeer(id);
@ -599,7 +598,6 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
// FLAG in NodeSpace (Should be dropped very quickly anyway) // FLAG in NodeSpace (Should be dropped very quickly anyway)
mNodeSpace.flagpeer(id, 0, BITDHT_PEER_EXFLAG_BADPEER); mNodeSpace.flagpeer(id, 0, BITDHT_PEER_EXFLAG_BADPEER);
#ifndef DISABLE_BAD_PEER_FILTER
return; return;
#endif #endif
} }

View File

@ -1,6 +1,6 @@
CXXFLAGS = -Wall -g -I.. CXXFLAGS = -Wall -g -I..
#CXXFLAGS += -arch i386 # OSX CXXFLAGS += -arch i386 # OSX
LIBS = -L../lib -lbitdht LIBS = -L../lib -lbitdht

View File

@ -45,7 +45,7 @@ virtual int dhtNodeCallback(const bdId *id, uint32_t peerflags)
return mParent->NodeCallback(id, peerflags); return mParent->NodeCallback(id, peerflags);
} }
virtual int dhtPeerCallback(const bdNodeId *id, uint32_t status) virtual int dhtPeerCallback(const bdId *id, uint32_t status)
{ {
return mParent->PeerCallback(id, status); return mParent->PeerCallback(id, status);
} }
@ -55,6 +55,16 @@ virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t statu
return mParent->ValueCallback(id, key, status); return mParent->ValueCallback(id, key, status);
} }
virtual int dhtConnectCallback(const bdId*, const bdId*, const bdId*, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
{
return 1;
}
virtual int dhtInfoCallback(const bdId*, uint32_t, uint32_t, std::string)
{
return 1;
}
private: private:
BitDhtHandler *mParent; BitDhtHandler *mParent;
@ -187,10 +197,10 @@ int BitDhtHandler::NodeCallback(const bdId *id, uint32_t peerflags)
return 0; return 0;
} }
int BitDhtHandler::PeerCallback(const bdNodeId *id, uint32_t status) int BitDhtHandler::PeerCallback(const bdId *id, uint32_t status)
{ {
std::cerr << "BitDhtHandler::PeerCallback() NodeId: "; std::cerr << "BitDhtHandler::PeerCallback() NodeId: ";
bdStdPrintNodeId(std::cerr, id); bdStdPrintId(std::cerr, id);
std::cerr << std::endl; std::cerr << std::endl;
bool connect = false; bool connect = false;

View File

@ -55,7 +55,7 @@ bool FindNode(bdNodeId *peerId);
bool DropNode(bdNodeId *peerId); bool DropNode(bdNodeId *peerId);
virtual int NodeCallback(const bdId *id, uint32_t peerflags); virtual int NodeCallback(const bdId *id, uint32_t peerflags);
virtual int PeerCallback(const bdNodeId *id, uint32_t status); virtual int PeerCallback(const bdId *id, uint32_t status);
virtual int ValueCallback(const bdNodeId *id, std::string key, uint32_t status); virtual int ValueCallback(const bdNodeId *id, std::string key, uint32_t status);
private: private:

View File

@ -4,8 +4,8 @@
########################################################################### ###########################################################################
#Define OS. #Define OS.
# #
OS = Linux #OS = Linux
#OS = MacOSX OS = MacOSX
#OS = Cygwin #OS = Cygwin
#OS = Win # MinGw. #OS = Win # MinGw.
########################################################################### ###########################################################################

View File

@ -313,6 +313,19 @@ void RsInit::InitRsConfig()
//setZoneLevel(PQL_DEBUG_BASIC, 49787); // pqissllistener //setZoneLevel(PQL_DEBUG_BASIC, 49787); // pqissllistener
} }
/********
* LOCALNET_TESTING - allows port restrictions
********/
#define LOCALNET_TESTING 1
#ifdef LOCALNET_TESTING
std::string portRestrictions;
bool doPortRestrictions = false;
#endif
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ /******************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
@ -395,7 +408,11 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
/* getopt info: every availiable option is listed here. if it is followed by a ':' it /* getopt info: every availiable option is listed here. if it is followed by a ':' it
needs an argument. If it is followed by a '::' the argument is optional. needs an argument. If it is followed by a '::' the argument is optional.
*/ */
#ifdef LOCALNET_TESTING
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:U:r:R:")) != -1)
#else
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:U:r:")) != -1) while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:U:r:")) != -1)
#endif
{ {
switch (c) switch (c)
{ {
@ -470,6 +487,14 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
std::cerr << "Opt for RetroShare link"; std::cerr << "Opt for RetroShare link";
std::cerr << std::endl; std::cerr << std::endl;
break; break;
#ifdef LOCALNET_TESTING
case 'R':
portRestrictions = optarg;
doPortRestrictions = true;
std::cerr << "Opt for Port Restrictions";
std::cerr << std::endl;
break;
#endif
case 'h': case 'h':
std::cerr << "Help: " << std::endl; std::cerr << "Help: " << std::endl;
std::cerr << "The commandline options are for retroshare-nogui, a headless server in a shell, or systems without QT." << std::endl << std::endl; std::cerr << "The commandline options are for retroshare-nogui, a headless server in a shell, or systems without QT." << std::endl << std::endl;
@ -486,6 +511,9 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck
std::cerr << "-e Use a forwarded external Port" << std::endl ; std::cerr << "-e Use a forwarded external Port" << std::endl ;
std::cerr << "-U [User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled." << std::endl; std::cerr << "-U [User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled." << std::endl;
std::cerr << "-r link Use RetroShare link." << std::endl; std::cerr << "-r link Use RetroShare link." << std::endl;
#ifdef LOCALNET_TESTING
std::cerr << "-R <lport-uport> Port Restrictions." << std::endl;
#endif
exit(1); exit(1);
break; break;
default: default:
@ -1886,7 +1914,35 @@ int RsServer::StartupRetroShare()
struct sockaddr_in tmpladdr; struct sockaddr_in tmpladdr;
sockaddr_clear(&tmpladdr); sockaddr_clear(&tmpladdr);
tmpladdr.sin_port = htons(RsInitConfig::port); tmpladdr.sin_port = htons(RsInitConfig::port);
#ifdef LOCALNET_TESTING
rsUdpStack *mDhtStack = new rsUdpStack(UDP_TEST_RESTRICTED_LAYER, tmpladdr);
/* parse portRestrictions */
unsigned int lport, uport;
if (doPortRestrictions)
{
if (2 == sscanf(portRestrictions.c_str(), "%u-%u", &lport, &uport))
{
std::cerr << "Adding Port Restriction (" << lport << "-" << uport << ")";
std::cerr << std::endl;
}
else
{
std::cerr << "Failed to parse Port Restrictions ... exiting";
std::cerr << std::endl;
exit(1);
}
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mDhtStack->getUdpLayer();
url->addRestrictedPortRange(lport, uport);
}
#else
rsUdpStack *mDhtStack = new rsUdpStack(tmpladdr); rsUdpStack *mDhtStack = new rsUdpStack(tmpladdr);
#endif
#ifdef RS_USE_BITDHT #ifdef RS_USE_BITDHT
@ -1943,6 +1999,10 @@ int RsServer::StartupRetroShare()
mDhtStunner->setTargetStunPeriod(300); /* slow (5mins) */ mDhtStunner->setTargetStunPeriod(300); /* slow (5mins) */
mDhtStack->addReceiver(mDhtStunner); mDhtStack->addReceiver(mDhtStunner);
#ifdef LOCALNET_TESTING
mDhtStunner->SetAcceptLocalNet();
#endif
// NEXT BITDHT. // NEXT BITDHT.
p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile); p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile);
/* install external Pointer for Interface */ /* install external Pointer for Interface */
@ -1969,12 +2029,30 @@ int RsServer::StartupRetroShare()
sockaddr_clear(&sndladdr); sockaddr_clear(&sndladdr);
uint16_t rndport = MIN_RANDOM_PORT + RSRandom::random_u32() % (MAX_RANDOM_PORT - MIN_RANDOM_PORT); uint16_t rndport = MIN_RANDOM_PORT + RSRandom::random_u32() % (MAX_RANDOM_PORT - MIN_RANDOM_PORT);
sndladdr.sin_port = htons(rndport); sndladdr.sin_port = htons(rndport);
#ifdef LOCALNET_TESTING
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(UDP_TEST_RESTRICTED_LAYER, sndladdr);
/* portRestrictions already parsed */
if (doPortRestrictions)
{
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mProxyStack->getUdpLayer();
url->addRestrictedPortRange(lport, uport);
}
#else
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(sndladdr); rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(sndladdr);
#endif
// FIRSTLY THE PROXY STUNNER. // FIRSTLY THE PROXY STUNNER.
UdpStunner *mProxyStunner = new UdpStunner(mProxyStack); UdpStunner *mProxyStunner = new UdpStunner(mProxyStack);
mProxyStunner->setTargetStunPeriod(300); /* slow (5mins) */ mProxyStunner->setTargetStunPeriod(300); /* slow (5mins) */
mProxyStack->addReceiver(mProxyStunner); mProxyStack->addReceiver(mProxyStunner);
#ifdef LOCALNET_TESTING
mProxyStunner->SetAcceptLocalNet();
#endif
// FINALLY THE PROXY UDP CONNECTIONS // FINALLY THE PROXY UDP CONNECTIONS
udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX] = new UdpPeerReceiver(mProxyStack); /* PROXY Connections (Alt UDP Port) */ udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX] = new UdpPeerReceiver(mProxyStack); /* PROXY Connections (Alt UDP Port) */