Class: Plug::PeerList
Instance Method Summary
collapse
Methods inherited from Array
#rand_elem, #randomize, #to_hash
Constructor Details
#initialize(owner, *args) ⇒ PeerList
Returns a new instance of PeerList.
42
43
44
45
46
47
|
# File 'lib/rbkb/plug/peer.rb', line 42
def initialize(owner, *args)
@owner = owner
@transport = @owner.transport
super(*args)
end
|
Instance Method Details
#add_peer(addr) ⇒ Object
53
54
55
56
|
# File 'lib/rbkb/plug/peer.rb', line 53
def add_peer(addr)
self << Peer.new(addr, @owner)
last
end
|
#add_peer_manually(host, port) ⇒ Object
58
59
60
61
|
# File 'lib/rbkb/plug/peer.rb', line 58
def add_peer_manually(host, port)
addr = Socket.pack_sockaddr_in(port, host)
find_peer(addr) || add_peer(addr)
end
|
#delete(addr) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/rbkb/plug/peer.rb', line 63
def delete(addr)
return unless p = find_peer(addr)
p.close
super(p)
end
|
#find_peer(addr) ⇒ Object
49
50
51
|
# File 'lib/rbkb/plug/peer.rb', line 49
def find_peer(addr)
find { |p| p.addr == addr }
end
|