/** 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); }
/** A peer is being disconnected This is called during the disconnection of a known, activated peer. It will not be called for outbound peer connections that don't succeed or for connections of peers that are dropped prior to being activated. */ void onPeerDisconnect (Peer::ref peer) { std::lock_guard <decltype(m_mutex)> lock (m_mutex); m_shortIdMap.erase (peer->getShortId ()); m_publicKeyMap.erase (peer->getNodePublic ()); }