Function holochain::conductor::p2p_agent_store::inject_agent_infos
source · pub async fn inject_agent_infos<'iter, I: IntoIterator<Item = &'iter AgentInfoSigned> + Send>(
env: DbWrite<DbKindP2pAgents>,
iter: I
) -> StateMutationResult<()>
Expand description
Inject multiple agent info entries into the peer store
Examples found in repository?
src/conductor/p2p_agent_store.rs (line 134)
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
pub async fn exchange_peer_info(envs: Vec<DbWrite<DbKindP2pAgents>>) {
for (i, a) in envs.iter().enumerate() {
let infos_a = all_agent_infos(a.clone().into()).await.unwrap();
for (j, b) in envs.iter().enumerate() {
if i == j {
continue;
}
let infos_b = all_agent_infos(b.clone().into()).await.unwrap();
inject_agent_infos(a.clone(), infos_b.iter()).await.unwrap();
inject_agent_infos(b.clone(), infos_a.iter()).await.unwrap();
}
}
}
/// Interconnect provided pair of conductors via their peer store databases,
/// according to the connectivity matrix
#[cfg(any(test, feature = "test_utils"))]
pub async fn exchange_peer_info_sparse(
envs: Vec<DbWrite<DbKindP2pAgents>>,
connectivity: Vec<HashSet<usize>>,
) {
assert_eq!(envs.len(), connectivity.len());
for (i, a) in envs.iter().enumerate() {
let infos_a = all_agent_infos(a.clone().into()).await.unwrap();
for (j, b) in envs.iter().enumerate() {
if i == j {
continue;
}
if !connectivity[j].contains(&i) {
continue;
}
// let infos_b = all_agent_infos(b.clone().into()).await.unwrap();
// inject_agent_infos(a.clone(), infos_b.iter()).await.unwrap();
inject_agent_infos(b.clone(), infos_a.iter()).await.unwrap();
}
}
}
/// Reveal every agent in a single conductor to every agent in another.
#[cfg(any(test, feature = "test_utils"))]
pub async fn reveal_peer_info(
observer_envs: Vec<DbWrite<DbKindP2pAgents>>,
seen_envs: Vec<DbWrite<DbKindP2pAgents>>,
) {
for observer in observer_envs.iter() {
for seen in seen_envs.iter() {
inject_agent_infos(
observer.clone(),
all_agent_infos(seen.clone().into()).await.unwrap().iter(),
)
.await
.unwrap();
}
}
}
More examples
src/conductor/conductor.rs (line 1971)
1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
pub async fn add_agent_infos(
&self,
agent_infos: Vec<AgentInfoSigned>,
) -> ConductorApiResult<()> {
let mut space_map = HashMap::new();
for agent_info_signed in agent_infos {
let space = agent_info_signed.space.clone();
space_map
.entry(space)
.or_insert_with(Vec::new)
.push(agent_info_signed);
}
for (space, agent_infos) in space_map {
let db = self.p2p_agents_db(&DnaHash::from_kitsune(&space));
inject_agent_infos(db, agent_infos.iter()).await?;
}
Ok(())
}