Skip to content

Commit

Permalink
Fixing cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sameh-farouk committed Sep 5, 2023
1 parent c1606b0 commit 6746c31
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/bins/rmb-peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rmb::identity::KeyType;
use rmb::identity::{Identity, Signer};
use rmb::peer::Pair;
use rmb::peer::{self, storage::RedisStorage};
use rmb::twin::{SubstrateTwinDB, TwinDB, RelayDomains};
use rmb::twin::{RelayDomains, SubstrateTwinDB, TwinDB};
use rmb::{identity, redis};

/// A peer requires only which rely to connect to, and
Expand Down Expand Up @@ -87,7 +87,8 @@ fn parse_urls(input: &[String]) -> Result<Vec<url::Url>> {

// maps a &Vec<url::Url> to a HashSet<String> that contains the domain name of each URL
fn get_domains(urls: &[url::Url]) -> RelayDomains {
let h = urls.iter()
let h = urls
.iter()
.filter_map(|url| url.domain())
.map(|domain| domain.to_string())
.collect::<Vec<_>>();
Expand Down
20 changes: 10 additions & 10 deletions src/relay/federation/router.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
relay::switch::{Sink, StreamID},
twin::TwinDB,
twin::RelayDomains,
twin::TwinDB,
types::Envelope,
};
use anyhow::{Context, Result};
Expand Down Expand Up @@ -30,15 +30,15 @@ where

async fn try_send<'a>(&self, domains: &'a RelayDomains, msg: Vec<u8>) -> Result<&'a str> {
// TODO: FIX ME
for domain in domains.iter() {
let url = if cfg!(test) {
format!("http://{}/", domain)
} else {
format!("https://{}/", domain)
};
log::debug!("federation to: {}", url);
let client = Client::new();
for _ in 0..3 {
for _ in 0..3 {
for domain in domains.iter() {
let url = if cfg!(test) {
format!("http://{}/", domain)
} else {
format!("https://{}/", domain)
};
log::debug!("federation to: {}", url);
let client = Client::new();
let resp = match client.post(&url).body(msg.clone()).send().await {
Ok(resp) => resp,
Err(err) => {
Expand Down
17 changes: 12 additions & 5 deletions src/twin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ mod substrate;
use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, fmt::{Display, Formatter}, str::FromStr};
use std::{
collections::HashSet,
fmt::{Display, Formatter},
str::FromStr,
};
pub use substrate::*;
use subxt::utils::AccountId32;

Expand Down Expand Up @@ -44,7 +48,8 @@ impl FromStr for RelayDomains {
type Err = &'static str;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let set = s.split('_')
let set = s
.split('_')
.map(|s| s.to_string())
.collect::<HashSet<String>>();
Ok(RelayDomains(set))
Expand All @@ -53,7 +58,9 @@ impl FromStr for RelayDomains {

impl Display for RelayDomains {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s = self.0.iter()
let s = self
.0
.iter()
.map(|t| t.to_string())
.collect::<Vec<_>>()
.join("_");
Expand All @@ -63,7 +70,7 @@ impl Display for RelayDomains {

impl RelayDomains {
pub fn new(inner: &[String]) -> Self {
Self (inner.iter().cloned().collect())
Self(inner.iter().cloned().collect())
}

pub fn contains(&self, domain: &str) -> bool {
Expand All @@ -73,4 +80,4 @@ impl RelayDomains {
pub fn iter(&self) -> std::collections::hash_set::Iter<String> {
self.0.iter()
}
}
}
6 changes: 1 addition & 5 deletions src/twin/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use super::TwinDB;
use crate::cache::Cache;
use anyhow::Result;
use async_trait::async_trait;
use itertools::Itertools;
use std::collections::HashSet;
use std::sync::Arc;
use subxt::utils::AccountId32;
use subxt::Error as ClientError;
Expand Down Expand Up @@ -49,9 +47,7 @@ where
pk: Option<&[u8]>,
) -> Result<()> {
let client = self.client.lock().await;
let hash = client
.update_twin(kp, Some(relay.to_string()), pk)
.await?;
let hash = client.update_twin(kp, Some(relay.to_string()), pk).await?;
log::debug!("hash: {:?}", hash);
Ok(())
}
Expand Down

0 comments on commit 6746c31

Please sign in to comment.