Esempio n. 1
0
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));
}
Esempio n. 2
0
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_);
}
Esempio n. 3
0
bool protocol::is_blacklisted(const config::authority& peer) const
{
    const auto found = [&peer](const config::authority& host)
    {
        return (host.port() == 0 || host.port() == peer.port()) &&
            (host.ip() == peer.ip());
    };
    auto it = std::find_if(blacklisted_.begin(), blacklisted_.end(), found);
    return it != blacklisted_.end();
    return true;
}
Esempio n. 4
0
version protocol_version::template_factory(const config::authority& authority,
        const settings& settings, uint64_t nonce, size_t height)
{
    auto version = protocol_version::template_;

    // The timestamp should not used here and there's no need to set services.
    version.address_you = authority.to_network_address();

    // The timestamp should not used here and services should be set in config.
    version.address_me = settings.self.to_network_address();

    // It is expected that the version is constructed shortly before use.
    BITCOIN_ASSERT_MSG(height < max_uint32, "Time to upgrade the protocol.");
    version.start_height = static_cast<uint32_t>(height);

    // Set required transaction relay policy for the connection.
    version.relay = settings.relay_transactions;

    // A non-zero nonce is used to detect connections to self.
    version.nonce = nonce;
    return version;
}
Esempio n. 5
0
void connector::connect(const config::authority& authority,
    connect_handler handler)
{
    connect(authority.to_hostname(), authority.port(), handler);
}