Method: Tapyrus::Network::Peer#initialize

Defined in:
lib/tapyrus/network/peer.rb

#initialize(host, port, pool, configuration) ⇒ Peer

Returns a new instance of Peer.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tapyrus/network/peer.rb', line 38

def initialize(host, port, pool, configuration)
  @host = host
  @port = port
  @pool = pool
  @chain = pool.chain
  @connected = false
  @primary = false
  @logger = Tapyrus::Logger.create(:debug)
  @outbound = true
  @best_hash = -1
  @best_height = -1
  @min_ping = -1
  @bytes_sent = 0
  @bytes_recv = 0
  @relay = configuration.conf[:relay]
  current_height = @chain.latest_block.height
  remote_addr = Tapyrus::Message::NetworkAddr.new(ip: host, port: port, time: nil)
  @local_version =
    Tapyrus::Message::Version.new(remote_addr: remote_addr, start_height: current_height, relay: @relay)
end