Пример #1
0
channel_proxy::channel_proxy(threadpool& pool, socket_ptr socket)
  : strand_(pool.service()), socket_(socket),
    timeout_(pool.service()), heartbeat_(pool.service()), stopped_(false)
{
#define CHANNEL_TRANSPORT_MECHANISM(MESSAGE_TYPE) \
    MESSAGE_TYPE##_subscriber_ = \
        std::make_shared<MESSAGE_TYPE##_subscriber_type>(pool); \
    loader_.add(new channel_loader_module<MESSAGE_TYPE##_type>( \
        std::bind(&MESSAGE_TYPE##_subscriber_type::relay, \
            MESSAGE_TYPE##_subscriber_, _1, _2)));

    CHANNEL_TRANSPORT_MECHANISM(version);
    CHANNEL_TRANSPORT_MECHANISM(verack);
    CHANNEL_TRANSPORT_MECHANISM(address);
    CHANNEL_TRANSPORT_MECHANISM(get_address);
    CHANNEL_TRANSPORT_MECHANISM(inventory);
    CHANNEL_TRANSPORT_MECHANISM(get_data);
    CHANNEL_TRANSPORT_MECHANISM(get_blocks);
    CHANNEL_TRANSPORT_MECHANISM(transaction);
    CHANNEL_TRANSPORT_MECHANISM(block);

#undef CHANNEL_TRANSPORT_MECHANISM

    raw_subscriber_ = std::make_shared<raw_subscriber_type>(pool);
    stop_subscriber_ = std::make_shared<stop_subscriber_type>(pool);
}
Пример #2
0
connector::connector(threadpool& pool, const settings& settings)
  : pool_(pool),
    settings_(settings),
    resolver_(std::make_shared<asio::resolver>(pool.service())),
    CONSTRUCT_TRACK(connector, LOG_NETWORK)
{
}
Пример #3
0
protocol::protocol(threadpool& pool, hosts& hsts,
                   handshake& shake, network& net)
    : strand_(pool), hosts_(hsts), handshake_(shake), network_(net),
      watermark_timer_(pool.service())
{
    channel_subscribe_ = std::make_shared<channel_subscriber_type>(pool);
}
Пример #4
0
session::session(threadpool& pool, const session_params& params)
  : strand_(pool.service()),
    handshake_(params.handshake_), protocol_(params.protocol_),
    chain_(params.blockchain_), poll_(params.poller_),
    tx_pool_(params.transaction_pool_),
    grabbed_invs_(20)
{
}
Пример #5
0
 void print_tp_status(threadpool &tp) {
     std::stringstream ss;
     for(u_int i=0;i<num_threads;i++){
         std::string status = tp.get_thread_status(i);
         if(status.size() && status!="Free"){
             ss << "Thread " << i << ": " << status << "\n";
         }
     }
     std::cout << ss.str() << "\n";
 }
Пример #6
0
connector::connector(threadpool& pool, const settings& settings)
  : stopped_(false),
    pool_(pool),
    settings_(settings),
    pending_(settings_),
    dispatch_(pool, NAME),
    resolver_(std::make_shared<asio::resolver>(pool.service())),
    CONSTRUCT_TRACK(connector)
{
}
Пример #7
0
work::work(threadpool& pool, const std::string& name)
  : name_(name),
    ////ordered_(std::make_shared<monitor::count>(0)),
    ////unordered_(std::make_shared<monitor::count>(0)),
    ////concurrent_(std::make_shared<monitor::count>(0)),
    ////sequential_(std::make_shared<monitor::count>(0)),
    service_(pool.service()),
    strand_(service_),
    sequence_(service_)
{
}
blockchain_impl::blockchain_impl(threadpool& pool, const std::string& prefix,
    const db_active_heights &active_heights, size_t orphan_capacity)
  : ios_(pool.service()), write_strand_(pool), reorg_strand_(pool),
    flock_(init_lock(prefix)), seqlock_(0), stopped_(false), db_paths_(prefix),
    interface_(db_paths_, active_heights), orphans_(orphan_capacity),
    chain_(simple_chain_impl(interface_)),
    reorganize_subscriber_(std::make_shared<reorganize_subscriber_type>(pool)),
    organizer_(organizer_factory(reorg_strand_, interface_, orphans_, chain_,
        reorganize_subscriber_))
{
}
Пример #9
0
void fullnode::stop()
{
    std::promise<std::error_code> ec_promise;
    auto session_stopped =
        [&ec_promise](const std::error_code& ec)
        {
            ec_promise.set_value(ec);
        };
    session_.stop(session_stopped);
    std::error_code ec = ec_promise.get_future().get();
    if (ec)
        log_error() << "Problem stopping session: " << ec.message();

    // Stop threadpools.
    net_pool_.stop();
    disk_pool_.stop();
    mem_pool_.stop();
    // Join threadpools. Wait for them to finish.
    net_pool_.join();
    disk_pool_.join();
    mem_pool_.join();

    // Safely close blockchain database.
    chain_.stop();
}
Пример #10
0
handshake::handshake(threadpool& pool)
  : strand_(pool.service())
{
    // Setup template version packet with defaults
    template_version_.version = protocol_version;
    template_version_.services = 1;
    // non-constant field
    //template_version_.timestamp = time(NULL);
    template_version_.address_me.services = template_version_.services;
    template_version_.address_me.ip = localhost_ip();
    template_version_.address_me.port = protocol_port;
    template_version_.address_you.services = template_version_.services;
    template_version_.address_you.ip =
        ip_address_type{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                         0x00, 0x00, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x01}};
    template_version_.address_you.port = protocol_port;
    template_version_.user_agent = "/libbitcoin:" LIBBITCOIN_VERSION "/";
    template_version_.start_height = 0;
    template_version_.nonce = rand();
}
Пример #11
0
		handshake::handshake(threadpool& pool, p2p_network p2p)
			: strand_(pool.service()), p2p_(p2p)
		{
			// Setup template version packet with defaults
			template_version_.version = protocol_version;
			template_version_.services = 1;
			// non-constant field
			//template_version_.timestamp = time(NULL);
			template_version_.address_me.services = template_version_.services;
			template_version_.address_me.ip = localhost_ip();
			template_version_.address_me.port = p2p_.get_port();
			template_version_.address_you.services = template_version_.services;
			template_version_.address_you.ip =
				ip_address_type{ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x01 } };
			template_version_.address_you.port = p2p_.get_port();
			template_version_.user_agent = "/decentralised:" DC_CORE_LIB_VERSION "/";
			template_version_.start_height = 0;
			template_version_.nonce = rand();
		}
