@@ -115,14 +115,6 @@ static EvoNotificationInterface* pEvoNotificationInterface = nullptr;
115115
116116static const char * DEFAULT_ASMAP_FILENAME=" ip_asn.map" ;
117117
118- /* * Used to pass flags to the Bind() function */
119- enum BindFlags {
120- BF_NONE = 0 ,
121- BF_EXPLICIT = (1U << 0 ),
122- BF_REPORT_ERROR = (1U << 1 ),
123- BF_WHITELIST = (1U << 2 ),
124- };
125-
126118static const char * FEE_ESTIMATES_FILENAME = " fee_estimates.dat" ;
127119CClientUIInterface uiInterface; // Declared but not defined in guiinterface.h
128120
@@ -387,19 +379,6 @@ static void registerSignalHandler(int signal, void(*handler)(int))
387379}
388380#endif
389381
390- bool static Bind (CConnman& connman, const CService& addr, unsigned int flags)
391- {
392- if (!(flags & BF_EXPLICIT) && !IsReachable (addr))
393- return false ;
394- std::string strError;
395- if (!connman.BindListenPort (addr, strError, (flags & BF_WHITELIST) != 0 )) {
396- if (flags & BF_REPORT_ERROR)
397- return UIError (strError);
398- return false ;
399- }
400- return true ;
401- }
402-
403382void OnRPCStarted ()
404383{
405384 uiInterface.NotifyBlockTip .connect (RPCNotifyBlockChange);
@@ -1044,11 +1023,14 @@ bool AppInitParameterInteraction()
10441023 // Make sure enough file descriptors are available
10451024
10461025 // -bind and -whitebind can't be set when not listening
1047- size_t nUserBind = gArgs .GetArgs (" -bind" ).size () + gArgs .GetArgs (" -whitebind" ).size ();
1026+ size_t nUserBind =
1027+ (gArgs .IsArgSet (" -bind" ) ? gArgs .GetArgs (" -bind" ).size () : 0 ) +
1028+ (gArgs .IsArgSet (" -whitebind" ) ? gArgs .GetArgs (" -whitebind" ).size () : 0 );
10481029 if (nUserBind != 0 && !gArgs .GetBoolArg (" -listen" , DEFAULT_LISTEN)) {
10491030 return UIError (strprintf (_ (" Cannot set %s or %s together with %s" ), " -bind" , " -whitebind" , " -listen=0" ));
10501031 }
10511032
1033+ // Make sure enough file descriptors are available
10521034 int nBind = std::max (nUserBind, size_t (1 ));
10531035 nUserMaxConnections = gArgs .GetArg (" -maxconnections" , DEFAULT_MAX_PEER_CONNECTIONS);
10541036 nMaxConnections = std::max (nUserMaxConnections, 0 );
@@ -1440,32 +1422,6 @@ bool AppInitMain()
14401422 fListen = gArgs .GetBoolArg (" -listen" , DEFAULT_LISTEN);
14411423 fDiscover = gArgs .GetBoolArg (" -discover" , true );
14421424
1443- bool fBound = false ;
1444- if (fListen ) {
1445- for (const std::string& strBind : gArgs .GetArgs (" -bind" )) {
1446- CService addrBind;
1447- if (!Lookup (strBind, addrBind, GetListenPort (), false ))
1448- return UIError (ResolveErrMsg (" bind" , strBind));
1449- fBound |= Bind (connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
1450- }
1451- for (const std::string& strBind : gArgs .GetArgs (" -whitebind" )) {
1452- CService addrBind;
1453- if (!Lookup (strBind, addrBind, 0 , false ))
1454- return UIError (ResolveErrMsg (" whitebind" , strBind));
1455- if (addrBind.GetPort () == 0 )
1456- return UIError (strprintf (_ (" Need to specify a port with %s: '%s'" ), " -whitebind" , strBind));
1457- fBound |= Bind (connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST));
1458- }
1459- if (!gArgs .IsArgSet (" -bind" ) && !gArgs .IsArgSet (" -whitebind" )) {
1460- struct in_addr inaddr_any;
1461- inaddr_any.s_addr = INADDR_ANY;
1462- fBound |= Bind (connman, CService ((in6_addr)IN6ADDR_ANY_INIT, GetListenPort ()), BF_NONE);
1463- fBound |= Bind (connman, CService (inaddr_any, GetListenPort ()), !fBound ? BF_REPORT_ERROR : BF_NONE);
1464- }
1465- if (!fBound )
1466- return UIError (strprintf (_ (" Failed to listen on any port. Use %s if you want this." ), " -listen=0" ));
1467- }
1468-
14691425 for (const std::string& strAddr : gArgs .GetArgs (" -externalip" )) {
14701426 CService addrLocal;
14711427 if (Lookup (strAddr, addrLocal, GetListenPort (), fNameLookup ) && addrLocal.IsValid ())
@@ -1963,7 +1919,6 @@ bool AppInitMain()
19631919 // Map ports with UPnP or NAT-PMP
19641920 StartMapPort (gArgs .GetBoolArg (" -upnp" , DEFAULT_UPNP), gArgs .GetBoolArg (" -natpmp" , DEFAULT_NATPMP));
19651921
1966- std::string strNodeError;
19671922 CConnman::Options connOptions;
19681923 connOptions.nLocalServices = nLocalServices;
19691924 connOptions.nRelevantServices = nRelevantServices;
@@ -1977,6 +1932,28 @@ bool AppInitMain()
19771932 connOptions.nSendBufferMaxSize = 1000 *gArgs .GetArg (" -maxsendbuffer" , DEFAULT_MAXSENDBUFFER);
19781933 connOptions.nReceiveFloodSize = 1000 *gArgs .GetArg (" -maxreceivebuffer" , DEFAULT_MAXRECEIVEBUFFER);
19791934
1935+ if (gArgs .IsArgSet (" -bind" )) {
1936+ for (const std::string& strBind : gArgs .GetArgs (" -bind" )) {
1937+ CService addrBind;
1938+ if (!Lookup (strBind, addrBind, GetListenPort (), false )) {
1939+ return UIError (ResolveErrMsg (" bind" , strBind));
1940+ }
1941+ connOptions.vBinds .emplace_back (addrBind);
1942+ }
1943+ }
1944+ if (gArgs .IsArgSet (" -whitebind" )) {
1945+ for (const std::string& strBind : gArgs .GetArgs (" -whitebind" )) {
1946+ CService addrBind;
1947+ if (!Lookup (strBind, addrBind, 0 , false )) {
1948+ return UIError (ResolveErrMsg (" whitebind" , strBind));
1949+ }
1950+ if (addrBind.GetPort () == 0 ) {
1951+ return UIError (strprintf (_ (" Need to specify a port with %s: '%s'" ), " -whitebind" , strBind));
1952+ }
1953+ connOptions.vWhiteBinds .emplace_back (addrBind);
1954+ }
1955+ }
1956+
19801957 for (const auto & net : gArgs .GetArgs (" -whitelist" )) {
19811958 CSubNet subnet;
19821959 LookupSubNet (net, subnet);
@@ -1985,8 +1962,9 @@ bool AppInitMain()
19851962 connOptions.vWhitelistedRange .emplace_back (subnet);
19861963 }
19871964
1988- if (!connman.Start (scheduler, strNodeError, connOptions))
1989- return UIError (strNodeError);
1965+ if (!connman.Start (scheduler, connOptions)) {
1966+ return false ;
1967+ }
19901968
19911969#ifdef ENABLE_WALLET
19921970 // Generate coins in the background (disabled on mainnet. use only wallet 0)
0 commit comments