Skip to content

Commit

Permalink
Merge pull request #522 from holochain/proxy-cleaner
Browse files Browse the repository at this point in the history
[TK-06413] prune bad proxy addrs
  • Loading branch information
neonphog committed Dec 11, 2020
2 parents 2925ba2 + 2214fc3 commit 047531c
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions crates/kitsune_p2p/proxy/src/inner_listen.rs
Expand Up @@ -210,6 +210,8 @@ ghost_actor::ghost_chan! {
futures::channel::mpsc::Receiver<ProxyWire>,
);

fn prune_bad_proxy_to(proxy_url: ProxyUrl) -> ();

fn register_proxy_to(proxy_url: ProxyUrl, base_url: url2::Url2) -> ();

fn req_proxy(proxy_url: ProxyUrl) -> ();
Expand Down Expand Up @@ -371,14 +373,38 @@ impl InternalHandler for InnerListen {
// and the channel create will re-use that.
// If it is not, it will try to create a new connection that may fail.
let fut = match proxy_to {
None => self
.i_s
.create_low_level_channel(dest_proxy_url.as_base().clone()),
None => {
tracing::warn!("Dropping message for {}", dest_proxy_url.as_full_str());
return Ok(async move {
write
.send(ProxyWire::failure(format!(
"Dropped message to {}",
dest_proxy_url.as_full_str()
)))
.await
.map_err(TransportError::other)?;
Ok(())
}
.boxed()
.into());
}
Some(proxy_to) => self.i_s.create_low_level_channel(proxy_to),
};
let i_s = self.i_s.clone();
Ok(async move {
let (mut fwd_write, fwd_read) = match fut.await {
let url = dest_proxy_url.clone();
let res = async move {
let (mut fwd_write, fwd_read) = fut.await?;
fwd_write
.send(ProxyWire::chan_new(url.into()))
.await
.map_err(TransportError::other)?;
TransportResult::Ok((fwd_write, fwd_read))
}
.await;
let (fwd_write, fwd_read) = match res {
Err(e) => {
let _ = i_s.prune_bad_proxy_to(dest_proxy_url).await;
write
.send(ProxyWire::failure(format!("{:?}", e)))
.await
Expand All @@ -387,10 +413,6 @@ impl InternalHandler for InnerListen {
}
Ok(t) => t,
};
fwd_write
.send(ProxyWire::chan_new(dest_proxy_url.clone().into()))
.await
.map_err(TransportError::other)?;
cross_join_channel_forward(fwd_write, read);
cross_join_channel_forward(write, fwd_read);
Ok(())
Expand All @@ -417,6 +439,11 @@ impl InternalHandler for InnerListen {
.into())
}

fn handle_prune_bad_proxy_to(&mut self, proxy_url: ProxyUrl) -> InternalHandlerResult<()> {
self.proxy_list.remove(&proxy_url);
Ok(async move { Ok(()) }.boxed().into())
}

#[tracing::instrument(skip(self))]
fn handle_register_proxy_to(
&mut self,
Expand Down

2 comments on commit 047531c

@thedavidmeister
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thedavidmeister
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.