#include "MyClass.h" #include #include #include MyClass::MyClass(DownloadManager *dlm) : m_dlm(dlm) { } void MyClass::start(const boost::system::error_code &error) { if (error) return; logInfo() << "We start finding a peer"; auto &addressDb = m_dlm->connectionManager().peerAddressDb(); PeerAddress address = addressDb.findBest( (1 << 2) // NODE_BLOOM + (1 << 8), // NODE_CF /* segment-id is used for wallet-privacy */ 0); // try to connect to a new peer. // please notice that this is essentially a semi-random IP address and there is no guarentee // the connection will succeed. if (address.isValid()) { logInfo() << " Valid peer found, connecting now." << address.peerAddress(); m_dlm->connectionManager().connect(address); } else { logWarning() << "No data available in addresss-DB, can't demo our great features!"; logInfo() << "Please turn on the Internet"; } } void MyClass::newPeer(const std::shared_ptr &peer) { // when this is called, the p2p handshake has been finished. The Peer object has // version, services and all that set properly. // Notice that the backend connects to peers too, especially at first run (to fill // the address DB) so don't expect this to be the same peer as the one we connected to // in 'start'. logCritical() << "Peer finished connecting!" << peer->connectionId() << peer->peerAddress(); }