コード例 #1
0
ファイル: protocol.cpp プロジェクト: cissp0/libbitcoin
void protocol::handle_connect(const code& ec, channel::ptr node,
    const config::authority& peer)
{
    if (ec)
    {
        log_debug(LOG_PROTOCOL)
            << "Failure connecting [" << peer << "] " << ec.message();

        // Restart connection attempt.
        new_connection();
        return;
    }

    // Save the connection as we are now assured of getting stop event.
    outbound_connections_.push_back(node);

    // Connected!
    log_info(LOG_PROTOCOL)
        << "Connected to peer [" << peer.to_string() << "] (" 
        << outbound_connections_.size() << " total)";

    const auto stop_handler =
        dispatch_.ordered_delegate(&protocol::outbound_channel_stopped,
            this, _1, node, peer.to_string());

    start_talking(node, stop_handler, relay_);
}
コード例 #2
0
ファイル: protocol.cpp プロジェクト: cissp0/libbitcoin
void protocol::start_connect(const code& ec, const config::authority& peer)
{
    if (ec)
    {
        handle_connect(ec, nullptr, peer);
        return;
    }

    if (is_connected(peer))
    {
        handle_connect(error::address_in_use, nullptr, peer);
        return;
    }

    if (is_blacklisted(peer))
    {
        handle_connect(error::address_blocked, nullptr, peer);
        return;
    }

    log_debug(LOG_PROTOCOL)
        << "Connecting to peer [" << peer.to_string() << "]";

    // OUTBOUND CONNECT (sequential)
    network_.connect(peer.to_hostname(), peer.port(),
        dispatch_.ordered_delegate(&protocol::handle_connect,
            this, _1, _2, peer));
}