Merge pull request #4227

634bd61 convert an if into an else if in OpenNetworkConnection() (Philip Kaufmann)
5bd6c31 small cleanup of net (Philip Kaufmann)
This commit is contained in:
Wladimir J. van der Laan 2014-06-11 13:00:28 +02:00
commit 9c8d2f6df0
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
2 changed files with 12 additions and 17 deletions

View File

@ -469,11 +469,10 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
} }
} }
/// debug print /// debug print
LogPrint("net", "trying connection %s lastseen=%.1fhrs\n", LogPrint("net", "trying connection %s lastseen=%.1fhrs\n",
pszDest ? pszDest : addrConnect.ToString(), pszDest ? pszDest : addrConnect.ToString(),
pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0); pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
// Connect // Connect
SOCKET hSocket; SOCKET hSocket;
@ -505,10 +504,8 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
pnode->nTimeConnected = GetTime(); pnode->nTimeConnected = GetTime();
return pnode; return pnode;
} }
else
{ return NULL;
return NULL;
}
} }
void CNode::CloseSocketDisconnect() void CNode::CloseSocketDisconnect()
@ -535,7 +532,6 @@ void CNode::Cleanup()
{ {
} }
void CNode::PushVersion() void CNode::PushVersion()
{ {
int nBestHeight = g_signals.GetHeight().get_value_or(0); int nBestHeight = g_signals.GetHeight().get_value_or(0);
@ -1425,21 +1421,21 @@ void ThreadOpenAddedConnections()
} }
// if successful, this moves the passed grant to the constructed node // if successful, this moves the passed grant to the constructed node
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *strDest, bool fOneShot) bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound, const char *pszDest, bool fOneShot)
{ {
// //
// Initiate outbound network connection // Initiate outbound network connection
// //
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
if (!strDest) if (!pszDest) {
if (IsLocal(addrConnect) || if (IsLocal(addrConnect) ||
FindNode((CNetAddr)addrConnect) || CNode::IsBanned(addrConnect) || FindNode((CNetAddr)addrConnect) || CNode::IsBanned(addrConnect) ||
FindNode(addrConnect.ToStringIPPort().c_str())) FindNode(addrConnect.ToStringIPPort().c_str()))
return false; return false;
if (strDest && FindNode(strDest)) } else if (FindNode(pszDest))
return false; return false;
CNode* pnode = ConnectNode(addrConnect, strDest); CNode* pnode = ConnectNode(addrConnect, pszDest);
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
if (!pnode) if (!pnode)
@ -1575,7 +1571,7 @@ bool BindListenPort(const CService &addrBind, string& strError)
socklen_t len = sizeof(sockaddr); socklen_t len = sizeof(sockaddr);
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len)) if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
{ {
strError = strprintf("Error: bind address family for %s not supported", addrBind.ToString()); strError = strprintf("Error: Bind address family for %s not supported", addrBind.ToString());
LogPrintf("%s\n", strError); LogPrintf("%s\n", strError);
return false; return false;
} }
@ -1769,9 +1765,8 @@ bool StopNode()
class CNetCleanup class CNetCleanup
{ {
public: public:
CNetCleanup() CNetCleanup() {}
{
}
~CNetCleanup() ~CNetCleanup()
{ {
// Close sockets // Close sockets

View File

@ -56,11 +56,11 @@ bool GetMyExternalIP(CNetAddr& ipRet);
void AddressCurrentlyConnected(const CService& addr); void AddressCurrentlyConnected(const CService& addr);
CNode* FindNode(const CNetAddr& ip); CNode* FindNode(const CNetAddr& ip);
CNode* FindNode(const CService& ip); CNode* FindNode(const CService& ip);
CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL); CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL);
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false); bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
void MapPort(bool fUseUPnP); void MapPort(bool fUseUPnP);
unsigned short GetListenPort(); unsigned short GetListenPort();
bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string())); bool BindListenPort(const CService &bindAddr, std::string& strError);
void StartNode(boost::thread_group& threadGroup); void StartNode(boost::thread_group& threadGroup);
bool StopNode(); bool StopNode();
void SocketSendData(CNode *pnode); void SocketSendData(CNode *pnode);