Example #1
0
    /** A peer has connected successfully
        This is called after the peer handshake has been completed and during
        peer activation. At this point, the peer address and the public key
        are known.
    */
    void onPeerActivated (Peer::ref peer)
    {
        // First assign this peer a new short ID
        peer->setShortId(++m_nextShortId);

        std::lock_guard <decltype(m_mutex)> lock (m_mutex);

        // Now track this peer
        std::pair<PeerByShortId::iterator, bool> idResult(
            m_shortIdMap.emplace (
                boost::unordered::piecewise_construct,
                boost::make_tuple (peer->getShortId()),
                boost::make_tuple (peer)));
        check_postcondition(idResult.second);

        std::pair<PeerByPublicKey::iterator, bool> keyResult(
            m_publicKeyMap.emplace (
                boost::unordered::piecewise_construct,
                boost::make_tuple (peer->getNodePublic()),
                boost::make_tuple (peer)));
        check_postcondition(keyResult.second);

        m_journal.debug << 
            "activated " << peer->getRemoteAddress() <<
            " (" << peer->getShortId() << 
            ":" << RipplePublicKey(peer->getNodePublic()) << ")";

        // We just accepted this peer so we have non-zero active peers
        check_postcondition(size() != 0);
    }
Example #2
0
/** A peer has connected successfully
    This is called after the peer handshake has been completed and during
    peer activation. At this point, the peer address and the public key
    are known.
*/
void
OverlayImpl::onPeerActivated (Peer::ptr const& peer)
{
    std::lock_guard <decltype(m_mutex)> lock (m_mutex);

    // Now track this peer
    {
        auto const result (m_shortIdMap.emplace (
                               std::piecewise_construct,
                               std::make_tuple (peer->getShortId()),
                               std::make_tuple (peer)));
        assert(result.second);
    }

    {
        auto const result (m_publicKeyMap.emplace (
                               std::piecewise_construct,
                               std::make_tuple (peer->getNodePublic()),
                               std::make_tuple (peer)));
        assert(result.second);
    }

    m_journal.debug <<
                    "activated " << peer->getRemoteAddress() <<
                    " (" << peer->getShortId() <<
                    ":" << RipplePublicKey(peer->getNodePublic()) << ")";

    // We just accepted this peer so we have non-zero active peers
    assert(size() != 0);
}