当前位置: 首页>>代码示例>>C++>>正文


C++ CService::IsRoutable方法代码示例

本文整理汇总了C++中CService::IsRoutable方法的典型用法代码示例。如果您正苦于以下问题:C++ CService::IsRoutable方法的具体用法?C++ CService::IsRoutable怎么用?C++ CService::IsRoutable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CService的用法示例。


在下文中一共展示了CService::IsRoutable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: IsValidNetAddr

bool CMasternode::IsValidNetAddr(CService addrIn)
{
    // TODO: regtest is fine with any addresses for now,
    // should probably be a bit smarter if one day we start to implement tests for this
    return Params().NetworkIDString() == CBaseChainParams::REGTEST ||
            (addrIn.IsIPv4() && IsReachable(addrIn) && addrIn.IsRoutable());
}
开发者ID:Dash3,项目名称:dash,代码行数:7,代码来源:masternode.cpp

示例2: ConnectSocket

bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
{
    SOCKET hSocket = INVALID_SOCKET;
    bool fProxy = (fUseProxy && addrDest.IsRoutable() && !vfNoProxy[addrDest.GetNetwork()]);

    if (!ConnectSocketDirectly(fProxy ? addrProxy : addrDest, hSocket, nTimeout))
        return false;

    if (fProxy)
    {
        switch(nSocksVersion)
        {
            case 4:
                if (!Socks4(addrDest, hSocket))
                    return false;
                break;

            case 5:
            default:
                if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket))
                    return false;
                break;
        }
    }

    hSocketRet = hSocket;
    return true;
}
开发者ID:5mil,项目名称:Pulse,代码行数:28,代码来源:netbase.cpp

示例3: AddLocal

// learn a new local address
bool AddLocal(const CService &addr, int nScore)
{
	if (!addr.IsRoutable())
		return false;

	if (!fDiscover && nScore < LOCAL_MANUAL)
		return false;

	if (IsLimited(addr))
		return false;

	printf("AddLocal(%s,%i)\n", addr.ToString().c_str(), nScore);

	{
		LOCK(cs_mapLocalHost);
		bool fAlready = mapLocalHost.count(addr) > 0;
		LocalServiceInfo &info = mapLocalHost[addr];
		if (!fAlready || nScore >= info.nScore) {
			info.nScore = nScore;
			info.nPort = addr.GetPort() + (fAlready ? 1 : 0);
		}
		SetReachable(addr.GetNetwork());
	}

	AdvertizeLocal();

	return true;
}
开发者ID:66maintainer,项目名称:66coin,代码行数:29,代码来源:net.cpp

示例4: ConnectSocket

	bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
	{
		hSocketRet = INVALID_SOCKET;

		SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		if (hSocket == INVALID_SOCKET)
			return false;
	#ifdef SO_NOSIGPIPE
		int set = 1;
		setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));
	#endif

		bool fProxy = (fUseProxy && addrDest.IsRoutable());
		struct sockaddr_in sockaddr;
		if (fProxy)
			addrProxy.GetSockAddr(&sockaddr);
		else
			addrDest.GetSockAddr(&sockaddr);

	#ifdef WIN32
		u_long fNonblock = 1;
		if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
	#else
		int fFlags = fcntl(hSocket, F_GETFL, 0);
		if (fcntl(hSocket, F_SETFL, fFlags | O_NONBLOCK) == -1)
	#endif
		{
			closesocket(hSocket);
			return false;
		}


		if (connect(hSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR)
		{
			// WSAEINVAL is here because some legacy version of winsock uses it
			if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() == WSAEWOULDBLOCK || WSAGetLastError() == WSAEINVAL)
			{
				struct timeval timeout;
				timeout.tv_sec  = nTimeout / 1000;
				timeout.tv_usec = (nTimeout % 1000) * 1000;

				fd_set fdset;
				FD_ZERO(&fdset);
				FD_SET(hSocket, &fdset);
				int nRet = select(hSocket + 1, NULL, &fdset, NULL, &timeout);
				if (nRet == 0)
				{
					printf("connection timeout\n");
					closesocket(hSocket);
					return false;
				}
				if (nRet == SOCKET_ERROR)
				{
					printf("select() for connection failed: %i\n",WSAGetLastError());
					closesocket(hSocket);
					return false;
				}
				socklen_t nRetSize = sizeof(nRet);
	#ifdef WIN32
				if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (char*)(&nRet), &nRetSize) == SOCKET_ERROR)
	#else
				if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR)
	#endif
				{
					printf("getsockopt() for connection failed: %i\n",WSAGetLastError());
					closesocket(hSocket);
					return false;
				}
				if (nRet != 0)
				{
					printf("connect() failed after select(): %s\n",strerror(nRet));
					closesocket(hSocket);
					return false;
				}
			}
	#ifdef WIN32
			else if (WSAGetLastError() != WSAEISCONN)
	#else
			else
	#endif
			{
				printf("connect() failed: %i\n",WSAGetLastError());
				closesocket(hSocket);
				return false;
			}
		}

		// this isn't even strictly necessary
		// CNode::ConnectNode immediately turns the socket back to non-blocking
		// but we'll turn it back to blocking just in case
	#ifdef WIN32
		fNonblock = 0;
		if (ioctlsocket(hSocket, FIONBIO, &fNonblock) == SOCKET_ERROR)
	#else
		fFlags = fcntl(hSocket, F_GETFL, 0);
		if (fcntl(hSocket, F_SETFL, fFlags & !O_NONBLOCK) == SOCKET_ERROR)
	#endif
		{
			closesocket(hSocket);
			return false;
//.........这里部分代码省略.........
开发者ID:Nexusoft,项目名称:Nexus,代码行数:101,代码来源:netbase.cpp


注:本文中的CService::IsRoutable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。