Class: Peasant::PeerInfo
- Inherits:
-
Object
- Object
- Peasant::PeerInfo
- Defined in:
- lib/peasant/peer_info.rb
Instance Method Summary collapse
- #inc_requests ⇒ Object
-
#initialize(peer, args = {}) ⇒ PeerInfo
constructor
A new instance of PeerInfo.
- #node ⇒ Object
- #node=(n) ⇒ Object
- #node_expired? ⇒ Boolean
- #reset ⇒ Object
- #reset_node_expiration ⇒ Object
Constructor Details
#initialize(peer, args = {}) ⇒ PeerInfo
Returns a new instance of PeerInfo.
3 4 5 6 7 8 |
# File 'lib/peasant/peer_info.rb', line 3 def initialize peer, args={} @peer = peer reset @max_requests = args[:max_requests] || 3 @node_timeout = args[:node_timeout] || 15 end |
Instance Method Details
#inc_requests ⇒ Object
26 27 28 |
# File 'lib/peasant/peer_info.rb', line 26 def inc_requests @requests += 1 end |
#node ⇒ Object
10 11 12 |
# File 'lib/peasant/peer_info.rb', line 10 def node node_expired? ? nil : @node end |
#node=(n) ⇒ Object
14 15 16 17 18 |
# File 'lib/peasant/peer_info.rb', line 14 def node= n reset @node = n @node_expiration = Time.now.to_f + @node_timeout end |
#node_expired? ⇒ Boolean
20 21 22 23 24 |
# File 'lib/peasant/peer_info.rb', line 20 def node_expired? expired = @node_expiration < Time.now.to_f || @requests > @max_requests reset if expired expired end |
#reset ⇒ Object
34 35 36 37 38 |
# File 'lib/peasant/peer_info.rb', line 34 def reset @node = nil @requests = 0 @node_expiration = 0 end |
#reset_node_expiration ⇒ Object
30 31 32 |
# File 'lib/peasant/peer_info.rb', line 30 def reset_node_expiration @node_expiration = Time.now.to_f + @node_timeout end |