Merge pull request #1299 from sipa/ipv6fixes

A few more IPv6-related improvements
This commit is contained in:
Gregory Maxwell 2012-05-14 09:22:03 -07:00
commit a6f18e4686
3 changed files with 28 additions and 12 deletions

View File

@ -204,7 +204,7 @@ std::string HelpMessage()
" -connect=<ip> " + _("Connect only to the specified node") + "\n" + " -connect=<ip> " + _("Connect only to the specified node") + "\n" +
" -seednode=<ip> " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n" + " -seednode=<ip> " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n" +
" -externalip=<ip> " + _("Specify your own public address") + "\n" + " -externalip=<ip> " + _("Specify your own public address") + "\n" +
" -blocknet=<net> " + _("Do not connect to addresses in network <net> (IPv4 or IPv6)") + "\n" + " -onlynet=<net> " + _("Only connect to nodes in network <net> (IPv4 or IPv6)") + "\n" +
" -discover " + _("Try to discover public IP address (default: 1)") + "\n" + " -discover " + _("Try to discover public IP address (default: 1)") + "\n" +
" -irc " + _("Find peers using internet relay chat (default: 0)") + "\n" + " -irc " + _("Find peers using internet relay chat (default: 0)") + "\n" +
" -listen " + _("Accept connections from outside (default: 1)") + "\n" + " -listen " + _("Accept connections from outside (default: 1)") + "\n" +
@ -572,11 +572,17 @@ bool AppInit2()
SoftSetBoolArg("-discover", false); SoftSetBoolArg("-discover", false);
} }
if (mapArgs.count("-blocknet")) { if (mapArgs.count("-onlynet")) {
BOOST_FOREACH(std::string snet, mapMultiArgs["-blocknet"]) { std::set<enum Network> nets;
BOOST_FOREACH(std::string snet, mapMultiArgs["-onlynet"]) {
enum Network net = ParseNetwork(snet); enum Network net = ParseNetwork(snet);
if (net == NET_UNROUTABLE) if (net == NET_UNROUTABLE)
return InitError(strprintf(_("Unknown network specified in -blocknet: '%s'"), snet.c_str())); return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet.c_str()));
nets.insert(net);
}
for (int n = 0; n < NET_MAX; n++) {
enum Network net = (enum Network)n;
if (!nets.count(net))
SetLimited(net); SetLimited(net);
} }
} }
@ -605,21 +611,23 @@ bool AppInit2()
std::string strError; std::string strError;
if (mapArgs.count("-bind")) { if (mapArgs.count("-bind")) {
BOOST_FOREACH(std::string strBind, mapMultiArgs["-bind"]) { BOOST_FOREACH(std::string strBind, mapMultiArgs["-bind"]) {
CService addrBind(strBind, GetListenPort(), false); CService addrBind;
if (!addrBind.IsValid()) if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
return InitError(strprintf(_("Cannot resolve -bind address: '%s'"), strBind.c_str())); return InitError(strprintf(_("Cannot resolve -bind address: '%s'"), strBind.c_str()));
fBound |= Bind(addrBind); fBound |= Bind(addrBind);
} }
} else { } else {
struct in_addr inaddr_any; struct in_addr inaddr_any;
inaddr_any.s_addr = INADDR_ANY; inaddr_any.s_addr = INADDR_ANY;
if (!IsLimited(NET_IPV4))
fBound |= Bind(CService(inaddr_any, GetListenPort())); fBound |= Bind(CService(inaddr_any, GetListenPort()));
#ifdef USE_IPV6 #ifdef USE_IPV6
if (!IsLimited(NET_IPV6))
fBound |= Bind(CService(in6addr_any, GetListenPort())); fBound |= Bind(CService(in6addr_any, GetListenPort()));
#endif #endif
} }
if (!fBound) if (!fBound)
return false; return InitError(_("Not listening on any port"));
} }
if (mapArgs.count("-externalip")) if (mapArgs.count("-externalip"))

View File

@ -245,14 +245,21 @@ bool AddLocal(const CNetAddr &addr, int nScore)
/** Make a particular network entirely off-limits (no automatic connects to it) */ /** Make a particular network entirely off-limits (no automatic connects to it) */
void SetLimited(enum Network net, bool fLimited) void SetLimited(enum Network net, bool fLimited)
{ {
if (net == NET_UNROUTABLE)
return;
LOCK(cs_mapLocalHost); LOCK(cs_mapLocalHost);
vfLimited[net] = fLimited; vfLimited[net] = fLimited;
} }
bool IsLimited(const CNetAddr& addr) bool IsLimited(enum Network net)
{ {
LOCK(cs_mapLocalHost); LOCK(cs_mapLocalHost);
return vfLimited[addr.GetNetwork()]; return vfLimited[net];
}
bool IsLimited(const CNetAddr &addr)
{
return IsLimited(addr.GetNetwork());
} }
/** vote for a local address */ /** vote for a local address */

View File

@ -57,6 +57,7 @@ enum
}; };
void SetLimited(enum Network net, bool fLimited = true); void SetLimited(enum Network net, bool fLimited = true);
bool IsLimited(enum Network net);
bool IsLimited(const CNetAddr& addr); bool IsLimited(const CNetAddr& addr);
bool AddLocal(const CService& addr, int nScore = LOCAL_NONE); bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE); bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);