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

Commit 2b94bdc

Browse files
committed
fix(http): check for single profile before creating dir + config
1 parent 9dc0c33 commit 2b94bdc

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

http/src/config.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ pub fn initialize(
6060
bits: NonZeroU16,
6161
profiles: Vec<Profile>,
6262
) -> Result<(), InitializationError> {
63+
// This check is done here to avoid an empty config file being created in the case of an
64+
// unsupported input.
65+
if profiles.len() != 1 {
66+
// profiles are expected to be (comma separated) "test" as there are no bootstrap peer
67+
// handling yet. the conformance test cases seem to init `go-ipfs` in this profile where
68+
// it does not have any bootstrap nodes, and multi node tests later call swarm apis to
69+
// dial the nodes together.
70+
unimplemented!("Multiple profiles are currently unsupported!");
71+
}
72+
6373
let config_path = ipfs_path.join("config");
6474

6575
fs::create_dir_all(&ipfs_path)
@@ -79,6 +89,11 @@ fn create(
7989
use prost::Message;
8090
use std::io::BufWriter;
8191

92+
let api_addrs = match profiles[0] {
93+
Profile::Test => "127.0.0.1:0",
94+
Profile::Default => "127.0.0.1:4004",
95+
};
96+
8297
let bits = bits.get();
8398

8499
if bits < 2048 || bits > 16 * 1024 {
@@ -124,19 +139,6 @@ fn create(
124139

125140
let private_key = Base64Pad.encode(&private_key);
126141

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-
140142
let config_contents = CompatibleConfigFile {
141143
identity: Identity {
142144
peer_id,

http/src/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum Options {
1919
/// List of configuration profiles to apply. Currently only the `Test` and `Default`
2020
/// profiles are supported.
2121
///
22-
/// `Test` uses ephemeral ports, `Default` uses `4004`.
22+
/// `Test` uses ephemeral ports (necessary for conformance tests), `Default` uses `4004`.
2323
#[structopt(long, use_delimiter = true)]
2424
profile: Vec<config::Profile>,
2525
},
@@ -157,11 +157,6 @@ fn main() {
157157

158158
let api_link_file = home.join("api");
159159

160-
// If the port is specified, use that to start the server, if it isn't use ephemeral ports,
161-
// i.e.:
162-
//
163-
// port => port
164-
// none => 0
165160
let (addr, server) = serve(&ipfs, api_listening_addrs);
166161

167162
// shutdown future will handle signalling the exit

0 commit comments

Comments
 (0)