Class: Dcha::Peer
- Inherits:
-
Object
- Object
- Dcha::Peer
- Includes:
- CanHeartbeat, HasBlockchain, HasTrie, RemoteExecutable, Observable
- Defined in:
- lib/dcha/peer.rb,
lib/dcha/peer/has_trie.rb,
lib/dcha/peer/can_heartbeat.rb,
lib/dcha/peer/has_blockchain.rb,
lib/dcha/peer/remote_executable.rb
Overview
:nodoc:
Defined Under Namespace
Modules: CanHeartbeat, HasBlockchain, HasTrie, RemoteExecutable
Constant Summary collapse
- MULTICAST_ADDR =
'224.5.5.55'.freeze
- BIND_ADDR =
'0.0.0.0'.freeze
- PORT =
'5555'.freeze
Constants included from RemoteExecutable
RemoteExecutable::EXECUTABLE_OBJECT
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#ipaddr ⇒ Object
readonly
Returns the value of attribute ipaddr.
-
#peers ⇒ Object
readonly
Returns the value of attribute peers.
Instance Method Summary collapse
-
#initialize ⇒ Peer
constructor
A new instance of Peer.
- #join ⇒ Object
- #listening? ⇒ Boolean
- #transmit(data) ⇒ Object
- #transmit_to(address, data) ⇒ Object
Methods included from CanHeartbeat
Methods included from HasBlockchain
#blocks, #chain, #create_block, #mine
Methods included from HasTrie
#read, #reset, #store_get, #store_set, #trie, #write
Methods included from RemoteExecutable
#execute, #execute_on, #pickup_object
Constructor Details
#initialize ⇒ Peer
Returns a new instance of Peer.
21 22 23 24 25 26 27 |
# File 'lib/dcha/peer.rb', line 21 def initialize @hostname = Socket.gethostname @ipaddr = Addrinfo.getaddrinfo(hostname, nil, :INET).first @peers = [] @thread = nil @packets = PacketManager.new end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
19 20 21 |
# File 'lib/dcha/peer.rb', line 19 def hostname @hostname end |
#ipaddr ⇒ Object (readonly)
Returns the value of attribute ipaddr.
19 20 21 |
# File 'lib/dcha/peer.rb', line 19 def ipaddr @ipaddr end |
#peers ⇒ Object (readonly)
Returns the value of attribute peers.
19 20 21 |
# File 'lib/dcha/peer.rb', line 19 def peers @peers end |
Instance Method Details
#join ⇒ Object
29 30 31 32 33 |
# File 'lib/dcha/peer.rb', line 29 def join return if listening? listen ping end |
#listening? ⇒ Boolean
35 36 37 |
# File 'lib/dcha/peer.rb', line 35 def listening? @listening == true end |
#transmit(data) ⇒ Object
39 40 41 |
# File 'lib/dcha/peer.rb', line 39 def transmit(data) transmit_to MULTICAST_ADDR, data end |