1
1
//! go-ipfs compatible configuration file handling or at least setup.
2
2
3
+ use parity_multiaddr:: Multiaddr ;
3
4
use serde:: { Deserialize , Serialize } ;
4
5
use std:: fs:: { self , File } ;
5
6
use std:: num:: NonZeroU16 ;
@@ -115,6 +116,9 @@ fn create(
115
116
peer_id,
116
117
private_key,
117
118
} ,
119
+ addresses : Addresses {
120
+ swarm : vec ! [ "/ip4/127.0.0.1/tcp/0" . parse( ) . unwrap( ) ] ,
121
+ } ,
118
122
} ;
119
123
120
124
serde_json:: to_writer_pretty ( BufWriter :: new ( config) , & config_contents)
@@ -140,12 +144,16 @@ pub enum LoadingError {
140
144
141
145
/// Loads a `go-ipfs` compatible configuration file from the given file.
142
146
///
143
- /// Returns only the [`ipfs::KeyPair`] or [`LoadingError`] but this should be extended to contain
144
- /// the bootstrap nodes at least later when we need to support those for testing purposes.
145
- pub fn load ( config : File ) -> Result < ipfs:: Keypair , LoadingError > {
147
+ /// Returns only the keypair and listening addresses or [`LoadingError`] but this should be
148
+ /// extended to contain the bootstrap nodes at least later when we need to support those for
149
+ /// testing purposes.
150
+ pub fn load ( config : File ) -> Result < ( ipfs:: Keypair , Vec < Multiaddr > ) , LoadingError > {
146
151
use std:: io:: BufReader ;
147
152
148
- let CompatibleConfigFile { identity } = serde_json:: from_reader ( BufReader :: new ( config) )
153
+ let CompatibleConfigFile {
154
+ identity,
155
+ addresses,
156
+ } = serde_json:: from_reader ( BufReader :: new ( config) )
149
157
. map_err ( LoadingError :: ConfigurationFileFormat ) ?;
150
158
151
159
let kp = identity. load_keypair ( ) ?;
@@ -159,7 +167,7 @@ pub fn load(config: File) -> Result<ipfs::Keypair, LoadingError> {
159
167
} ) ;
160
168
}
161
169
162
- Ok ( kp )
170
+ Ok ( ( kp , addresses . swarm ) )
163
171
}
164
172
165
173
/// Converts a PEM format to DER where PEM is a container for Base64 data with padding, starting on
@@ -230,6 +238,13 @@ fn pem_to_der(bytes: &[u8]) -> Vec<u8> {
230
238
#[ serde( rename_all = "PascalCase" ) ]
231
239
struct CompatibleConfigFile {
232
240
identity : Identity ,
241
+ addresses : Addresses ,
242
+ }
243
+
244
+ #[ derive( Debug , Serialize , Deserialize ) ]
245
+ #[ serde( rename_all = "PascalCase" ) ]
246
+ struct Addresses {
247
+ swarm : Vec < Multiaddr > ,
233
248
}
234
249
235
250
#[ derive( Debug , Serialize , Deserialize ) ]
0 commit comments