class Ciri::P2P::Dialer

Discovery and dial new nodes

Public Class Methods

new(private_key:, handshake:) click to toggle source
# File lib/ciri/p2p/dialer.rb, line 35
def initialize(private_key:, handshake:)
  @private_key = private_key
  @handshake = handshake
end

Public Instance Methods

dial(node) click to toggle source

setup a new connection to node

# 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