class Bitcoin::Network::Connection

Basic Bitcoin P2P connection class

Attributes

fee_rate[RW]

minimum fee(in satoshis per kilobyte) for relay tx

logger[R]
peer[R]
sendheaders[RW]

if true, this peer send new block announcements using a headers message rather than an inv message.

version[RW]

remote peer version.

Public Class Methods

new(peer) click to toggle source
# File lib/bitcoin/network/connection.rb, line 21
def initialize(peer)
  @peer = peer
  @logger = peer.logger
  @sendheaders = false
  @attr_accessor = 0
  @message = ''
  self.pending_connect_timeout = 5.0
end

Public Instance Methods

addr() click to toggle source
# File lib/bitcoin/network/connection.rb, line 45
def addr
  peer.addr
end
close(msg = '') click to toggle source

close network connection.

# File lib/bitcoin/network/connection.rb, line 50
def close(msg = '')
  logger.info "close connection with #{addr}. #{msg}"
  close_connection_after_writing
end
handle_error(e) click to toggle source
# File lib/bitcoin/network/connection.rb, line 55
def handle_error(e)
  peer.handle_error(e)
end
post_handshake() click to toggle source
# File lib/bitcoin/network/connection.rb, line 41
def post_handshake
  peer.post_handshake
end
post_init() click to toggle source
# File lib/bitcoin/network/connection.rb, line 30
def post_init
  logger.info "connected. #{addr}"
  peer.conn_time = Time.now.to_i
  begin_handshake
end
receive_data(data) click to toggle source

handle receiving data from remote node.

# File lib/bitcoin/network/connection.rb, line 37
def receive_data(data)
  handle(data)
end
unbind() click to toggle source
# File lib/bitcoin/network/connection.rb, line 59
def unbind
  logger.info "unbind. #{addr}"
  peer.unbind
end

Private Instance Methods

begin_handshake() click to toggle source

start handshake

# File lib/bitcoin/network/connection.rb, line 67
def begin_handshake
  logger.info "begin handshake with #{addr}"
  send_message(peer.local_version)
end