Skip to content

Commit

Permalink
small clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed Oct 3, 2018
1 parent 6a75aa3 commit 8ae3c9a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
6 changes: 3 additions & 3 deletions lighthouse/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ impl Client {
// Start the network thread
let network_state = NetworkState::new(
&config.data_dir,
&config.p2p_listen_port,
config.p2p_listen_port,
&log).expect("Network setup failed"); let (network_thread, network_tx, network_rx) = {
let (message_sender, message_receiver) = unbounded();
let (event_sender, event_receiver) = unbounded();
let network_log = log.new(o!());
let thread = thread::spawn(move || {
network_listen(
network_state,
event_sender,
&event_sender,
message_receiver,
network_log,
&network_log,
);
});
(thread, message_sender, event_receiver)
Expand Down
1 change: 0 additions & 1 deletion lighthouse/sync/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ fn handle_network_message(
);
Ok(())
}
_ => Ok(())
}
}
Err(_) => {
Expand Down
5 changes: 4 additions & 1 deletion lighthouse/sync/wire_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ pub enum WireMessageDecodeError {
}

pub enum WireMessageHeader {
Blocks,
/*
// Leave out until used
Status,
NewBlockHashes,
GetBlockHashes,
BlockHashes,
GetBlocks,
Blocks,
NewBlock,
*/
}

pub struct WireMessage<'a> {
Expand Down
6 changes: 3 additions & 3 deletions network-libp2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ use self::bytes::Bytes;
pub use self::libp2p_floodsub::Message;

pub fn listen(state: NetworkState,
events_to_app: UnboundedSender<NetworkEvent>,
events_to_app: &UnboundedSender<NetworkEvent>,
raw_rx: UnboundedReceiver<OutgoingMessage>,
log: Logger)
log: &Logger)
{
let peer_store = state.peer_store;
let peer_id = state.peer_id;
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn listen(state: NetworkState,
let kad_config = libp2p_kad::KademliaConfig {
parallelism: 3,
record_store: (),
peer_store: peer_store,
peer_store,
local_peer_id: peer_id.clone(),
timeout: Duration::from_secs(2)
};
Expand Down
26 changes: 13 additions & 13 deletions network-libp2p/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ pub struct NetworkState {
}

impl NetworkState {
/// Create a new libp2p network state. Used to initialize
/// Create a new libp2p network state. Used to initialize
/// network service.
pub fn new(
// config: LighthouseConfig,
// config: LighthouseConfig,
base_dir: &Path,
listen_port: &u16,
log: &Logger)
listen_port: u16,
log: &Logger)
-> Result <Self, Box<Error>>
{
let curve = Secp256k1::new();
let seckey = match
let seckey = match
NetworkState::load_secret_key_from_pem_file(base_dir, &curve)
{
Ok(k) => k,
Expand Down Expand Up @@ -71,23 +71,23 @@ impl NetworkState {

/// Return a TCP multiaddress on 0.0.0.0 for a given port.
pub fn multiaddr_on_port(port: &str) -> Multiaddr {
return format!("/ip4/0.0.0.0/tcp/{}", port)
format!("/ip4/0.0.0.0/tcp/{}", port)
.parse::<Multiaddr>().unwrap()
}

pub fn add_peer(&mut self,
peer_id: PeerId,
peer_id: &PeerId,
multiaddr: Multiaddr,
duration_secs: u64) {
self.peer_store.peer_or_create(&peer_id)
.add_addr(multiaddr, Duration::from_secs(duration_secs));
}

/// Instantiate a SecretKey from a .pem file on disk.
/// Instantiate a SecretKey from a .pem file on disk.
pub fn load_secret_key_from_pem_file(
base_dir: &Path,
curve: &Secp256k1)
-> Result<SecretKey, Box<Error>>
-> Result<SecretKey, Box<Error>>
{
let path = base_dir.join(LOCAL_PEM_FILE);
let mut contents = String::new();
Expand All @@ -97,12 +97,12 @@ impl NetworkState {
let key = SecretKey::from_slice(curve, &pem_key.contents)?;
Ok(key)
}
/// Generate a new SecretKey and store it on disk as a .pem file.

/// Generate a new SecretKey and store it on disk as a .pem file.
pub fn generate_new_secret_key(
base_dir: &Path,
curve: &Secp256k1)
-> Result<SecretKey, Box<Error>>
-> Result<SecretKey, Box<Error>>
{
let mut rng = rand::thread_rng();
let sk = SecretKey::new(&curve, &mut rng);
Expand All @@ -113,7 +113,7 @@ impl NetworkState {
let s_string = pem::encode(&pem_key);
let path = base_dir.join(LOCAL_PEM_FILE);
let mut s_file = File::create(path)?;
s_file.write(s_string.as_bytes())?;
s_file.write_all(s_string.as_bytes())?;
Ok(sk)
}
}

0 comments on commit 8ae3c9a

Please sign in to comment.