Skip to content

Commit

Permalink
PeerAddr everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed Feb 14, 2019
1 parent 72bd890 commit 1298b4a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 58 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ pub use crate::peers::Peers;
pub use crate::serv::{DummyAdapter, Server};
pub use crate::store::{PeerData, State};
pub use crate::types::{
Capabilities, ChainAdapter, Direction, Error, P2PConfig, PeerInfo, ReasonForBan, Seeding,
TxHashSetRead, MAX_BLOCK_HEADERS, MAX_LOCATORS, MAX_PEER_ADDRS,
Capabilities, ChainAdapter, Direction, Error, P2PConfig, PeerAddr, PeerInfo, ReasonForBan,
Seeding, TxHashSetRead, MAX_BLOCK_HEADERS, MAX_LOCATORS, MAX_PEER_ADDRS,
};
2 changes: 1 addition & 1 deletion p2p/src/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Peers {
pub adapter: Arc<dyn ChainAdapter>,
store: PeerStore,
peers: RwLock<HashMap<PeerAddr, Arc<Peer>>>,
dandelion_relay: RwLock<HashMap<i64, Arc<Peer>>>,
dandelion_relay: RwLock<Option<(i64, Arc<Peer>)>>,
config: P2PConfig,
}

Expand Down
2 changes: 1 addition & 1 deletion p2p/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Eq for PeerAddr {}

impl std::fmt::Display for PeerAddr {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "PeerAddr({})", self.0)
write!(f, "{}", self.0)
}
}

Expand Down
19 changes: 7 additions & 12 deletions servers/src/grin/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use chrono::prelude::{DateTime, Utc};
use chrono::{Duration, MIN_DATE};
use rand::{thread_rng, Rng};
use std::collections::HashMap;
use std::net::{SocketAddr, ToSocketAddrs};
use std::net::ToSocketAddrs;
use std::sync::{mpsc, Arc};
use std::{cmp, str, thread, time};

Expand Down Expand Up @@ -395,17 +395,12 @@ pub fn dns_seeds() -> Box<dyn Fn() -> Vec<PeerAddr> + Send> {
})
}

// /// Convenience function when the seed list is immediately known. Mostly used
// /// for tests.
// pub fn predefined_seeds(addrs_str: Vec<PeerAddr>) -> Box<dyn Fn() -> Vec<PeerAddr> + Send> {
// Box::new(move || {
// addrs_str
// .iter()
// .map(|s| PeerAddr(s.parse().unwrap()))
// .collect::<Vec<_>>()
// })
// }
//
/// Convenience function when the seed list is immediately known. Mostly used
/// for tests.
pub fn predefined_seeds(addrs: Vec<PeerAddr>) -> Box<dyn Fn() -> Vec<PeerAddr> + Send> {
Box::new(move || addrs.clone())
}

// /// Convenience function when the seed list is immediately known. Mostly used
// /// for tests.
// pub fn preferred_peers(addrs_str: Vec<PeerAddr>) -> Option<Vec<PeerAddr>> {
Expand Down
11 changes: 6 additions & 5 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//! the peer-to-peer server, the blockchain and the transaction pool) and acts
//! as a facade.
use std::net::SocketAddr;
use std::sync::Arc;
use std::{thread, time};

Expand Down Expand Up @@ -104,7 +103,7 @@ impl Server {
}

/// Instantiates a new server associated with the provided future reactor.
pub fn new(mut config: ServerConfig) -> Result<Server, Error> {
pub fn new(config: ServerConfig) -> Result<Server, Error> {
// Defaults to None (optional) in config file.
// This translates to false here.
let archive_mode = match config.archive_mode {
Expand Down Expand Up @@ -183,9 +182,11 @@ impl Server {
let seeder = match config.p2p_config.seeding_type {
p2p::Seeding::None => {
warn!("No seed configured, will stay solo until connected to");
vec![]
seed::predefined_seeds(vec![])
}
p2p::Seeding::List => {
seed::predefined_seeds(config.p2p_config.seeds.clone().unwrap())
}
p2p::Seeding::List => config.p2p_config.seeds.unwrap_or(vec![]),
p2p::Seeding::DNSSeed => seed::dns_seeds(),
_ => unreachable!(),
};
Expand All @@ -195,7 +196,7 @@ impl Server {
config.p2p_config.capabilities,
config.dandelion_config.clone(),
seeder,
config.p2p_config.peers_preferred,
config.p2p_config.peers_preferred.clone(),
stop_state.clone(),
);
}
Expand Down
43 changes: 6 additions & 37 deletions src/bin/cmd/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

/// Grin server commands processing
#[cfg(not(target_os = "windows"))]
use std::env::current_dir;
use std::process::exit;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
Expand All @@ -26,7 +25,7 @@ use ctrlc;

use crate::config::GlobalConfig;
use crate::core::global;
use crate::p2p::Seeding;
use crate::p2p::{PeerAddr, Seeding};
use crate::servers;
use crate::tui::ui;

Expand Down Expand Up @@ -118,45 +117,15 @@ pub fn server_command(
}

if let Some(seeds) = a.values_of("seed") {
let seed_addrs = seeds
.filter_map(|x| x.parse().ok())
.map(|x| PeerAddr(x))
.collect();
server_config.p2p_config.seeding_type = Seeding::List;
server_config.p2p_config.seeds = Some(seeds.map(|s| s.to_string()).collect());
server_config.p2p_config.seeds = Some(seed_addrs);
}
}

/*if let Some(true) = server_config.run_wallet_listener {
let mut wallet_config = global_config.members.as_ref().unwrap().wallet.clone();
wallet::init_wallet_seed(wallet_config.clone());
let wallet = wallet::instantiate_wallet(wallet_config.clone(), "");
let _ = thread::Builder::new()
.name("wallet_listener".to_string())
.spawn(move || {
controller::foreign_listener(wallet, &wallet_config.api_listen_addr())
.unwrap_or_else(|e| {
panic!(
"Error creating wallet listener: {:?} Config: {:?}",
e, wallet_config
)
});
});
}
if let Some(true) = server_config.run_wallet_owner_api {
let mut wallet_config = global_config.members.unwrap().wallet;
let wallet = wallet::instantiate_wallet(wallet_config.clone(), "");
wallet::init_wallet_seed(wallet_config.clone());
let _ = thread::Builder::new()
.name("wallet_owner_listener".to_string())
.spawn(move || {
controller::owner_listener(wallet, "127.0.0.1:13420").unwrap_or_else(|e| {
panic!(
"Error creating wallet api listener: {:?} Config: {:?}",
e, wallet_config
)
});
});
}*/

if let Some(a) = server_args {
match a.subcommand() {
("run", _) => {
Expand Down

0 comments on commit 1298b4a

Please sign in to comment.