Add support for DNS Seed (#940)
* Add support for DNS Seed * Add port * Add seed.grin-tech.org * Remove duplicate IPs
This commit is contained in:
committed by
Ignotus Peverell
parent
65d5bd40e3
commit
cb221ee102
@@ -18,6 +18,7 @@
|
||||
|
||||
use std::io::Read;
|
||||
use std::net::SocketAddr;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::str;
|
||||
use std::sync::{mpsc, Arc};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
@@ -31,6 +32,7 @@ use p2p;
|
||||
use util::LOGGER;
|
||||
|
||||
const SEEDS_URL: &'static str = "http://grin-tech.org/seeds.txt";
|
||||
const DNS_SEEDS: &'static [&'static str] = &["seed.grin-tech.org", "seed.grin.lesceller.com"];
|
||||
|
||||
pub fn connect_and_monitor(
|
||||
p2p_server: Arc<p2p::Server>,
|
||||
@@ -231,6 +233,32 @@ fn listen_for_addrs(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dns_seeds() -> Box<Fn() -> Vec<SocketAddr> + Send> {
|
||||
Box::new(|| {
|
||||
let mut addresses: Vec<SocketAddr> = vec![];
|
||||
for dns_seed in DNS_SEEDS {
|
||||
let temp_addresses = addresses.clone();
|
||||
debug!(LOGGER, "Retrieving seed nodes from dns {}", dns_seed);
|
||||
match (dns_seed.to_owned(), 0).to_socket_addrs() {
|
||||
Ok(addrs) => addresses.append(
|
||||
&mut (addrs
|
||||
.map(|mut addr| {
|
||||
addr.set_port(13414);
|
||||
addr
|
||||
})
|
||||
.filter(|addr| !temp_addresses.contains(addr))
|
||||
.collect()),
|
||||
),
|
||||
Err(e) => debug!(
|
||||
LOGGER,
|
||||
"Failed to resolve seed {:?} got error {:?}", dns_seed, e
|
||||
),
|
||||
}
|
||||
}
|
||||
addresses
|
||||
})
|
||||
}
|
||||
|
||||
/// Extract the list of seeds from a pre-defined text file available through
|
||||
/// http. Easy method until we have a set of DNS names we can rely on.
|
||||
pub fn web_seeds() -> Box<Fn() -> Vec<SocketAddr> + Send> {
|
||||
|
||||
@@ -168,6 +168,7 @@ impl Server {
|
||||
seed::predefined_seeds(vec![])
|
||||
}
|
||||
Seeding::List => seed::predefined_seeds(config.seeds.as_mut().unwrap().clone()),
|
||||
Seeding::DNSSeed => seed::dns_seeds(),
|
||||
Seeding::WebStatic => seed::web_seeds(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
@@ -111,6 +111,8 @@ pub enum Seeding {
|
||||
List,
|
||||
/// Automatically download a text file with a list of server addresses
|
||||
WebStatic,
|
||||
/// Automatically get a list of seeds from mutliple DNS
|
||||
DNSSeed,
|
||||
/// Mostly for tests, where connections are initiated programmatically
|
||||
Programmatic,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user