Skip to content

Commit

Permalink
feat: derp mesh network & derper cli & config cleanup (#1130)
Browse files Browse the repository at this point in the history
* set up `MeshClients` & use it in `derp::http::Server` to mesh with other derp servers

* Clean up Derper CLI

To run the derper in dev mode, use the `--dev` flag.

All other configuration must be set using a config file.

Generate a default config file by running the derper with the
`--config-path` flag and supplying a path.

Note: you can use a config file along with the `--dev` flag, but it will
ignore any TLS specific configuration & only run the derper using HTTP.

* fix conn tests test: ensure we dial via tls
  • Loading branch information
ramfox committed Jun 30, 2023
1 parent da2d4d0 commit 3dca612
Show file tree
Hide file tree
Showing 9 changed files with 860 additions and 187 deletions.
333 changes: 205 additions & 128 deletions iroh-net/src/bin/derper.rs

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion iroh-net/src/hp/derp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub struct InnerClient {
writer_task: Mutex<Option<JoinHandle<Result<()>>>>,
/// The reader connected to the server
reader: Mutex<tokio::io::ReadHalf<Box<dyn Io + Send + Sync + 'static>>>,
/// Public key of the server we are connected to
server_public_key: PublicKey,
}

// TODO: I believe that any of these that error should actually trigger a shut down of the client
Expand Down Expand Up @@ -285,6 +287,10 @@ impl Client {
}
}
}

pub fn server_public_key(self) -> PublicKey {
self.inner.server_public_key.clone()
}
}

/// The kinds of messages we can send to the Server
Expand Down Expand Up @@ -482,7 +488,7 @@ where

pub async fn build(mut self, buf: Option<Bytes>) -> Result<Client> {
// exchange information with the server
let (_, rate_limiter) = self.server_handshake(buf).await?;
let (server_public_key, rate_limiter) = self.server_handshake(buf).await?;

// create task to handle writing to the server
let (writer_sender, writer_recv) = mpsc::channel(PER_CLIENT_SEND_QUEUE_DEPTH);
Expand All @@ -502,6 +508,7 @@ where
writer_channel: writer_sender,
writer_task: Mutex::new(Some(writer_task)),
reader: Mutex::new(self.reader),
server_public_key,
}),
};

Expand Down
13 changes: 9 additions & 4 deletions iroh-net/src/hp/derp/http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod client;
mod mesh_clients;
mod server;

pub use self::client::{Client, ClientBuilder, ClientError};
pub use self::mesh_clients::MeshAddrs;
pub use self::server::{Server, ServerBuilder, TlsAcceptor, TlsConfig};

pub(crate) const HTTP_UPGRADE_PROTOCOL: &str = "iroh derp http";
Expand Down Expand Up @@ -139,10 +141,13 @@ mod tests {
if let Some(url) = server_url {
client = client.server_url(url);
}
let client = client.new_region(key.clone(), move || {
let region = region.clone();
Box::pin(async move { Some(region) })
});
let client = client
.get_region(move || {
let region = region.clone();
Box::pin(async move { Some(region) })
})
.build(key.clone())
.expect("won't fail if you supply a `get_region`");
let public_key = key.public_key();
let (received_msg_s, received_msg_r) = tokio::sync::mpsc::channel(10);
let client_reader = client.clone();
Expand Down
Loading

0 comments on commit 3dca612

Please sign in to comment.