Class: Ciri::P2P::Dialer
- Inherits:
-
Object
- Object
- Ciri::P2P::Dialer
- Includes:
- RLPX
- Defined in:
- lib/ciri/p2p/dialer.rb
Overview
Discovery and dial new nodes
Constant Summary
Constants included from RLPX
RLPX::AUTH_MSG_LENGTH, RLPX::AUTH_RESP_MSG_LENGTH, RLPX::BASE_PROTOCOL_LENGTH, RLPX::BASE_PROTOCOL_MAX_MSG_SIZE, RLPX::BASE_PROTOCOL_VERSION, RLPX::ECIES_OVERHEAD, RLPX::ENC_AUTH_MSG_LENGTH, RLPX::ENC_AUTH_RESP_MSG_LENGTH, RLPX::HANDSHAKE_TIMEOUT, RLPX::PUBLIC_KEY_LENGTH, RLPX::SHA_LENGTH, RLPX::SIGNATURE_LENGTH, RLPX::SNAPPY_PROTOCOL_VERSION
Instance Method Summary collapse
-
#dial(node) ⇒ Object
setup a new connection to node.
-
#initialize(private_key:, handshake:) ⇒ Dialer
constructor
A new instance of Dialer.
Constructor Details
#initialize(private_key:, handshake:) ⇒ Dialer
Returns a new instance of Dialer.
35 36 37 38 |
# File 'lib/ciri/p2p/dialer.rb', line 35 def initialize(private_key:, handshake:) @private_key = private_key @handshake = handshake end |
Instance Method Details
#dial(node) ⇒ Object
setup a new connection to node
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ciri/p2p/dialer.rb', line 41 def dial(node) # connect tcp socket # Use Stream to buffer IO operation address = node.addresses&.first return unless address socket = Async::IO::Stream.new(Async::IO::Endpoint.tcp(address.ip.to_s, address.tcp_port).connect) c = Connection.new(socket) c.encryption_handshake!(private_key: @private_key, remote_node_id: node.node_id) remote_handshake = c.protocol_handshake!(@handshake) [c, remote_handshake] end |