Displaced connection check from zmq_listener to sidechain_net_manager
This commit is contained in:
parent
9137f31960
commit
0c42d7ea6f
5 changed files with 20 additions and 22 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
#include <fc/network/ip.hpp>
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <string>
|
||||
#include <fc/network/http/connection.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
|
||||
namespace sidechain {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fc/network/http/connection.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
#include <fc/signals.hpp>
|
||||
|
||||
#include <zmq.hpp>
|
||||
|
|
@ -16,7 +14,7 @@ class zmq_listener
|
|||
|
||||
public:
|
||||
|
||||
zmq_listener( std::string _ip, uint32_t _zmq, uint32_t _rpc );
|
||||
zmq_listener( std::string _ip, uint32_t _zmq );
|
||||
|
||||
bool connection_is_not_defined() const { return zmq_port == 0; }
|
||||
|
||||
|
|
@ -29,7 +27,6 @@ private:
|
|||
|
||||
std::string ip;
|
||||
uint32_t zmq_port;
|
||||
uint32_t rpc_port;
|
||||
|
||||
zmq::context_t ctx;
|
||||
zmq::socket_t socket;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
#include <sidechain/network/sidechain_net_manager.hpp>
|
||||
|
||||
#include <fc/network/http/connection.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
|
@ -7,20 +11,25 @@
|
|||
namespace sidechain {
|
||||
|
||||
sidechain_net_manager::sidechain_net_manager( graphene::chain::database* _db, std::string _ip,
|
||||
uint32_t _zmq, uint32_t _rpc, std::string _user, std::string _password ):
|
||||
listener( new zmq_listener( _ip, _zmq, _rpc ) ), bitcoin_client( new bitcoin_rpc_client( _ip, _rpc, _user, _password ) ), db( _db )
|
||||
uint32_t _zmq, uint32_t _rpc, std::string _user, std::string _password )
|
||||
{
|
||||
listener->block_received.connect( [this]( const std::string& block_hash ) {
|
||||
std::thread( &sidechain_net_manager::handle_block, this, block_hash ).detach();
|
||||
});
|
||||
initialize_manager(_db, _ip, _zmq, _rpc, _user, _password );
|
||||
}
|
||||
|
||||
void sidechain_net_manager::initialize_manager( graphene::chain::database* _db, std::string _ip,
|
||||
uint32_t _zmq, uint32_t _rpc, std::string _user, std::string _password )
|
||||
{
|
||||
db = std::unique_ptr<graphene::chain::database>( _db );
|
||||
listener = std::unique_ptr<zmq_listener>( new zmq_listener( _ip, _zmq, _rpc ) );
|
||||
listener = std::unique_ptr<zmq_listener>( new zmq_listener( _ip, _zmq ) );
|
||||
bitcoin_client = std::unique_ptr<bitcoin_rpc_client>( new bitcoin_rpc_client( _ip, _rpc, _user, _password ) );
|
||||
db = std::unique_ptr<graphene::chain::database>( _db );
|
||||
|
||||
fc::http::connection conn;
|
||||
try {
|
||||
conn.connect_to( fc::ip::endpoint( fc::ip::address( _ip ), _rpc ) );
|
||||
} catch ( fc::exception e ) {
|
||||
elog( "No BTC node running at ${ip} or wrong rpc port: ${port}", ("ip", _ip) ("port", _rpc) );
|
||||
FC_ASSERT( false );
|
||||
}
|
||||
|
||||
listener->block_received.connect([this]( const std::string& block_hash ) {
|
||||
std::thread( &sidechain_net_manager::handle_block, this, block_hash).detach();
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
namespace sidechain {
|
||||
|
||||
zmq_listener::zmq_listener( std::string _ip, uint32_t _zmq, uint32_t _rpc ):
|
||||
ip( _ip ), zmq_port( _zmq ), rpc_port( _rpc ), ctx( 1 ), socket( ctx, ZMQ_SUB )
|
||||
zmq_listener::zmq_listener( std::string _ip, uint32_t _zmq ): ip( _ip ), zmq_port( _zmq ), ctx( 1 ), socket( ctx, ZMQ_SUB )
|
||||
{
|
||||
std::thread( &zmq_listener::handle_zmq, this ).detach();
|
||||
}
|
||||
|
|
@ -34,14 +33,6 @@ void zmq_listener::handle_zmq()
|
|||
socket.setsockopt( ZMQ_SUBSCRIBE, "hashblock", 0 );
|
||||
socket.connect( "tcp://" + ip + ":" + std::to_string( zmq_port ) );
|
||||
|
||||
fc::http::connection conn;
|
||||
try {
|
||||
conn.connect_to( fc::ip::endpoint( fc::ip::address( ip ), rpc_port ) );
|
||||
} catch ( fc::exception e ) {
|
||||
elog( "No BTC node running at ${ip} or wrong rpc port: ${port}", ("ip", ip) ("port", rpc_port) );
|
||||
FC_ASSERT( false );
|
||||
}
|
||||
|
||||
while ( true ) {
|
||||
auto msg = receive_multipart();
|
||||
const auto header = std::string( static_cast<char*>( msg[0].data() ), msg[0].size() );
|
||||
|
|
|
|||
Loading…
Reference in a new issue