Class: Ciri::P2P::ProtocolContext
- Inherits:
-
Object
- Object
- Ciri::P2P::ProtocolContext
- Extended by:
- Forwardable
- Defined in:
- lib/ciri/p2p/protocol_context.rb
Overview
ProtocolContext is used to manuaplate
Instance Attribute Summary collapse
-
#peer ⇒ Object
readonly
Returns the value of attribute peer.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#protocol_io ⇒ Object
readonly
Returns the value of attribute protocol_io.
Instance Method Summary collapse
- #find_peer(raw_node_id) ⇒ Object
-
#initialize(network_state, peer: nil, protocol: nil, protocol_io: nil) ⇒ ProtocolContext
constructor
A new instance of ProtocolContext.
- #peers ⇒ Object
- #raw_local_node_id ⇒ Object
- #send_data(code, data, peer: self.peer, protocol: self.protocol.name) ⇒ Object
Constructor Details
#initialize(network_state, peer: nil, protocol: nil, protocol_io: nil) ⇒ ProtocolContext
Returns a new instance of ProtocolContext.
39 40 41 42 43 44 |
# File 'lib/ciri/p2p/protocol_context.rb', line 39 def initialize(network_state, peer: nil, protocol: nil, protocol_io: nil) @network_state = network_state @peer = peer @protocol = protocol @protocol_io = protocol_io end |
Instance Attribute Details
#peer ⇒ Object (readonly)
Returns the value of attribute peer.
35 36 37 |
# File 'lib/ciri/p2p/protocol_context.rb', line 35 def peer @peer end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
35 36 37 |
# File 'lib/ciri/p2p/protocol_context.rb', line 35 def protocol @protocol end |
#protocol_io ⇒ Object (readonly)
Returns the value of attribute protocol_io.
35 36 37 |
# File 'lib/ciri/p2p/protocol_context.rb', line 35 def protocol_io @protocol_io end |
Instance Method Details
#find_peer(raw_node_id) ⇒ Object
58 59 60 |
# File 'lib/ciri/p2p/protocol_context.rb', line 58 def find_peer(raw_node_id) @network_state.peers[raw_node_id] end |
#peers ⇒ Object
54 55 56 |
# File 'lib/ciri/p2p/protocol_context.rb', line 54 def peers @network_state.peers.values end |
#raw_local_node_id ⇒ Object
50 51 52 |
# File 'lib/ciri/p2p/protocol_context.rb', line 50 def raw_local_node_id @raw_local_node_id ||= local_node_id.to_bytes end |
#send_data(code, data, peer: self.peer, protocol: self.protocol.name) ⇒ Object
46 47 48 |
# File 'lib/ciri/p2p/protocol_context.rb', line 46 def send_data(code, data, peer: self.peer, protocol: self.protocol.name) ensure_peer(peer).find_protocol_io(protocol).send_data(code, data) end |