Пример #12
0
async_strand::async_strand(threadpool& pool)
  : ios_(pool.service()), strand_(ios_)
{
}
leveldb_blockchain::leveldb_blockchain(threadpool& pool)
  : ios_(pool.service()), strand_(pool), reorg_strand_(pool), seqlock_(0)
{
    reorganize_subscriber_ =
        std::make_shared<reorganize_subscriber_type>(pool);
}
Пример #14
0
// This protects timer_ against concurrent access with no chance of deadlock.
// This can be dereferenced with an outstanding callback because the timer
// closure captures an instance of this class and the callback.
// This is guaranteed to call handler exactly once unless canceled or reset.
deadline::deadline(threadpool& pool, const asio::duration duration)
  : duration_(duration),
    timer_(pool.service()),
    CONSTRUCT_TRACK(deadline)
{
}
Пример #15
0
 subscriber(threadpool& pool)
   : strand_(pool.service())
 {
 }
Пример #16
0
 perform_connect_with_timeout(threadpool& pool)
   : timer_(pool.service())
 {
     socket_ = std::make_shared<tcp::socket>(pool.service());
     proxy_ = std::make_shared<channel_proxy>(pool, socket_);
 }
Пример #17
0
poller::poller(threadpool& pool, blockchain& chain)
    : strand_(pool.service()), chain_(chain),
      last_locator_begin_(null_hash), last_hash_stop_(null_hash),
      last_block_hash_(null_hash)
{
}