lib/bitcoin/protocol/parser.rb in bitcoin-ruby-0.0.4 vs lib/bitcoin/protocol/parser.rb in bitcoin-ruby-0.0.5

- old
+ new

@@ -2,14 +2,19 @@ module Bitcoin module Protocol class Parser + attr_reader :stats def initialize(handler=nil) @h = handler || Handler.new @buf = "" + @stats = { + 'total_packets' => 0, + 'total_bytes' => 0 + } end def log @log ||= Bitcoin::Logger.create("parser") end @@ -67,9 +72,12 @@ stop_hash = payload[0..32].reverse_hth [version, hashes, stop_hash] end def process_pkt(command, payload) + @stats['total_packets'] += 1 + @stats['total_bytes'] += payload.bytesize + @stats[command] ? (@stats[command] += 1) : @stats[command] = 1 case command when 'tx'; @h.on_tx( Tx.new(payload) ) when 'block'; @h.on_block( Block.new(payload) ) when 'headers'; parse_headers(payload) when 'inv'; parse_inv(payload, :put)