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


C++ StellarMessage::peers方法代码示例

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


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

示例1: CLOG

void
Peer::recvPeers(StellarMessage const& msg)
{
    for (auto peer : msg.peers())
    {
        stringstream ip;

        ip << (int)peer.ip[0] << "." << (int)peer.ip[1] << "."
           << (int)peer.ip[2] << "." << (int)peer.ip[3];

        if (peer.port == 0 || peer.port > UINT16_MAX)
        {
            CLOG(DEBUG, "Overlay") << "ignoring peer with bad port";
            continue;
        }
        PeerRecord pr{ip.str(), static_cast<unsigned short>(peer.port),
                      mApp.getClock().now(), peer.numFailures, 1};

        if (pr.isPrivateAddress())
        {
            CLOG(DEBUG, "Overlay") << "ignoring flooded private address";
        }
        else
        {
            pr.insertIfNew(mApp.getDatabase());
        }
    }
}
开发者ID:datachand,项目名称:stellar-core,代码行数:28,代码来源:Peer.cpp

示例2: sendMessage

void
Peer::sendPeers()
{
    // send top 50 peers we know about
    vector<PeerRecord> peerList;
    PeerRecord::loadPeerRecords(mApp.getDatabase(), 50, mApp.getClock().now(),
                                peerList);
    StellarMessage newMsg;
    newMsg.type(PEERS);
    newMsg.peers().resize(xdr::size32(peerList.size()));
    for (size_t n = 0; n < peerList.size(); n++)
    {
        if (!peerList[n].isPrivateAddress())
        {
            peerList[n].toXdr(newMsg.peers()[n]);
        }
    }
    sendMessage(newMsg);
}
开发者ID:datachand,项目名称:stellar-core,代码行数:19,代码来源:Peer.cpp

示例3: if

void
Peer::recvPeers(StellarMessage const& msg)
{
    const uint32 NEW_PEER_WINDOW_SECONDS = 10;

    for (auto const& peer : msg.peers())
    {
        if (peer.port == 0 || peer.port > UINT16_MAX)
        {
            CLOG(WARNING, "Overlay") << "ignoring received peer with bad port "
                                     << peer.port;
            continue;
        }
        if (peer.ip.type() == IPv6)
        {
            CLOG(WARNING, "Overlay") << "ignoring received IPv6 address"
                                     << " (not yet supported)";
            continue;
        }
        // randomize when we'll try to connect to this peer next if we don't
        // know it
        auto defaultNextAttempt =
            mApp.getClock().now() +
            std::chrono::seconds(std::rand() % NEW_PEER_WINDOW_SECONDS);

        stringstream ip;
        ip << (int)peer.ip.ipv4()[0] << "." << (int)peer.ip.ipv4()[1] << "."
           << (int)peer.ip.ipv4()[2] << "." << (int)peer.ip.ipv4()[3];
        // don't use peer.numFailures here as we may have better luck
        // (and we don't want to poison our failure count)
        PeerRecord pr{ip.str(), static_cast<unsigned short>(peer.port),
                      defaultNextAttempt, 0};

        if (pr.isPrivateAddress())
        {
            CLOG(WARNING, "Overlay") << "ignoring received private address "
                                     << pr.toString();
        }
        else if (pr.isSelfAddressAndPort(getIP(), mApp.getConfig().PEER_PORT))
        {
            CLOG(WARNING, "Overlay") << "ignoring received self-address "
                                     << pr.toString();
        }
        else if (pr.isLocalhost() &&
                 !mApp.getConfig().ALLOW_LOCALHOST_FOR_TESTING)
        {
            CLOG(WARNING, "Overlay") << "ignoring received localhost";
        }
        else
        {
            pr.insertIfNew(mApp.getDatabase());
        }
    }
}
开发者ID:StellarCN,项目名称:stellar-core,代码行数:54,代码来源:Peer.cpp

示例4: sendMessage

void
Peer::sendPeers()
{
    // send top 50 peers we know about
    vector<PeerRecord> peerList;
    PeerRecord::loadPeerRecords(mApp.getDatabase(), 50, mApp.getClock().now(),
                                peerList);
    StellarMessage newMsg;
    newMsg.type(PEERS);
    newMsg.peers().reserve(peerList.size());
    for (auto const& pr : peerList)
    {
        if (pr.isPrivateAddress() ||
            pr.isSelfAddressAndPort(getIP(), mRemoteListeningPort))
        {
            continue;
        }
        PeerAddress pa;
        pr.toXdr(pa);
        newMsg.peers().push_back(pa);
    }
    sendMessage(newMsg);
}
开发者ID:StellarCN,项目名称:stellar-core,代码行数:23,代码来源:Peer.cpp

示例5: if

void
Peer::recvPeers(StellarMessage const& msg)
{
    for (auto const& peer : msg.peers())
    {
        if (peer.port == 0 || peer.port > UINT16_MAX)
        {
            CLOG(WARNING, "Overlay") << "ignoring received peer with bad port "
                                     << peer.port;
            continue;
        }
        if (peer.ip.type() == IPv6)
        {
            CLOG(WARNING, "Overlay") << "ignoring received IPv6 address"
                                     << " (not yet supported)";
            continue;
        }
        stringstream ip;
        ip << (int)peer.ip.ipv4()[0] << "." << (int)peer.ip.ipv4()[1] << "."
           << (int)peer.ip.ipv4()[2] << "." << (int)peer.ip.ipv4()[3];
        PeerRecord pr{ip.str(), static_cast<unsigned short>(peer.port),
                      mApp.getClock().now(), peer.numFailures};

        if (pr.isPrivateAddress())
        {
            CLOG(WARNING, "Overlay") << "ignoring received private address "
                                     << pr.toString();
        }
        else if (pr.isSelfAddressAndPort(getIP(), mApp.getConfig().PEER_PORT))
        {
            CLOG(WARNING, "Overlay") << "ignoring received self-address "
                                     << pr.toString();
        }
        else
        {
            pr.insertIfNew(mApp.getDatabase());
        }
    }
}
开发者ID:irisli,项目名称:stellar-core,代码行数:39,代码来源:Peer.cpp


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