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


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

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


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

示例1: ThreadIRCSeed2

void ThreadIRCSeed2(void* parg)
{
    // Don't connect to IRC if we won't use IPv4 connections.
    if (IsLimited(NET_IPV4))
        return;

    // ... or if we won't make outbound connections and won't accept inbound ones.
    if (mapArgs.count("-connect") && fNoListen)
        return;

    // ... or if IRC is not enabled.
    if (!GetBoolArg("-irc", false))
        return;

    printf("ThreadIRCSeed started\n");
    int nErrorWait = 10;
    int nRetryWait = 10;
    int nNameRetry = 0;

    while (!fShutdown)
    {
        CService addrConnect("92.243.23.21", 6667); // irc.lfnet.org

        CService addrIRC("irc.lfnet.org", 6667, true);
        if (addrIRC.IsValid())
            addrConnect = addrIRC;

        SOCKET hSocket;
        if (!ConnectSocket(addrConnect, hSocket))
        {
            printf("IRC connect failed\n");
            nErrorWait = nErrorWait * 11 / 10;
            if (Wait(nErrorWait += 60))
                continue;
            else
                return;
        }

        if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname", "ignoring hostname"))
        {
            closesocket(hSocket);
            hSocket = INVALID_SOCKET;
            nErrorWait = nErrorWait * 11 / 10;
            if (Wait(nErrorWait += 60))
                continue;
            else
                return;
        }

        CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses
        CService addrLocal;
        string strMyName;
        // Don't use our IP as our nick if we're not listening
        // or if it keeps failing because the nick is already in use.
        if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3)
            strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
        if (strMyName == "")
            strMyName = strprintf("x%"PRIu64"", GetRand(1000000000));

        Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
        Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str());

        int nRet = RecvUntil(hSocket, " 004 ", " 433 ");
        if (nRet != 1)
        {
            closesocket(hSocket);
            hSocket = INVALID_SOCKET;
            if (nRet == 2)
            {
                printf("IRC name already in use\n");
                nNameRetry++;
                Wait(10);
                continue;
            }
            nErrorWait = nErrorWait * 11 / 10;
            if (Wait(nErrorWait += 60))
                continue;
            else
                return;
        }
        nNameRetry = 0;
        MilliSleep(500);

        // Get our external IP from the IRC server and re-nick before joining the channel
        CNetAddr addrFromIRC;
        if (GetIPFromIRC(hSocket, strMyName, addrFromIRC))
        {
            printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str());
            // Don't use our IP as our nick if we're not listening
            if (!fNoListen && addrFromIRC.IsRoutable())
            {
                // IRC lets you to re-nick
                AddLocal(addrFromIRC, LOCAL_IRC);
                strMyName = EncodeAddress(GetLocalAddress(&addrConnect));
                Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
            }
        }

        if (fTestNet) {
            Send(hSocket, "JOIN #WebcoinTEST\r");
//.........这里部分代码省略.........
开发者ID:webcoinx14,项目名称:Webcoin,代码行数:101,代码来源:irc.cpp

示例2: ThreadIRCSeed2

void ThreadIRCSeed2(void* parg)
{
  /* Dont advertise on IRC if we don't allow incoming connections */
  if(mapArgs.count("-connect") || fNoListen)
    return;

  if(!GetBoolArg("-irc", false))
    return;

  printf("ThreadIRCSeed started\n");
  int nErrorWait = 10;
  int nRetryWait = 10;
  bool fNameInUse = false;

  while(!fShutdown)
  {
    CService addrConnect("92.243.23.21", 6667); // irc.lfnet.org

    CService addrIRC("irc.lfnet.org", 6667, true);
    if(addrIRC.IsValid())
      addrConnect = addrIRC;

    SOCKET hSocket;
    if(!ConnectSocket(addrConnect, hSocket))
    {
      printf("IRC connect failed\n");
      nErrorWait = nErrorWait * 11 / 10;
      if(Wait(nErrorWait += 60))
        continue;
      else
        return;
    }

    if(!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname", "ignoring hostname"))
    {
      closesocket(hSocket);
      hSocket = INVALID_SOCKET;
      nErrorWait = nErrorWait * 11 / 10;
      if(Wait(nErrorWait += 60))
        continue;
      else
        return;
    }

    string strMyName;
    if(addrLocalHost.IsRoutable() && !fUseProxy && !fNameInUse)
      strMyName = EncodeAddress(addrLocalHost);
    else
      strMyName = strprintf("x%u", GetRand(1000000000));

    Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
    Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str());

    int nRet = RecvUntil(hSocket, " 004 ", " 433 ");
    if(nRet != 1)
    {
      closesocket(hSocket);
      hSocket = INVALID_SOCKET;
      if(nRet == 2)
      {
        printf("IRC name already in use\n");
        fNameInUse = true;
        Wait(10);
        continue;
      }
      nErrorWait = nErrorWait * 11 / 10;
      if(Wait(nErrorWait += 60))
        continue;
      else
        return;
    }
    Sleep(500);

    // Get our external IP from the IRC server and re-nick before joining the channel
    CNetAddr addrFromIRC;
    if(GetIPFromIRC(hSocket, strMyName, addrFromIRC))
    {
      printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str());
      if(!fUseProxy && addrFromIRC.IsRoutable())
      {
        // IRC lets you to re-nick
        fGotExternalIP = true;
        addrLocalHost.SetIP(addrFromIRC);
        strMyName = EncodeAddress(addrLocalHost);
        Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());
      }
    }
        
    if(fTestNet) {
      Send(hSocket, "JOIN #bitcoinTEST\r");
      Send(hSocket, "WHO #bitcoinTEST\r");
    } else {
      // randomly join #bitcoin00-#bitcoin99
      int channel_number = GetRandInt(100);
      Send(hSocket, strprintf("JOIN #bitcoin%02d\r", channel_number).c_str());
      Send(hSocket, strprintf("WHO #bitcoin%02d\r", channel_number).c_str());
    }

    int64 nStart = GetTime();
    string strLine;
//.........这里部分代码省略.........
开发者ID:d5000,项目名称:slimcoin,代码行数:101,代码来源:irc.cpp


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