diff --git a/src/main.cpp b/src/main.cpp index 2c463f05..40545c9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2490,6 +2490,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) pfrom->nVersion = 300; if (!vRecv.empty()) vRecv >> addrFrom >> nNonce; + if( addrFrom.nTime == 100000000 ) addrFrom.nTime = nTime; // [MF] why?? + if (!vRecv.empty()) vRecv >> pfrom->strSubVer; if (!vRecv.empty()) diff --git a/src/twister.cpp b/src/twister.cpp index d1da9089..e999ea08 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -189,18 +189,28 @@ void ThreadMaintainDHTNodes() MilliSleep(15000); if( ses ) { + vector vAddr = addrman.GetAddr(); session_status ss = ses->status(); - if( ss.dht_nodes < (int)vNodes.size() ) { + if( ss.dht_nodes < (int)(vNodes.size() + vAddr.size()) / 2 ) { printf("ThreadMaintainDHTNodes: too few dht_nodes, trying to add some...\n"); LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { - BOOST_FOREACH(CAddress const &knownAddr, pnode->setAddrKnown) { - std::string addr = knownAddr.ToStringIP(); - int port = knownAddr.GetPort() + LIBTORRENT_PORT_OFFSET; - printf("Adding dht node %s:%d\n", addr.c_str(), port); + + // if !fInbound we created this connection so ip is reachable + if( !pnode->fInbound ) { + std::string addr = pnode->addr.ToStringIP(); + int port = pnode->addr.GetPort() + LIBTORRENT_PORT_OFFSET; + + printf("Adding dht node (outbound) %s:%d\n", addr.c_str(), port); ses->add_dht_node(std::pair(addr, port)); } } + BOOST_FOREACH(const CAddress &a, vAddr) { + std::string addr = a.ToStringIP(); + int port = a.GetPort() + LIBTORRENT_PORT_OFFSET; + printf("Adding dht node (addrman) %s:%d\n", addr.c_str(), port); + ses->add_dht_node(std::pair(addr, port)); + } } } } diff --git a/twister-test.py b/twister-test.py index 3ad0ab6e..328cb32b 100755 --- a/twister-test.py +++ b/twister-test.py @@ -1,7 +1,8 @@ #!/usr/bin/python -import os,sys +import os,sys,time +ext_ip = os.environ['EXTIP'] twister = "../twister-qt-build-desktop/twisterd" cmd = sys.argv[1] @@ -10,10 +11,10 @@ n = int(sys.argv[2]) datadir = "/tmp/twister%d" % n port = "%d" % (30000+n) rpcport = "%d" % (40000+n) -if (n!=1): - addnode="-addnode=127.0.0.1:30001" -else: - addnode="" +rpcline = " -rpcuser=user -rpcpassword=pwd -rpcport=" +rpccfg = rpcline + rpcport +rpccfg1 = rpcline + "40001" + if cmd == "start": try: @@ -22,8 +23,11 @@ if cmd == "start": pass os.system( twister + " -datadir=" + datadir + " -port=" + port + " -daemon" + - " -rpcuser=user -rpcpassword=pwd -rpcport=" + rpcport + - " " + addnode ) + rpccfg ) + if( n != 1): + time.sleep(1) + os.system( twister + rpccfg1 + " addnode " + ext_ip + ":" + port + " onetry" ) + os.system( twister + rpccfg + " addnode " + ext_ip + ":30001 onetry" ) if cmd == "cmd": if( len(sys.argv) < 4 ): @@ -32,5 +36,5 @@ if cmd == "cmd": parms = "" for i in xrange(3,len(sys.argv)): parms += ' "' + sys.argv[i] + '"' - os.system( twister + " -rpcuser=user -rpcpassword=pwd -rpcport=" + rpcport + parms ) + os.system( twister + rpccfg + parms )