new rpc adddnsseed

This commit is contained in:
Miguel Freitas 2013-11-10 11:54:22 -02:00
parent a2c87535c0
commit bd479f0b2e
5 changed files with 40 additions and 4 deletions

View File

@ -204,6 +204,7 @@ static const CRPCCommand vRPCCommands[] =
{ "getconnectioncount", &getconnectioncount, true, false },
{ "getpeerinfo", &getpeerinfo, true, false },
{ "addnode", &addnode, true, true },
{ "adddnsseed", &adddnsseed, true, true },
{ "getaddednodeinfo", &getaddednodeinfo, true, true },
{ "getdifficulty", &getdifficulty, true, false },
{ "getgenerate", &getgenerate, true, false },

View File

@ -143,6 +143,7 @@ extern void EnsureWalletIsUnlocked();
extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value adddnsseed(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp

View File

@ -1174,11 +1174,17 @@ void MapPort(bool)
void ThreadDNSAddressSeed()
void _ThreadDNSAddressSeed(const char *strDNS)
{
const vector<CDNSSeedData> &vSeeds = Params().DNSSeeds();
vector<CDNSSeedData> vSeeds = Params().DNSSeeds();
int found = 0;
if( strDNS ) {
printf("ThreadDNSAddressSeed: %s\n", strDNS);
vSeeds.clear();
vSeeds.push_back(CDNSSeedData(strDNS, strDNS));
}
printf("Loading addresses from DNS seeds (could take a while)\n");
BOOST_FOREACH(const CDNSSeedData &seed, vSeeds) {
@ -1203,10 +1209,24 @@ void ThreadDNSAddressSeed()
}
printf("%d addresses found from DNS seeds\n", found);
if( strDNS ) {
delete [] strDNS;
}
}
void ThreadDNSAddressSeed()
{
_ThreadDNSAddressSeed(NULL);
}
void AddDNSandRunThread(std::string strDNS)
{
boost::thread_group threadGroup;
char *strCopyOfDNS = new char [strDNS.length()+1];
strcpy(strCopyOfDNS, strDNS.c_str());
threadGroup.create_thread(boost::bind(_ThreadDNSAddressSeed, strCopyOfDNS));
}

View File

@ -82,7 +82,7 @@ bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
bool IsReachable(const CNetAddr &addr);
void SetReachable(enum Network net, bool fFlag = true);
CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL);
void AddDNSandRunThread(std::string strDNS);
extern bool fDiscover;
extern uint64 nLocalServices;

View File

@ -110,6 +110,20 @@ Value addnode(const Array& params, bool fHelp)
return Value::null;
}
Value adddnsseed(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1 )
throw runtime_error(
"adddnsseed <seeder>\n"
"Add a different DNS <seeder> to obtain node list from.");
string strDNS = params[0].get_str();
AddDNSandRunThread(strDNS);
return Value::null;
}
Value getaddednodeinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)