Class: DEVp2p::P2PProtocol::Hello

Inherits:
Command
  • Object
show all
Defined in:
lib/devp2p/p2p_protocol.rb

Instance Attribute Summary

Attributes inherited from Command

#receive_callbacks

Instance Method Summary collapse

Methods inherited from Command

decode_payload, encode_payload, #initialize, sedes

Methods included from Configurable

#add_config

Constructor Details

This class inherits a constructor from DEVp2p::Command

Instance Method Details

#create(proto) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/devp2p/p2p_protocol.rb', line 38

def create(proto)
  { version: proto.class.version,
    client_version_string: proto.config[:client_version_string],
    capabilities: proto.peer.capabilities,
    listen_port: proto.config[:p2p][:listen_port],
    remote_pubkey: proto.config[:node][:id] }
end

#receive(proto, data) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/devp2p/p2p_protocol.rb', line 46

def receive(proto, data)
  logger.debug 'receive_hello', peer: proto.peer, version: data[:version]

  reasons = proto.class::Disconnect::Reason
  if data[:remote_pubkey] == proto.config[:node][:id]
    logger.debug 'connected myself'
    return proto.send_disconnect(reason: reasons[:connected_to_self])
  end

  proto.peer.async.receive_hello proto, data
  super(proto, data)
end