Browse Source

small cleanup of net

- remove an unneded else in ConnectNode()
- make 0 a double and change to 0.0 in ConnectNode()
- rename strDest to pszDest in OpenNetworkConnection()
- remove an unneded call to our REF() macro in BindListenPort()
- small style cleanups and removal of unneeded new-lines
0.10
Philip Kaufmann 11 years ago
parent
commit
5bd6c31bd6
  1. 24
      src/net.cpp
  2. 4
      src/net.h

24
src/net.cpp

@ -469,11 +469,10 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest) @@ -469,11 +469,10 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
}
}
/// debug print
LogPrint("net", "trying connection %s lastseen=%.1fhrs\n",
pszDest ? pszDest : addrConnect.ToString(),
pszDest ? 0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
pszDest ? 0.0 : (double)(GetAdjustedTime() - addrConnect.nTime)/3600.0);
// Connect
SOCKET hSocket;
@ -505,10 +504,8 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest) @@ -505,10 +504,8 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest)
pnode->nTimeConnected = GetTime();
return pnode;
}
else
{
return NULL;
}
}
void CNode::CloseSocketDisconnect()
@ -535,7 +532,6 @@ void CNode::Cleanup() @@ -535,7 +532,6 @@ void CNode::Cleanup()
{
}
void CNode::PushVersion()
{
int nBestHeight = g_signals.GetHeight().get_value_or(0);
@ -1425,21 +1421,22 @@ void ThreadOpenAddedConnections() @@ -1425,21 +1421,22 @@ void ThreadOpenAddedConnections()
}
// 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
//
boost::this_thread::interruption_point();
if (!strDest)
if (!pszDest) {
if (IsLocal(addrConnect) ||
FindNode((CNetAddr)addrConnect) || CNode::IsBanned(addrConnect) ||
FindNode(addrConnect.ToStringIPPort().c_str()))
return false;
if (strDest && FindNode(strDest))
}
if (pszDest && FindNode(pszDest))
return false;
CNode* pnode = ConnectNode(addrConnect, strDest);
CNode* pnode = ConnectNode(addrConnect, pszDest);
boost::this_thread::interruption_point();
if (!pnode)
@ -1575,7 +1572,7 @@ bool BindListenPort(const CService &addrBind, string& strError) @@ -1575,7 +1572,7 @@ bool BindListenPort(const CService &addrBind, string& strError)
socklen_t len = sizeof(sockaddr);
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);
return false;
}
@ -1769,9 +1766,8 @@ bool StopNode() @@ -1769,9 +1766,8 @@ bool StopNode()
class CNetCleanup
{
public:
CNetCleanup()
{
}
CNetCleanup() {}
~CNetCleanup()
{
// Close sockets

4
src/net.h

@ -54,11 +54,11 @@ bool GetMyExternalIP(CNetAddr& ipRet); @@ -54,11 +54,11 @@ bool GetMyExternalIP(CNetAddr& ipRet);
void AddressCurrentlyConnected(const CService& addr);
CNode* FindNode(const CNetAddr& 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);
void MapPort(bool fUseUPnP);
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);
bool StopNode();
void SocketSendData(CNode *pnode);

Loading…
Cancel
Save