Class: Ciri::DevP2P::RLPX::Connection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ciri/devp2p/rlpx/connection.rb

Overview

RLPX::Connection implement RLPX protocol operations all operations end with bang(!)

Defined Under Namespace

Classes: Error, FormatError, MessageOverflowError, UnexpectedMessageError

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Connection


55
56
57
58
59
# File 'lib/ciri/devp2p/rlpx/connection.rb', line 55

def initialize(io)
  set_timeout(io)
  @io = io
  @frame_io = nil
end

Instance Method Details

#encryption_handshake!(private_key:, node_id: nil) ⇒ Object

Encryption handshake, exchange keys with node, must been invoked before other operations


62
63
64
65
66
# File 'lib/ciri/devp2p/rlpx/connection.rb', line 62

def encryption_handshake!(private_key:, node_id: nil)
  enc_handshake = EncryptionHandshake.new(private_key: private_key, remote_id: node_id)
  secrets = node_id.nil? ? receiver_enc_handshake(enc_handshake) : initiator_enc_handshake(enc_handshake)
  @frame_io = FrameIO.new(@io, secrets)
end

#protocol_handshake!(our_hs) ⇒ Object

protocol handshake


69
70
71
72
73
74
75
# File 'lib/ciri/devp2p/rlpx/connection.rb', line 69

def protocol_handshake!(our_hs)
  @frame_io.send_data(MESSAGES[:handshake], our_hs.rlp_encode!)
  remote_hs = read_protocol_handshake  # enable snappy compress if remote peer support

  @frame_io.snappy = remote_hs.version >= SNAPPY_PROTOCOL_VERSION
  remote_hs
end