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

Commit 335a23a

Browse files
bors[bot]ljedrz
andauthored
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 #356 Co-authored-by: ljedrz <[email protected]>
2 parents 8b4c34c + fef8e7c commit 335a23a

File tree

3 files changed

+12
-39
lines changed

3 files changed

+12
-39
lines changed

Diff for: conformance/patches/bootstrap.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const peers = res.Peers
77
- expect(peers).to.have.property('length').that.is.gt(1)
8-
+ expect(peers).to.have.property('length').that.is.eq(0)
8+
+ expect(peers).to.have.property('length').that.is.gt(0)
99
})
1010

1111
it('should return a list of all peers removed when all option is passed', async () => {

Diff for: src/config.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,8 @@ use std::fs;
77
use std::path::Path;
88
use thiserror::Error;
99

10-
const BOOTSTRAP_NODES: &[&str] = &[
11-
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
12-
"/ip4/104.236.179.241/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
13-
"/ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
14-
"/ip4/128.199.219.111/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
15-
"/ip4/178.62.158.247/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
16-
"/ip6/2400:6180:0:d0::151:6001/tcp/4001/p2p/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
17-
"/ip6/2604:a880:1:20::203:d001/tcp/4001/p2p/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
18-
"/ip6/2604:a880:800:10::4a:5001/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
19-
"/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
20-
];
10+
pub const BOOTSTRAP_NODES: &[&str] =
11+
&["/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"];
2112

2213
/// See test cases for examples how to write such file.
2314
#[derive(Clone, Debug, Serialize, Deserialize)]

Diff for: src/p2p/behaviour.rs

+9-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::pubsub::Pubsub;
22
use super::swarm::{Connection, Disconnector, SwarmApi};
3+
use crate::config::BOOTSTRAP_NODES;
34
use crate::p2p::{MultiaddrWithPeerId, SwarmOptions};
45
use crate::repo::BlockPut;
56
use crate::subscription::{SubscriptionFuture, SubscriptionRegistry};
@@ -17,7 +18,7 @@ use libp2p::swarm::toggle::Toggle;
1718
use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourEventProcess};
1819
use libp2p::NetworkBehaviour;
1920
use multibase::Base;
20-
use std::{collections::HashSet, convert::TryInto, env, fs::File, path::PathBuf, sync::Arc};
21+
use std::{convert::TryInto, sync::Arc};
2122
use tokio::task;
2223

2324
/// Behaviour type.
@@ -594,34 +595,15 @@ impl<Types: IpfsTypes> Behaviour<Types> {
594595
}
595596

596597
pub fn restore_bootstrappers(&mut self) -> Result<Vec<Multiaddr>, anyhow::Error> {
597-
let mut config_location = PathBuf::from(env::var("IPFS_PATH")?);
598-
config_location.push("config");
599-
let mut config_reader = File::open(config_location)?;
600-
let config_file: serde_json::Value = serde_json::from_reader(&mut config_reader)?;
601-
let mut ret = HashSet::new();
602-
603-
if let Some(addrs) = config_file
604-
.as_object()
605-
.expect("the config JSON is an object")
606-
.get("Bootstrap")
607-
{
608-
let addrs = addrs
609-
.as_array()
610-
.expect("the Bootstrap key contains an array");
611-
612-
ret.reserve(addrs.len());
613-
for addr in addrs {
614-
let addr: MultiaddrWithPeerId = addr
615-
.as_str()
616-
.expect("the members of the Bootstrap array are strings")
617-
.parse()
618-
.expect("the config file had already been parsed on startup");
619-
self.swarm.bootstrappers.insert(addr.clone());
620-
ret.insert(addr.into());
621-
}
598+
for addr in BOOTSTRAP_NODES {
599+
let addr = addr.parse::<MultiaddrWithPeerId>().unwrap();
600+
self.swarm.bootstrappers.insert(addr);
622601
}
623602

624-
Ok(ret.into_iter().collect())
603+
Ok(BOOTSTRAP_NODES
604+
.iter()
605+
.map(|addr| addr.parse().unwrap())
606+
.collect())
625607
}
626608
}
627609

0 commit comments

Comments
 (0)