summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-05-22 16:51:07 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-05-22 16:51:07 +0200
commit4216fe15db7d2bfa43ceef6ac939157353a312c8 (patch)
treeb2a296901f4e9acc607e8b20983b0a2f13738ec0
parentfa655bbe8acae9c7f5d46e977ebea01ac0572327 (diff)
Update ipfs-embed impl
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml9
-rw-r--r--src/backend/backend.rs8
-rw-r--r--src/main.rs31
-rw-r--r--src/profile.rs2
4 files changed, 32 insertions, 18 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d557fb9..27e3357 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,18 +20,21 @@ edition = "2018"
anyhow = "1"
async-trait = "0.1"
-cid = "0.6"
chrono = "0.4"
+cid = "0.6"
clap-v3 = "3.0.0-beta.1"
daglib = { git = "https://git.sr.ht/~matthiasbeyer/daglib", branch = "master" }
-ipfs-embed = "0.19"
+ipfs-embed = { version = "0.20", features = ["tokio"] }
libipld = "0.11"
libipld-cbor = "0.11"
-libp2p = "0.36"
+libp2p = "*"
libp2p-bitswap = "*"
libp2p-core = "*"
libp2p-gossipsub = "*"
libp2p-ping = "*"
mime = "0.3"
+rand_core = { version = "0.6", features = ["getrandom"] }
+rand_os = "0.2"
+ed25519-dalek = "*"
tokio = { version = "1", features = ["full"] }
diff --git a/src/backend/backend.rs b/src/backend/backend.rs
index 33a8906..2f8bdbf 100644
--- a/src/backend/backend.rs
+++ b/src/backend/backend.rs
@@ -20,7 +20,7 @@ impl IpfsEmbedBackend {
impl daglib::DagBackend<Id, Node> for IpfsEmbedBackend {
async fn get(&self, id: Id) -> Result<Option<(Id, Node)>> {
- let block = self.ipfs.fetch(id.as_ref()).await?;
+ let block = self.ipfs.fetch(id.as_ref(), self.ipfs.peers()).await?;
let node = block.decode::<libipld::cbor::DagCborCodec, crate::backend::Node>()?;
Ok(Some((id, node)))
}
@@ -29,8 +29,7 @@ impl daglib::DagBackend<Id, Node> for IpfsEmbedBackend {
let block = libipld::block::Block::encode(libipld::cbor::DagCborCodec, libipld::multihash::Code::Blake3_256, &node)?;
let cid = Id::from(block.cid().clone());
self.ipfs
- .insert(&block)?
- .await
+ .insert(&block)
.map(|_| cid)
}
}
@@ -53,8 +52,7 @@ impl IpfsEmbedBackend {
pub async fn write_payload(&self, payload: &crate::backend::Payload) -> Result<cid::Cid> {
let block = libipld::block::Block::encode(libipld::cbor::DagCborCodec, libipld::multihash::Code::Blake3_256, &payload)?;
self.ipfs
- .insert(&block)?
- .await
+ .insert(&block)
.map(|_| block.cid().clone())
}
}
diff --git a/src/main.rs b/src/main.rs
index ca89d15..145a3d9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,11 @@ use std::path::PathBuf;
use anyhow::Result;
use daglib::DagBackend;
+use rand_os::OsRng;
+use rand_core::CryptoRng;
+use rand_core::RngCore;
+use ed25519_dalek::Keypair;
+use ed25519_dalek::Signature;
extern crate clap_v3 as clap;
@@ -27,16 +32,22 @@ async fn main() -> Result<()> {
gc_target_duration: std::time::Duration::from_secs(60), // 1 minute
};
+ let mut csprng = OsRng{};
let nconf = ipfs_embed::NetworkConfig {
- node_key: libp2p_core::identity::Keypair::generate_ed25519(),
node_name: String::from("distrox-devel"),
- enable_mdns: false, // don't know what this is, yet
- enable_kad: false, // don't know what this is, yet
- allow_non_globals_in_dht: false, // don't know what this is, yet
- psk: None, // Pre shared key for pnet.
- ping: libp2p_ping::PingConfig::new(), // Ping config.
- gossipsub: libp2p_gossipsub::GossipsubConfig::default(), // Gossipsub config.
- bitswap: ipfs_embed::BitswapConfig::new(), // Bitswap config.
+ node_key: ipfs_embed::Keypair::generate(&mut csprng),
+
+ quic: ipfs_embed::TransportConfig::default(),
+ psk: None,
+ dns: None,
+ mdns: None,
+ kad: None,
+ ping: None,
+ identify: None,
+ gossipsub: None,
+ broadcast: None,
+ bitswap: None,
+
};
let ipfs_configuration = ipfs_embed::Config {
@@ -46,7 +57,9 @@ async fn main() -> Result<()> {
crate::backend::IpfsEmbedBackend::new_with_config(ipfs_configuration).await?
};
- backend.ipfs().listen_on("/ip4/127.0.0.1/tcp/0".parse()?).await?;
+ //backend.ipfs()
+ // .listen_on("/ip4/127.0.0.1/tcp/0".parse()?)?
+ // .await?;
match app.get_matches().subcommand() {
("create-profile", Some(mtch)) => {
diff --git a/src/profile.rs b/src/profile.rs
index 091412f..edd8355 100644
--- a/src/profile.rs
+++ b/src/profile.rs
@@ -59,7 +59,7 @@ impl LoadedNode {
let payload = {
let ipfs = backend.ipfs();
- let block = ipfs.fetch(node.payload_id()).await?;
+ let block = ipfs.fetch(node.payload_id(), ipfs.peers()).await?;
block.decode::<libipld::cbor::DagCborCodec, crate::backend::Payload>()?
};