1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![warn(missing_docs)]
use async_trait::async_trait;
use crate::dht::ChordStorage;
use crate::dht::PeerRingAction;
use crate::dht::PeerRingRemoteAction;
use crate::err::Error;
use crate::err::Result;
use crate::message::types::Message;
use crate::message::PayloadSender;
use crate::prelude::vnode::VNodeOperation;
use crate::swarm::Swarm;
#[cfg_attr(feature = "wasm", async_trait(?Send))]
#[cfg_attr(not(feature = "wasm"), async_trait)]
pub trait SubringInterface {
async fn subring_join(&self, name: &str) -> Result<()>;
}
#[cfg_attr(feature = "wasm", async_trait(?Send))]
#[cfg_attr(not(feature = "wasm"), async_trait)]
impl SubringInterface for Swarm {
async fn subring_join(&self, name: &str) -> Result<()> {
let op = VNodeOperation::JoinSubring(name.to_string(), self.dht.did);
match self.dht.vnode_operate(op).await? {
PeerRingAction::None => Ok(()),
PeerRingAction::RemoteAction(target, PeerRingRemoteAction::FindVNodeForOperate(op)) => {
self.send_direct_message(Message::OperateVNode(op), target)
.await?;
Ok(())
}
act => Err(Error::PeerRingUnexpectedAction(act)),
}
}
}