@@ -88,14 +88,6 @@ static CZMQNotificationInterface* pzmqNotificationInterface = NULL;
88
88
#define MIN_CORE_FILEDESCRIPTORS 150
89
89
#endif
90
90
91
- /* * Used to pass flags to the Bind() function */
92
- enum BindFlags {
93
- BF_NONE = 0 ,
94
- BF_EXPLICIT = (1U << 0 ),
95
- BF_REPORT_ERROR = (1U << 1 ),
96
- BF_WHITELIST = (1U << 2 ),
97
- };
98
-
99
91
static const char * FEE_ESTIMATES_FILENAME=" fee_estimates.dat" ;
100
92
101
93
// ////////////////////////////////////////////////////////////////////////////
@@ -296,17 +288,6 @@ static void registerSignalHandler(int signal, void(*handler)(int))
296
288
}
297
289
#endif
298
290
299
- bool static Bind (CConnman& connman, const CService &addr, unsigned int flags) {
300
- if (!(flags & BF_EXPLICIT) && IsLimited (addr))
301
- return false ;
302
- std::string strError;
303
- if (!connman.BindListenPort (addr, strError, (flags & BF_WHITELIST) != 0 )) {
304
- if (flags & BF_REPORT_ERROR)
305
- return InitError (strError);
306
- return false ;
307
- }
308
- return true ;
309
- }
310
291
void OnRPCStarted ()
311
292
{
312
293
uiInterface.NotifyBlockTip .connect (&RPCNotifyBlockChange);
@@ -898,10 +879,16 @@ bool AppInitParameterInteraction()
898
879
return InitError (_ (" Prune mode is incompatible with -txindex." ));
899
880
}
900
881
882
+ // -bind and -whitebind can't be set when not listening
883
+ size_t nUserBind =
884
+ (gArgs .IsArgSet (" -bind" ) ? gArgs .GetArgs (" -bind" ).size () : 0 ) +
885
+ (gArgs .IsArgSet (" -whitebind" ) ? gArgs .GetArgs (" -whitebind" ).size () : 0 );
886
+ if (nUserBind != 0 && !gArgs .GetBoolArg (" -listen" , DEFAULT_LISTEN)) {
887
+ return InitError (" Cannot set -bind or -whitebind together with -listen=0" );
888
+ }
889
+
901
890
// Make sure enough file descriptors are available
902
- int nBind = std::max (
903
- (gArgs .IsArgSet (" -bind" ) ? gArgs .GetArgs (" -bind" ).size () : 0 ) +
904
- (gArgs .IsArgSet (" -whitebind" ) ? gArgs .GetArgs (" -whitebind" ).size () : 0 ), size_t (1 ));
891
+ int nBind = std::max (nUserBind, size_t (1 ));
905
892
nUserMaxConnections = GetArg (" -maxconnections" , DEFAULT_MAX_PEER_CONNECTIONS);
906
893
nMaxConnections = std::max (nUserMaxConnections, 0 );
907
894
@@ -1280,16 +1267,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1280
1267
}
1281
1268
}
1282
1269
1283
- if (gArgs .IsArgSet (" -whitelist" )) {
1284
- for (const std::string& net : gArgs .GetArgs (" -whitelist" )) {
1285
- CSubNet subnet;
1286
- LookupSubNet (net.c_str (), subnet);
1287
- if (!subnet.IsValid ())
1288
- return InitError (strprintf (_ (" Invalid netmask specified in -whitelist: '%s'" ), net));
1289
- connman.AddWhitelistedRange (subnet);
1290
- }
1291
- }
1292
-
1293
1270
// Check for host lookup allowed before parsing any network related parameters
1294
1271
fNameLookup = GetBoolArg (" -dns" , DEFAULT_NAME_LOOKUP);
1295
1272
@@ -1340,36 +1317,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1340
1317
fDiscover = GetBoolArg (" -discover" , true );
1341
1318
fRelayTxes = !GetBoolArg (" -blocksonly" , DEFAULT_BLOCKSONLY);
1342
1319
1343
- if (fListen ) {
1344
- bool fBound = false ;
1345
- if (gArgs .IsArgSet (" -bind" )) {
1346
- for (const std::string& strBind : gArgs .GetArgs (" -bind" )) {
1347
- CService addrBind;
1348
- if (!Lookup (strBind.c_str (), addrBind, GetListenPort (), false ))
1349
- return InitError (ResolveErrMsg (" bind" , strBind));
1350
- fBound |= Bind (connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
1351
- }
1352
- }
1353
- if (gArgs .IsArgSet (" -whitebind" )) {
1354
- for (const std::string& strBind : gArgs .GetArgs (" -whitebind" )) {
1355
- CService addrBind;
1356
- if (!Lookup (strBind.c_str (), addrBind, 0 , false ))
1357
- return InitError (ResolveErrMsg (" whitebind" , strBind));
1358
- if (addrBind.GetPort () == 0 )
1359
- return InitError (strprintf (_ (" Need to specify a port with -whitebind: '%s'" ), strBind));
1360
- fBound |= Bind (connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST));
1361
- }
1362
- }
1363
- if (!gArgs .IsArgSet (" -bind" ) && !gArgs .IsArgSet (" -whitebind" )) {
1364
- struct in_addr inaddr_any;
1365
- inaddr_any.s_addr = INADDR_ANY;
1366
- fBound |= Bind (connman, CService (in6addr_any, GetListenPort ()), BF_NONE);
1367
- fBound |= Bind (connman, CService (inaddr_any, GetListenPort ()), !fBound ? BF_REPORT_ERROR : BF_NONE);
1368
- }
1369
- if (!fBound )
1370
- return InitError (_ (" Failed to listen on any port. Use -listen=0 if you want this." ));
1371
- }
1372
-
1373
1320
if (gArgs .IsArgSet (" -externalip" )) {
1374
1321
for (const std::string& strAddr : gArgs .GetArgs (" -externalip" )) {
1375
1322
CService addrLocal;
@@ -1636,7 +1583,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1636
1583
// Map ports with UPnP
1637
1584
MapPort (GetBoolArg (" -upnp" , DEFAULT_UPNP));
1638
1585
1639
- std::string strNodeError;
1640
1586
CConnman::Options connOptions;
1641
1587
connOptions.nLocalServices = nLocalServices;
1642
1588
connOptions.nRelevantServices = nRelevantServices;
@@ -1652,12 +1598,45 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1652
1598
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe;
1653
1599
connOptions.nMaxOutboundLimit = nMaxOutboundLimit;
1654
1600
1601
+ if (gArgs .IsArgSet (" -bind" )) {
1602
+ for (const std::string& strBind : gArgs .GetArgs (" -bind" )) {
1603
+ CService addrBind;
1604
+ if (!Lookup (strBind.c_str (), addrBind, GetListenPort (), false )) {
1605
+ return InitError (ResolveErrMsg (" bind" , strBind));
1606
+ }
1607
+ connOptions.vBinds .push_back (addrBind);
1608
+ }
1609
+ }
1610
+ if (gArgs .IsArgSet (" -whitebind" )) {
1611
+ for (const std::string& strBind : gArgs .GetArgs (" -whitebind" )) {
1612
+ CService addrBind;
1613
+ if (!Lookup (strBind.c_str (), addrBind, 0 , false )) {
1614
+ return InitError (ResolveErrMsg (" whitebind" , strBind));
1615
+ }
1616
+ if (addrBind.GetPort () == 0 ) {
1617
+ return InitError (strprintf (_ (" Need to specify a port with -whitebind: '%s'" ), strBind));
1618
+ }
1619
+ connOptions.vWhiteBinds .push_back (addrBind);
1620
+ }
1621
+ }
1622
+
1623
+ if (gArgs .IsArgSet (" -whitelist" )) {
1624
+ for (const auto & net : gArgs .GetArgs (" -whitelist" )) {
1625
+ CSubNet subnet;
1626
+ LookupSubNet (net.c_str (), subnet);
1627
+ if (!subnet.IsValid ())
1628
+ return InitError (strprintf (_ (" Invalid netmask specified in -whitelist: '%s'" ), net));
1629
+ connOptions.vWhitelistedRange .push_back (subnet);
1630
+ }
1631
+ }
1632
+
1655
1633
if (gArgs .IsArgSet (" -seednode" )) {
1656
1634
connOptions.vSeedNodes = gArgs .GetArgs (" -seednode" );
1657
1635
}
1658
1636
1659
- if (!connman.Start (scheduler, strNodeError, connOptions))
1660
- return InitError (strNodeError);
1637
+ if (!connman.Start (scheduler, connOptions)) {
1638
+ return false ;
1639
+ }
1661
1640
1662
1641
// ********************************************************* Step 12: finished
1663
1642
0 commit comments