Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Switch from devp2p to libp2p #268

Merged
merged 35 commits into from
Jul 15, 2018
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a94e7e7
Switch from devp2p to libp2p
tomaka May 22, 2018
a514ed3
Move the keys in the network state
tomaka Jun 30, 2018
1cfc18e
Properly load, store or generate private key
tomaka Jun 30, 2018
0e30b5d
Some robustness
tomaka Jun 30, 2018
536edd6
Merge remote-tracking branch 'upstream/master' into tka-libp2p
tomaka Jul 2, 2018
21ab784
Update for latest libp2p
tomaka Jul 2, 2018
fb17f77
Allow secio
tomaka Jul 2, 2018
329b7dc
Don't open a new Kademlia connec all the time
tomaka Jul 2, 2018
abe756c
Handle Kademlia disconnection
tomaka Jul 2, 2018
1131498
Set correct permissions on key file
tomaka Jul 2, 2018
d1d38d7
Improvements to secret key storage
tomaka Jul 2, 2018
2277a5f
Flush the peer store at Kademlia requests
tomaka Jul 2, 2018
224f6b1
Use RAII guards for disconnection
tomaka Jul 2, 2018
77092a3
Some misc work
tomaka Jul 3, 2018
18ee06f
Set informations about peers
tomaka Jul 3, 2018
4ad5da7
Fix tests and external URL
tomaka Jul 3, 2018
fdc5fbf
Merge remote-tracking branch 'upstream/master' into tka-libp2p
tomaka Jul 3, 2018
9e06c31
Fix some style
tomaka Jul 3, 2018
5e74817
Split obtain_private_key into multiple function
tomaka Jul 4, 2018
293cbdf
Split start_kademlia_discovery in multiple functions
tomaka Jul 4, 2018
95c79fc
More style fixes
tomaka Jul 4, 2018
e8f743c
More style fixes
tomaka Jul 6, 2018
61e3e57
Merge remote-tracking branch 'upstream/master' into tka-libp2p
tomaka Jul 6, 2018
533f53d
Fix some concerns
tomaka Jul 6, 2018
fc5a342
Turn // into ///
tomaka Jul 7, 2018
e5390ab
More style fixes
tomaka Jul 8, 2018
2316ebb
Merge remote-tracking branch 'upstream/master' into tka-libp2p
tomaka Jul 10, 2018
ce3b819
More style fixes
tomaka Jul 10, 2018
b9b54b3
Merge remote-tracking branch 'upstream/master' into tka-libp2p
tomaka Jul 11, 2018
dfa92bc
Merge remote-tracking branch 'origin/master' into tka-libp2p
gavofyork Jul 12, 2018
e9757a4
Add annotations to unreachable!
tomaka Jul 13, 2018
6731f05
Fix style again
tomaka Jul 13, 2018
06b5498
Remove commented out code
tomaka Jul 13, 2018
ab89ef9
Fix test year
tomaka Jul 13, 2018
1a942a2
More concerns
tomaka Jul 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Set correct permissions on key file
  • Loading branch information
tomaka committed Jul 2, 2018
commit 1131498c0ab28823789d977686893f49919d0129
25 changes: 21 additions & 4 deletions substrate/network-libp2p/src/network_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use network::{PeerId, ProtocolId, SessionInfo};
use parking_lot::{Mutex, RwLock};
use rand::{self, Rng};
use std::cmp;
use std::fs::File;
use std::fs;
use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read, Write};
use std::path::Path;
use std::sync::atomic;
Expand Down Expand Up @@ -682,7 +682,7 @@ fn obtain_private_key(config: &NetworkConfiguration) -> Result<secio::SecioKeyPa
} else {
if let Some(ref path) = config.net_config_path {
let secret_path = Path::new(path).join(SECRET_FILE);
let loaded_secret = File::open(&secret_path)
let loaded_secret = fs::File::open(&secret_path)
.and_then(|mut file| {
// We are in 2018 and there is still no method on `std::io::Read` that
// directly returns a `Vec`.
Expand All @@ -700,10 +700,9 @@ fn obtain_private_key(config: &NetworkConfiguration) -> Result<secio::SecioKeyPa
let raw_key: [u8; 32] = rand::rngs::EntropyRng::new().gen();
let secio_key = secio::SecioKeyPair::secp256k1_raw_key(&raw_key)
.map_err(|err| IoError::new(IoErrorKind::InvalidData, err))?;
if let Ok(mut file) = File::create(&secret_path) {
if let Ok(mut file) = open_priv_key_file(&secret_path) {
let _ = file.write_all(&raw_key);
}
// TODO: chmod the file
secio_key
}

Expand All @@ -716,6 +715,24 @@ fn obtain_private_key(config: &NetworkConfiguration) -> Result<secio::SecioKeyPa
})
}

// Opens a file containing a private key in write mode.
#[cfg(unix)]
fn open_priv_key_file(path: impl AsRef<Path>) -> Result<fs::File, IoError> {
use std::os::unix::fs::OpenOptionsExt;
fs::OpenOptions::new()
.write(true)
.create_new(true)
.mode(600)
.open(path)
}
#[cfg(not(unix))]
fn open_priv_key_file(path: impl AsRef<Path>) -> Result<fs::File, IoError> {
fs::OpenOptions::new()
.write(true)
.create_new(true)
.open(path)
}

#[cfg(test)]
mod tests {
use futures::sync::mpsc;
Expand Down