From ebc96bfc1f2e1d7de12de8806414ce7dab276336 Mon Sep 17 00:00:00 2001 From: drbob Date: Sat, 7 Jan 2012 11:28:00 +0000 Subject: [PATCH] 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 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 --- src/bitdht/bdmanager.cc | 36 ++++++++++++++++++++++++++++++------ src/bitdht/bdmanager.h | 1 + src/bitdht/bdnode.cc | 8 +++----- src/example/Makefile | 2 +- src/example/bdhandler.cc | 16 +++++++++++++--- src/example/bdhandler.h | 2 +- src/tests/scripts/config.mk | 4 ++-- 7 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/bitdht/bdmanager.cc b/src/bitdht/bdmanager.cc index a7ee7f2..db188ba 100644 --- a/src/bitdht/bdmanager.cc +++ b/src/bitdht/bdmanager.cc @@ -58,7 +58,7 @@ * #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_ENGINE) @@ -312,11 +312,11 @@ void bdNodeManager::iteration() */ #define TRANSITION_OP_SPACE_SIZE 50 /* 1 query / sec, should take 12-15 secs */ -#define MAX_FINDSELF_TIME 30 -#define MIN_OP_SPACE_SIZE 10 +//#define MAX_FINDSELF_TIME 30 +//#define MIN_OP_SPACE_SIZE 10 // testing parameters. -//#define MAX_FINDSELF_TIME 10 -//#define MIN_OP_SPACE_SIZE 2 // for testing. self + oneother. +#define MAX_FINDSELF_TIME 10 +#define MIN_OP_SPACE_SIZE 2 // for testing. self + oneother. { uint32_t nodeSpaceSize = mNodeSpace.calcSpaceSize(); @@ -403,7 +403,8 @@ void bdNodeManager::iteration() /* run a random search for ourselves, from own App DHT peer */ QueryRandomLocalNet(); -#define SEARCH_MAX_SIZE 10 +//#define SEARCH_MAX_SIZE 10 +#define SEARCH_MAX_SIZE 0 if (mBdNetworkSize < SEARCH_MAX_SIZE) { #ifdef DEBUG_MGR @@ -1434,3 +1435,26 @@ int bdDebugCallback::dhtConnectCallback(const bdId *srcId, const bdId *proxyId, 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; +} + + + diff --git a/src/bitdht/bdmanager.h b/src/bitdht/bdmanager.h index b29aaa7..635a5eb 100644 --- a/src/bitdht/bdmanager.h +++ b/src/bitdht/bdmanager.h @@ -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 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); +virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info); }; diff --git a/src/bitdht/bdnode.cc b/src/bitdht/bdnode.cc index b486608..9c4659c 100644 --- a/src/bitdht/bdnode.cc +++ b/src/bitdht/bdnode.cc @@ -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) { @@ -488,6 +488,7 @@ void bdNode::checkPotentialPeer(bdId *id, bdId *src) { if (knownAddr.sin_addr.s_addr != id->addr.sin_addr.s_addr) { +#ifndef DISABLE_BAD_PEER_FILTER std::cerr << "bdNode::checkPotentialPeer("; mFns->bdPrintId(std::cerr, id); 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. mBadPeerQueue.queuePeer(id, 0); -#ifndef DISABLE_BAD_PEER_FILTER mFilterPeers->addPeerToFilter(id, 0); std::list 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) { +#ifndef DISABLE_BAD_PEER_FILTER std::cerr << "bdNode::addPeer("; mFns->bdPrintId(std::cerr, id); 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. mBadPeerQueue.queuePeer(id, peerflags); -#ifndef DISABLE_BAD_PEER_FILTER mFilterPeers->addPeerToFilter(id, peerflags); std::list filteredIPs; mFilterPeers->filteredIPs(filteredIPs); mStore.filterIpList(filteredIPs); -#endif // DO WE EXPLICITLY NEED TO DO THIS, OR WILL THEY JUST BE DROPPED? //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) mNodeSpace.flagpeer(id, 0, BITDHT_PEER_EXFLAG_BADPEER); -#ifndef DISABLE_BAD_PEER_FILTER return; #endif } diff --git a/src/example/Makefile b/src/example/Makefile index b71d1f8..eeb1c8c 100644 --- a/src/example/Makefile +++ b/src/example/Makefile @@ -1,6 +1,6 @@ CXXFLAGS = -Wall -g -I.. -#CXXFLAGS += -arch i386 # OSX +CXXFLAGS += -arch i386 # OSX LIBS = -L../lib -lbitdht diff --git a/src/example/bdhandler.cc b/src/example/bdhandler.cc index 5b3e9b7..faa6afb 100644 --- a/src/example/bdhandler.cc +++ b/src/example/bdhandler.cc @@ -45,7 +45,7 @@ virtual int dhtNodeCallback(const bdId *id, uint32_t 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); } @@ -55,6 +55,16 @@ virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t statu 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: BitDhtHandler *mParent; @@ -187,10 +197,10 @@ int BitDhtHandler::NodeCallback(const bdId *id, uint32_t peerflags) 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: "; - bdStdPrintNodeId(std::cerr, id); + bdStdPrintId(std::cerr, id); std::cerr << std::endl; bool connect = false; diff --git a/src/example/bdhandler.h b/src/example/bdhandler.h index 88ef8bb..e2ad55d 100644 --- a/src/example/bdhandler.h +++ b/src/example/bdhandler.h @@ -55,7 +55,7 @@ bool FindNode(bdNodeId *peerId); bool DropNode(bdNodeId *peerId); 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); private: diff --git a/src/tests/scripts/config.mk b/src/tests/scripts/config.mk index 0859a47..67b25b2 100644 --- a/src/tests/scripts/config.mk +++ b/src/tests/scripts/config.mk @@ -4,8 +4,8 @@ ########################################################################### #Define OS. # -OS = Linux -#OS = MacOSX +#OS = Linux +OS = MacOSX #OS = Cygwin #OS = Win # MinGw. ###########################################################################