Class: Tapyrus::Network::Connection

Inherits:
EM::Connection
  • Object
show all
Includes:
MessageHandler
Defined in:
lib/tapyrus/network/connection.rb

Overview

Basic Bitcoin P2P connection class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageHandler

#defer_handle_command, #handle, #handle_command, #handshake_done, #on_addr, #on_block, #on_cmpct_block, #on_fee_filter, #on_get_addr, #on_get_data, #on_get_headers, #on_headers, #on_inv, #on_mem_pool, #on_merkle_block, #on_not_found, #on_ping, #on_pong, #on_reject, #on_send_cmpct, #on_send_headers, #on_tx, #on_ver_ack, #on_version, #parse, #parse_header, #send_message

Constructor Details

#initialize(peer) ⇒ Connection

Returns a new instance of Connection.



18
19
20
21
22
23
24
25
# File 'lib/tapyrus/network/connection.rb', line 18

def initialize(peer)
  @peer = peer
  @logger = peer.logger
  @sendheaders = false
  @attr_accessor = 0
  @message = ""
  self.pending_connect_timeout = 5.0
end

Instance Attribute Details

#fee_rateObject

minimum fee(in satoshis per kilobyte) for relay tx



16
17
18
# File 'lib/tapyrus/network/connection.rb', line 16

def fee_rate
  @fee_rate
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/tapyrus/network/connection.rb', line 7

def logger
  @logger
end

#peerObject (readonly)

Returns the value of attribute peer.



7
8
9
# File 'lib/tapyrus/network/connection.rb', line 7

def peer
  @peer
end

#sendheadersObject

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



13
14
15
# File 'lib/tapyrus/network/connection.rb', line 13

def sendheaders
  @sendheaders
end

#versionObject

remote peer version.



10
11
12
# File 'lib/tapyrus/network/connection.rb', line 10

def version
  @version
end

Instance Method Details

#addrObject



42
43
44
# File 'lib/tapyrus/network/connection.rb', line 42

def addr
  peer.addr
end

#close(msg = "") ⇒ Object

close network connection.



47
48
49
50
# File 'lib/tapyrus/network/connection.rb', line 47

def close(msg = "")
  logger.info "close connection with #{addr}. #{msg}"
  close_connection_after_writing
end

#handle_error(e) ⇒ Object



52
53
54
# File 'lib/tapyrus/network/connection.rb', line 52

def handle_error(e)
  peer.handle_error(e)
end

#post_handshakeObject



38
39
40
# File 'lib/tapyrus/network/connection.rb', line 38

def post_handshake
  peer.post_handshake
end

#post_initObject



27
28
29
30
31
# File 'lib/tapyrus/network/connection.rb', line 27

def post_init
  logger.info "connected. #{addr}"
  peer.conn_time = Time.now.to_i
  begin_handshake
end

#receive_data(data) ⇒ Object

handle receiving data from remote node.



34
35
36
# File 'lib/tapyrus/network/connection.rb', line 34

def receive_data(data)
  handle(data)
end

#unbindObject



56
57
58
59
# File 'lib/tapyrus/network/connection.rb', line 56

def unbind
  logger.info "unbind. #{addr}"
  peer.unbind
end