class Bitcourier::PeerList
Attributes
peers[R]
storage[R]
Public Class Methods
new()
click to toggle source
# File lib/bitcourier/peer_list.rb, line 5 def initialize @peers = [] @storage = Storage.new(self) load end
Public Instance Methods
next()
click to toggle source
# File lib/bitcourier/peer_list.rb, line 22 def next peers.select(&:can_connect?).sample end
store(peer)
click to toggle source
# File lib/bitcourier/peer_list.rb, line 12 def store(peer) if existing = find(peer) existing.update(peer) else peers << peer end save end
Private Instance Methods
find(peer)
click to toggle source
# File lib/bitcourier/peer_list.rb, line 30 def find(peer) peers.detect { |existing| existing.same?(peer) } end
load()
click to toggle source
# File lib/bitcourier/peer_list.rb, line 38 def load storage.read seed if peers.size == 0 end
save()
click to toggle source
# File lib/bitcourier/peer_list.rb, line 34 def save storage.write end
seed()
click to toggle source
# File lib/bitcourier/peer_list.rb, line 44 def seed store Peer.new('146.185.167.10', 6081) end