Class: BitcoinNode::P2p::Client::CommandHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin_node/p2p/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, buffer, probe) ⇒ CommandHandler



46
47
48
# File 'lib/bitcoin_node/p2p/client.rb', line 46

def initialize(client, buffer, probe)
  @client, @buffer, @probe = client, buffer, probe
end

Instance Method Details

#parseObject



50
51
52
53
54
55
56
57
# File 'lib/bitcoin_node/p2p/client.rb', line 50

def parse
  @probe << { receiving: @command }

  callback = Parser.new(@command, @payload).parse

  @buffer.clear
  callback.call(@client)
end

#valid_message?Boolean



59
60
61
62
63
64
65
66
# File 'lib/bitcoin_node/p2p/client.rb', line 59

def valid_message?
  @payload, @command = BN::Protocol::Message.validate(@buffer)
rescue BN::P::IncompleteMessageError
  false
rescue BN::P::InvalidChecksumError => e  
  BN::Logger.info(e.message)
  false
end