Merge #387
387: fix: restore bootstrappers from static list, update the bootstrapper list r=koivunej a=ljedrz Alters the `BOOTSTRAP_NODES` list to contain only the currently working addresses and changes the behavior of `Swarm::remove_bootstrappers` to not use the config file, but rather the aforementioned in-memory list. Cc https://github.com/rs-ipfs/rust-ipfs/issues/356 Co-authored-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
commit
335a23a6a5
@ -5,7 +5,7 @@
|
||||
|
||||
const peers = res.Peers
|
||||
- expect(peers).to.have.property('length').that.is.gt(1)
|
||||
+ expect(peers).to.have.property('length').that.is.eq(0)
|
||||
+ expect(peers).to.have.property('length').that.is.gt(0)
|
||||
})
|
||||
|
||||
it('should return a list of all peers removed when all option is passed', async () => {
|
||||
|
@ -7,17 +7,8 @@ use std::fs;
|
||||
use std::path::Path;
|
||||
use thiserror::Error;
|
||||
|
||||
const BOOTSTRAP_NODES: &[&str] = &[
|
||||
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
|
||||
"/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
|
||||
"/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
|
||||
"/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
|
||||
"/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
|
||||
"/ip6/2400:6180:0:d0::151:6001/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
|
||||
"/ip6/2604:a880:1:20::203:d001/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
|
||||
"/ip6/2604:a880:800:10::4a:5001/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
|
||||
"/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
|
||||
];
|
||||
pub const BOOTSTRAP_NODES: &[&str] =
|
||||
&["/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"];
|
||||
|
||||
/// See test cases for examples how to write such file.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
@ -1,5 +1,6 @@
|
||||
use super::pubsub::Pubsub;
|
||||
use super::swarm::{Connection, Disconnector, SwarmApi};
|
||||
use crate::config::BOOTSTRAP_NODES;
|
||||
use crate::p2p::{MultiaddrWithPeerId, SwarmOptions};
|
||||
use crate::repo::BlockPut;
|
||||
use crate::subscription::{SubscriptionFuture, SubscriptionRegistry};
|
||||
@ -17,7 +18,7 @@ use libp2p::swarm::toggle::Toggle;
|
||||
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourEventProcess};
|
||||
use libp2p::NetworkBehaviour;
|
||||
use multibase::Base;
|
||||
use std::{collections::HashSet, convert::TryInto, env, fs::File, path::PathBuf, sync::Arc};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
use tokio::task;
|
||||
|
||||
/// Behaviour type.
|
||||
@ -594,34 +595,15 @@ impl<Types: IpfsTypes> Behaviour<Types> {
|
||||
}
|
||||
|
||||
pub fn restore_bootstrappers(&mut self) -> Result<Vec<Multiaddr>, anyhow::Error> {
|
||||
let mut config_location = PathBuf::from(env::var("IPFS_PATH")?);
|
||||
config_location.push("config");
|
||||
let mut config_reader = File::open(config_location)?;
|
||||
let config_file: serde_json::Value = serde_json::from_reader(&mut config_reader)?;
|
||||
let mut ret = HashSet::new();
|
||||
|
||||
if let Some(addrs) = config_file
|
||||
.as_object()
|
||||
.expect("the config JSON is an object")
|
||||
.get("Bootstrap")
|
||||
{
|
||||
let addrs = addrs
|
||||
.as_array()
|
||||
.expect("the Bootstrap key contains an array");
|
||||
|
||||
ret.reserve(addrs.len());
|
||||
for addr in addrs {
|
||||
let addr: MultiaddrWithPeerId = addr
|
||||
.as_str()
|
||||
.expect("the members of the Bootstrap array are strings")
|
||||
.parse()
|
||||
.expect("the config file had already been parsed on startup");
|
||||
self.swarm.bootstrappers.insert(addr.clone());
|
||||
ret.insert(addr.into());
|
||||
}
|
||||
for addr in BOOTSTRAP_NODES {
|
||||
let addr = addr.parse::<MultiaddrWithPeerId>().unwrap();
|
||||
self.swarm.bootstrappers.insert(addr);
|
||||
}
|
||||
|
||||
Ok(ret.into_iter().collect())
|
||||
Ok(BOOTSTRAP_NODES
|
||||
.iter()
|
||||
.map(|addr| addr.parse().unwrap())
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user