Sha256: b0db8b54a2c21abbab8dad8eae72f1125b63a70be0ac392cd41d2fe85036f6d2
Contents?: true
Size: 1019 Bytes
Versions: 2
Compression:
Stored size: 1019 Bytes
Contents
module Tapyrus module Network class PeerDiscovery attr_reader :logger, :configuration def initialize(configuration) @logger = Tapyrus::Logger.create(:debug) @configuration = configuration end # get peer addresses, from DNS seeds. def peers # TODO add find from previous connected peer at first. (find_from_dns_seeds + seeds).uniq end private def dns_seeds Tapyrus.chain_params.dns_seeds || [] end def seeds [*configuration.conf[:connect]] end def find_from_dns_seeds logger.debug 'discover peer address from DNS seeds.' dns_seeds.map do |seed| begin Socket.getaddrinfo(seed, Tapyrus.chain_params.default_port).map { |a| a[2] }.uniq rescue SocketError => e logger.error "SocketError occurred when load DNS seed: #{seed}, error: #{e.message}" nil end end.flatten.compact end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tapyrus-0.2.9 | lib/tapyrus/network/peer_discovery.rb |
tapyrus-0.2.8 | lib/tapyrus/network/peer_discovery.rb |