Merge pull request #1778 from Diapolo/allow_explicit_bind
allow listening on -bind=address for blocked networks
This commit is contained in:
commit
20db1c099e
1 changed files with 18 additions and 16 deletions
34
src/init.cpp
34
src/init.cpp
|
@ -26,6 +26,13 @@ using namespace boost;
|
||||||
CWallet* pwalletMain;
|
CWallet* pwalletMain;
|
||||||
CClientUIInterface uiInterface;
|
CClientUIInterface uiInterface;
|
||||||
|
|
||||||
|
// Used to pass flags to the Bind() function
|
||||||
|
enum BindFlags {
|
||||||
|
BF_NONE = 0,
|
||||||
|
BF_EXPLICIT = 1,
|
||||||
|
BF_REPORT_ERROR = 2
|
||||||
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Shutdown
|
// Shutdown
|
||||||
|
@ -213,12 +220,12 @@ bool static InitWarning(const std::string &str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool static Bind(const CService &addr, bool fError = true) {
|
bool static Bind(const CService &addr, int flags) {
|
||||||
if (IsLimited(addr))
|
if (!(flags & BF_EXPLICIT) && IsLimited(addr))
|
||||||
return false;
|
return false;
|
||||||
std::string strError;
|
std::string strError;
|
||||||
if (!BindListenPort(addr, strError)) {
|
if (!BindListenPort(addr, strError)) {
|
||||||
if (fError)
|
if (flags & BF_REPORT_ERROR)
|
||||||
return InitError(strError);
|
return InitError(strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +258,7 @@ std::string HelpMessage()
|
||||||
" -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n" +
|
" -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\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 if no -proxy or -connect)") + "\n" +
|
" -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n" +
|
||||||
" -bind=<addr> " + _("Bind to given address. Use [host]:port notation for IPv6") + "\n" +
|
" -bind=<addr> " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n" +
|
||||||
" -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n" +
|
" -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n" +
|
||||||
" -banscore=<n> " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
|
" -banscore=<n> " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
|
||||||
" -bantime=<n> " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" +
|
" -bantime=<n> " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" +
|
||||||
|
@ -309,7 +316,6 @@ std::string HelpMessage()
|
||||||
return strUsage;
|
return strUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct CImportingNow
|
struct CImportingNow
|
||||||
{
|
{
|
||||||
CImportingNow() {
|
CImportingNow() {
|
||||||
|
@ -677,32 +683,28 @@ bool AppInit2()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool fBound = false;
|
bool fBound = false;
|
||||||
if (!fNoListen)
|
if (!fNoListen) {
|
||||||
{
|
|
||||||
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;
|
CService addrBind;
|
||||||
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
|
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, (BF_EXPLICIT | BF_REPORT_ERROR));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
struct in_addr inaddr_any;
|
struct in_addr inaddr_any;
|
||||||
inaddr_any.s_addr = INADDR_ANY;
|
inaddr_any.s_addr = INADDR_ANY;
|
||||||
#ifdef USE_IPV6
|
#ifdef USE_IPV6
|
||||||
if (!IsLimited(NET_IPV6))
|
fBound |= Bind(CService(in6addr_any, GetListenPort()), BF_NONE);
|
||||||
fBound |= Bind(CService(in6addr_any, GetListenPort()), false);
|
|
||||||
#endif
|
#endif
|
||||||
if (!IsLimited(NET_IPV4))
|
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE);
|
||||||
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound);
|
|
||||||
}
|
}
|
||||||
if (!fBound)
|
if (!fBound)
|
||||||
return InitError(_("Failed to listen on any port. Use -listen=0 if you want this."));
|
return InitError(_("Failed to listen on any port. Use -listen=0 if you want this."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapArgs.count("-externalip"))
|
if (mapArgs.count("-externalip")) {
|
||||||
{
|
|
||||||
BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"]) {
|
BOOST_FOREACH(string strAddr, mapMultiArgs["-externalip"]) {
|
||||||
CService addrLocal(strAddr, GetListenPort(), fNameLookup);
|
CService addrLocal(strAddr, GetListenPort(), fNameLookup);
|
||||||
if (!addrLocal.IsValid())
|
if (!addrLocal.IsValid())
|
||||||
|
|
Loading…
Add table
Reference in a new issue