Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit 9dc0c33

Browse files
committed
fix(http): plan for future support of multiple profiles
1 parent ded7549 commit 9dc0c33

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

http/src/config.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub enum InitializationError {
5858
pub fn initialize(
5959
ipfs_path: &Path,
6060
bits: NonZeroU16,
61-
profile: Profile,
61+
profiles: Vec<Profile>,
6262
) -> Result<(), InitializationError> {
6363
let config_path = ipfs_path.join("config");
6464

@@ -67,10 +67,14 @@ pub fn initialize(
6767
.and_then(|_| {
6868
fs::File::create(&config_path).map_err(InitializationError::ConfigCreationFailed)
6969
})
70-
.and_then(|config_file| create(config_file, bits, profile))
70+
.and_then(|config_file| create(config_file, bits, profiles))
7171
}
7272

73-
fn create(config: File, bits: NonZeroU16, profile: Profile) -> Result<(), InitializationError> {
73+
fn create(
74+
config: File,
75+
bits: NonZeroU16,
76+
profiles: Vec<Profile>,
77+
) -> Result<(), InitializationError> {
7478
use multibase::Base::Base64Pad;
7579
use prost::Message;
7680
use std::io::BufWriter;
@@ -82,19 +86,6 @@ fn create(config: File, bits: NonZeroU16, profile: Profile) -> Result<(), Initia
8286
return Err(InitializationError::InvalidRsaKeyLength(bits));
8387
}
8488

85-
// if profiles.len() != 1 || profiles[0] != "test" || profiles[0] != "default" {
86-
// // profiles are expected to be (comma separated) "test" as there are no bootstrap peer
87-
// // handling yet. the conformance test cases seem to init `go-ipfs` in this profile where
88-
// // it does not have any bootstrap nodes, and multi node tests later call swarm apis to
89-
// // dial the nodes together.
90-
// return Err(InitializationError::InvalidProfile(profiles));
91-
// }
92-
93-
let api_addrs = match profile {
94-
Profile::Test => "127.0.0.1:0",
95-
Profile::Default => "127.0.0.1:4004",
96-
};
97-
9889
let pk = openssl::rsa::Rsa::generate(bits as u32)
9990
.map_err(|e| InitializationError::KeyGeneration(Box::new(e)))?;
10091

@@ -133,6 +124,19 @@ fn create(config: File, bits: NonZeroU16, profile: Profile) -> Result<(), Initia
133124

134125
let private_key = Base64Pad.encode(&private_key);
135126

127+
if profiles.len() != 1 {
128+
// profiles are expected to be (comma separated) "test" as there are no bootstrap peer
129+
// handling yet. the conformance test cases seem to init `go-ipfs` in this profile where
130+
// it does not have any bootstrap nodes, and multi node tests later call swarm apis to
131+
// dial the nodes together.
132+
unimplemented!("Multiple profiles are currently unsupported!")
133+
}
134+
135+
let api_addrs = match profiles[0] {
136+
Profile::Test => "127.0.0.1:0",
137+
Profile::Default => "127.0.0.1:4004",
138+
};
139+
136140
let config_contents = CompatibleConfigFile {
137141
identity: Identity {
138142
peer_id,

http/src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ enum Options {
1616
/// Generated key length
1717
#[structopt(long)]
1818
bits: NonZeroU16,
19-
/// List of configuration profiles to apply
20-
#[structopt(long)]
21-
profile: config::Profile,
19+
/// List of configuration profiles to apply. Currently only the `Test` and `Default`
20+
/// profiles are supported.
21+
///
22+
/// `Test` uses ephemeral ports, `Default` uses `4004`.
23+
#[structopt(long, use_delimiter = true)]
24+
profile: Vec<config::Profile>,
2225
},
2326
/// Start the IPFS node in the foreground (not detaching from parent process).
2427
Daemon,
@@ -202,8 +205,6 @@ fn serve<Types: IpfsTypes>(
202205

203206
let ipfs = ipfs.clone();
204207

205-
println!("SOCKET_ADDR: {:?}", listening_addrs);
206-
207208
warp::serve(routes).bind_with_graceful_shutdown(listening_addrs, async move {
208209
shutdown_rx.next().await;
209210
info!("Shutdown trigger received; starting shutdown");

0 commit comments

Comments
 (0)