Browse Source

improve dht node added from bitcoin network peers

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
3a1d772643
  1. 2
      src/main.cpp
  2. 20
      src/twister.cpp
  3. 20
      twister-test.py

2
src/main.cpp

@ -2490,6 +2490,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) @@ -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())

20
src/twister.cpp

@ -189,18 +189,28 @@ void ThreadMaintainDHTNodes() @@ -189,18 +189,28 @@ void ThreadMaintainDHTNodes()
MilliSleep(15000);
if( ses ) {
vector<CAddress> 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<std::string, int>(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<std::string, int>(addr, port));
}
}
}
}

20
twister-test.py

@ -1,7 +1,8 @@ @@ -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]) @@ -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": @@ -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": @@ -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 )

Loading…
Cancel
Save