net: Add -natpmp command line option
This commit is contained in:
9 files changed
+49
-14
No files matched your search
+14
-3
@@ -469,6 +469,11 @@ void SetupServerArgs(NodeContext& node)
|
|||||||
#else
|
#else
|
||||||
hidden_args.emplace_back("-upnp");
|
hidden_args.emplace_back("-upnp");
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_NATPMP
|
||||||
|
argsman.AddArg("-natpmp", strprintf("Use NAT-PMP to map the listening port (default: %s)", DEFAULT_NATPMP ? "1 when listening and no -proxy" : "0"), ArgsManager::ALLOW_BOOL, OptionsCategory::CONNECTION);
|
||||||
|
#else
|
||||||
|
hidden_args.emplace_back("-natpmp");
|
||||||
|
#endif // USE_NATPMP
|
||||||
argsman.AddArg("-whitebind=<[permissions@]addr>", "Bind to the given address and add permission flags to the peers connecting to it. "
|
argsman.AddArg("-whitebind=<[permissions@]addr>", "Bind to the given address and add permission flags to the peers connecting to it. "
|
||||||
"Use [host]:port notation for IPv6. Allowed permissions: " + Join(NET_PERMISSIONS_DOC, ", ") + ". "
|
"Use [host]:port notation for IPv6. Allowed permissions: " + Join(NET_PERMISSIONS_DOC, ", ") + ". "
|
||||||
"Specify multiple permissions separated by commas (default: download,noban,mempool,relay). Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
"Specify multiple permissions separated by commas (default: download,noban,mempool,relay). Can be specified multiple times.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
|
||||||
@@ -813,10 +818,13 @@ void InitParameterInteraction(ArgsManager& args)
|
|||||||
// to protect privacy, do not listen by default if a default proxy server is specified
|
// to protect privacy, do not listen by default if a default proxy server is specified
|
||||||
if (args.SoftSetBoolArg("-listen", false))
|
if (args.SoftSetBoolArg("-listen", false))
|
||||||
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
|
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
|
||||||
// to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
|
// to protect privacy, do not map ports when a proxy is set. The user may still specify -listen=1
|
||||||
// to listen locally, so don't rely on this happening through -listen below.
|
// to listen locally, so don't rely on this happening through -listen below.
|
||||||
if (args.SoftSetBoolArg("-upnp", false))
|
if (args.SoftSetBoolArg("-upnp", false))
|
||||||
LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
|
LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
|
||||||
|
if (args.SoftSetBoolArg("-natpmp", false)) {
|
||||||
|
LogPrintf("%s: parameter interaction: -proxy set -> setting -natpmp=0\n", __func__);
|
||||||
|
}
|
||||||
// to protect privacy, do not discover addresses by default
|
// to protect privacy, do not discover addresses by default
|
||||||
if (args.SoftSetBoolArg("-discover", false))
|
if (args.SoftSetBoolArg("-discover", false))
|
||||||
LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
|
LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
|
||||||
@@ -826,6 +834,9 @@ void InitParameterInteraction(ArgsManager& args)
|
|||||||
// do not map ports or try to retrieve public IP when not listening (pointless)
|
// do not map ports or try to retrieve public IP when not listening (pointless)
|
||||||
if (args.SoftSetBoolArg("-upnp", false))
|
if (args.SoftSetBoolArg("-upnp", false))
|
||||||
LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
|
LogPrintf("%s: parameter interaction: -listen=0 -> setting -upnp=0\n", __func__);
|
||||||
|
if (args.SoftSetBoolArg("-natpmp", false)) {
|
||||||
|
LogPrintf("%s: parameter interaction: -listen=0 -> setting -natpmp=0\n", __func__);
|
||||||
|
}
|
||||||
if (args.SoftSetBoolArg("-discover", false))
|
if (args.SoftSetBoolArg("-discover", false))
|
||||||
LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
|
LogPrintf("%s: parameter interaction: -listen=0 -> setting -discover=0\n", __func__);
|
||||||
if (args.SoftSetBoolArg("-listenonion", false))
|
if (args.SoftSetBoolArg("-listenonion", false))
|
||||||
@@ -1899,8 +1910,8 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
|||||||
|
|
||||||
Discover();
|
Discover();
|
||||||
|
|
||||||
// Map ports with UPnP
|
// Map ports with UPnP or NAT-PMP.
|
||||||
StartMapPort(args.GetBoolArg("-upnp", DEFAULT_UPNP));
|
StartMapPort(args.GetBoolArg("-upnp", DEFAULT_UPNP), gArgs.GetBoolArg("-natpmp", DEFAULT_NATPMP));
|
||||||
|
|
||||||
CConnman::Options connOptions;
|
CConnman::Options connOptions;
|
||||||
connOptions.nLocalServices = nLocalServices;
|
connOptions.nLocalServices = nLocalServices;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public:
|
|||||||
virtual bool shutdownRequested() = 0;
|
virtual bool shutdownRequested() = 0;
|
||||||
|
|
||||||
//! Map port.
|
//! Map port.
|
||||||
virtual void mapPort(bool use_upnp) = 0;
|
virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
|
||||||
|
|
||||||
//! Get proxy.
|
//! Get proxy.
|
||||||
virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
|
virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
|
||||||
|
|||||||
+3
-2
@@ -297,9 +297,10 @@ static void MapPortProtoSetEnabled(MapPortProtoFlag proto, bool enabled)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartMapPort(bool use_upnp)
|
void StartMapPort(bool use_upnp, bool use_natpmp)
|
||||||
{
|
{
|
||||||
MapPortProtoSetEnabled(MapPortProtoFlag::UPNP, use_upnp);
|
MapPortProtoSetEnabled(MapPortProtoFlag::UPNP, use_upnp);
|
||||||
|
MapPortProtoSetEnabled(MapPortProtoFlag::NAT_PMP, use_natpmp);
|
||||||
DispatchMapPort();
|
DispatchMapPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +321,7 @@ void StopMapPort()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else // #if defined(USE_NATPMP) || defined(USE_UPNP)
|
#else // #if defined(USE_NATPMP) || defined(USE_UPNP)
|
||||||
void StartMapPort(bool use_upnp)
|
void StartMapPort(bool use_upnp, bool use_natpmp)
|
||||||
{
|
{
|
||||||
// Intentionally left blank.
|
// Intentionally left blank.
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-5
@@ -5,12 +5,17 @@
|
|||||||
#ifndef BITCOIN_MAPPORT_H
|
#ifndef BITCOIN_MAPPORT_H
|
||||||
#define BITCOIN_MAPPORT_H
|
#define BITCOIN_MAPPORT_H
|
||||||
|
|
||||||
/** -upnp default */
|
|
||||||
#ifdef USE_UPNP
|
#ifdef USE_UPNP
|
||||||
static const bool DEFAULT_UPNP = USE_UPNP;
|
static constexpr bool DEFAULT_UPNP = USE_UPNP;
|
||||||
#else
|
#else
|
||||||
static const bool DEFAULT_UPNP = false;
|
static constexpr bool DEFAULT_UPNP = false;
|
||||||
#endif
|
#endif // USE_UPNP
|
||||||
|
|
||||||
|
#ifdef USE_NATPMP
|
||||||
|
static constexpr bool DEFAULT_NATPMP = USE_NATPMP;
|
||||||
|
#else
|
||||||
|
static constexpr bool DEFAULT_NATPMP = false;
|
||||||
|
#endif // USE_NATPMP
|
||||||
|
|
||||||
enum MapPortProtoFlag : unsigned int {
|
enum MapPortProtoFlag : unsigned int {
|
||||||
NONE = 0x00,
|
NONE = 0x00,
|
||||||
@@ -18,7 +23,7 @@ enum MapPortProtoFlag : unsigned int {
|
|||||||
NAT_PMP = 0x02,
|
NAT_PMP = 0x02,
|
||||||
};
|
};
|
||||||
|
|
||||||
void StartMapPort(bool use_upnp);
|
void StartMapPort(bool use_upnp, bool use_natpmp);
|
||||||
void InterruptMapPort();
|
void InterruptMapPort();
|
||||||
void StopMapPort();
|
void StopMapPort();
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||||
void mapPort(bool use_upnp) override { StartMapPort(use_upnp); }
|
void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
|
||||||
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
|
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
|
||||||
size_t getNodeCount(CConnman::NumConnections flags) override
|
size_t getNodeCount(CConnman::NumConnections flags) override
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
|
|||||||
#endif
|
#endif
|
||||||
connect(this, &QDialog::accepted, [this](){
|
connect(this, &QDialog::accepted, [this](){
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
model->node().mapPort(settings.value("fUseUPnP").toBool());
|
model->node().mapPort(settings.value("fUseUPnP").toBool(), settings.value("fUseNatpmp").toBool());
|
||||||
});
|
});
|
||||||
|
|
||||||
ui->proxyIp->setEnabled(false);
|
ui->proxyIp->setEnabled(false);
|
||||||
|
|||||||
+17
-1
@@ -124,6 +124,13 @@ void OptionsModel::Init(bool resetSettings)
|
|||||||
if (!gArgs.SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
|
if (!gArgs.SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
|
||||||
addOverriddenOption("-upnp");
|
addOverriddenOption("-upnp");
|
||||||
|
|
||||||
|
if (!settings.contains("fUseNatpmp")) {
|
||||||
|
settings.setValue("fUseNatpmp", DEFAULT_NATPMP);
|
||||||
|
}
|
||||||
|
if (!gArgs.SoftSetBoolArg("-natpmp", settings.value("fUseNatpmp").toBool())) {
|
||||||
|
addOverriddenOption("-natpmp");
|
||||||
|
}
|
||||||
|
|
||||||
if (!settings.contains("fListen"))
|
if (!settings.contains("fListen"))
|
||||||
settings.setValue("fListen", DEFAULT_LISTEN);
|
settings.setValue("fListen", DEFAULT_LISTEN);
|
||||||
if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool()))
|
if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool()))
|
||||||
@@ -283,7 +290,13 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
|||||||
return settings.value("fUseUPnP");
|
return settings.value("fUseUPnP");
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif // USE_UPNP
|
||||||
|
case MapPortNatpmp:
|
||||||
|
#ifdef USE_NATPMP
|
||||||
|
return settings.value("fUseNatpmp");
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif // USE_NATPMP
|
||||||
case MinimizeOnClose:
|
case MinimizeOnClose:
|
||||||
return fMinimizeOnClose;
|
return fMinimizeOnClose;
|
||||||
|
|
||||||
@@ -356,6 +369,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
|||||||
case MapPortUPnP: // core option - can be changed on-the-fly
|
case MapPortUPnP: // core option - can be changed on-the-fly
|
||||||
settings.setValue("fUseUPnP", value.toBool());
|
settings.setValue("fUseUPnP", value.toBool());
|
||||||
break;
|
break;
|
||||||
|
case MapPortNatpmp: // core option - can be changed on-the-fly
|
||||||
|
settings.setValue("fUseNatpmp", value.toBool());
|
||||||
|
break;
|
||||||
case MinimizeOnClose:
|
case MinimizeOnClose:
|
||||||
fMinimizeOnClose = value.toBool();
|
fMinimizeOnClose = value.toBool();
|
||||||
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
|
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
ShowTrayIcon, // bool
|
ShowTrayIcon, // bool
|
||||||
MinimizeToTray, // bool
|
MinimizeToTray, // bool
|
||||||
MapPortUPnP, // bool
|
MapPortUPnP, // bool
|
||||||
|
MapPortNatpmp, // bool
|
||||||
MinimizeOnClose, // bool
|
MinimizeOnClose, // bool
|
||||||
ProxyUse, // bool
|
ProxyUse, // bool
|
||||||
ProxyIP, // QString
|
ProxyIP, // QString
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ def initialize_datadir(dirname, n, chain):
|
|||||||
f.write("listenonion=0\n")
|
f.write("listenonion=0\n")
|
||||||
f.write("printtoconsole=0\n")
|
f.write("printtoconsole=0\n")
|
||||||
f.write("upnp=0\n")
|
f.write("upnp=0\n")
|
||||||
|
f.write("natpmp=0\n")
|
||||||
f.write("shrinkdebugfile=0\n")
|
f.write("shrinkdebugfile=0\n")
|
||||||
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
|
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
|
||||||
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
|
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
|
||||||
|
|||||||
Reference in new issue
Block a user