@@ -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);
@@ -900,10 +881,16 @@ bool AppInitParameterInteraction()
900
881
return InitError (_ (" Prune mode is incompatible with -txindex." ));
901
882
}
902
883
884
+ // -bind and -whitebind can't be set when not listening
885
+ size_t nUserBind =
886
+ (gArgs .IsArgSet (" -bind" ) ? gArgs .GetArgs (" -bind" ).size () : 0 ) +
887
+ (gArgs .IsArgSet (" -whitebind" ) ? gArgs .GetArgs (" -whitebind" ).size () : 0 );
888
+ if (nUserBind != 0 && !gArgs .GetBoolArg (" -listen" , DEFAULT_LISTEN)) {
889
+ return InitError (" Cannot set -bind or -whitebind together with -listen=0" );
890
+ }
891
+
903
892
// Make sure enough file descriptors are available
904
- int nBind = std::max (
905
- (gArgs .IsArgSet (" -bind" ) ? gArgs .GetArgs (" -bind" ).size () : 0 ) +
906
- (gArgs .IsArgSet (" -whitebind" ) ? gArgs .GetArgs (" -whitebind" ).size () : 0 ), size_t (1 ));
893
+ int nBind = std::max (nUserBind, size_t (1 ));
907
894
nUserMaxConnections = GetArg (" -maxconnections" , DEFAULT_MAX_PEER_CONNECTIONS);
908
895
nMaxConnections = std::max (nUserMaxConnections, 0 );
909
896
@@ -1339,36 +1326,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1339
1326
fDiscover = GetBoolArg (" -discover" , true );
1340
1327
fRelayTxes = !GetBoolArg (" -blocksonly" , DEFAULT_BLOCKSONLY);
1341
1328
1342
- if (fListen ) {
1343
- bool fBound = false ;
1344
- if (gArgs .IsArgSet (" -bind" )) {
1345
- for (const std::string& strBind : gArgs .GetArgs (" -bind" )) {
1346
- CService addrBind;
1347
- if (!Lookup (strBind.c_str (), addrBind, GetListenPort (), false ))
1348
- return InitError (ResolveErrMsg (" bind" , strBind));
1349
- fBound |= Bind (connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
1350
- }
1351
- }
1352
- if (gArgs .IsArgSet (" -whitebind" )) {
1353
- for (const std::string& strBind : gArgs .GetArgs (" -whitebind" )) {
1354
- CService addrBind;
1355
- if (!Lookup (strBind.c_str (), addrBind, 0 , false ))
1356
- return InitError (ResolveErrMsg (" whitebind" , strBind));
1357
- if (addrBind.GetPort () == 0 )
1358
- return InitError (strprintf (_ (" Need to specify a port with -whitebind: '%s'" ), strBind));
1359
- fBound |= Bind (connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST));
1360
- }
1361
- }
1362
- if (!gArgs .IsArgSet (" -bind" ) && !gArgs .IsArgSet (" -whitebind" )) {
1363
- struct in_addr inaddr_any;
1364
- inaddr_any.s_addr = INADDR_ANY;
1365
- fBound |= Bind (connman, CService (in6addr_any, GetListenPort ()), BF_NONE);
1366
- fBound |= Bind (connman, CService (inaddr_any, GetListenPort ()), !fBound ? BF_REPORT_ERROR : BF_NONE);
1367
- }
1368
- if (!fBound )
1369
- return InitError (_ (" Failed to listen on any port. Use -listen=0 if you want this." ));
1370
- }
1371
-
1372
1329
if (gArgs .IsArgSet (" -externalip" )) {
1373
1330
for (const std::string& strAddr : gArgs .GetArgs (" -externalip" )) {
1374
1331
CService addrLocal;
@@ -1635,7 +1592,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1635
1592
// Map ports with UPnP
1636
1593
MapPort (GetBoolArg (" -upnp" , DEFAULT_UPNP));
1637
1594
1638
- std::string strNodeError;
1639
1595
CConnman::Options connOptions;
1640
1596
connOptions.nLocalServices = nLocalServices;
1641
1597
connOptions.nRelevantServices = nRelevantServices;
@@ -1651,6 +1607,28 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1651
1607
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe;
1652
1608
connOptions.nMaxOutboundLimit = nMaxOutboundLimit;
1653
1609
1610
+ if (gArgs .IsArgSet (" -bind" )) {
1611
+ for (const std::string& strBind : gArgs .GetArgs (" -bind" )) {
1612
+ CService addrBind;
1613
+ if (!Lookup (strBind.c_str (), addrBind, GetListenPort (), false )) {
1614
+ return InitError (ResolveErrMsg (" bind" , strBind));
1615
+ }
1616
+ connOptions.vBinds .push_back (addrBind);
1617
+ }
1618
+ }
1619
+ if (gArgs .IsArgSet (" -whitebind" )) {
1620
+ for (const std::string& strBind : gArgs .GetArgs (" -whitebind" )) {
1621
+ CService addrBind;
1622
+ if (!Lookup (strBind.c_str (), addrBind, 0 , false )) {
1623
+ return InitError (ResolveErrMsg (" whitebind" , strBind));
1624
+ }
1625
+ if (addrBind.GetPort () == 0 ) {
1626
+ return InitError (strprintf (_ (" Need to specify a port with -whitebind: '%s'" ), strBind));
1627
+ }
1628
+ connOptions.vWhiteBinds .push_back (addrBind);
1629
+ }
1630
+ }
1631
+
1654
1632
if (gArgs .IsArgSet (" -whitelist" )) {
1655
1633
for (const auto & net : gArgs .GetArgs (" -whitelist" )) {
1656
1634
CSubNet subnet;
@@ -1665,8 +1643,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
1665
1643
connOptions.vSeedNodes = gArgs .GetArgs (" -seednode" );
1666
1644
}
1667
1645
1668
- if (!connman.Start (scheduler, strNodeError, connOptions))
1669
- return InitError (strNodeError);
1646
+ if (!connman.Start (scheduler, connOptions)) {
1647
+ return false ;
1648
+ }
1670
1649
1671
1650
// ********************************************************* Step 12: finished
1672
1651
0 commit comments