Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linkd #779

Merged
merged 6 commits into from
Sep 14, 2021
Merged

linkd #779

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ members = [
"link-git-protocol",
"link-identities",
"macros",
"node-lib",
"rad-clib",
"rad-exe",
"rad-profile",
"seed",
"std-ext",
"test",
]
exclude = [
"bins"
]

[patch.crates-io.git2]
git = "https://github.com/radicle-dev/git2-rs.git"
Expand Down
8 changes: 8 additions & 0 deletions bins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
members = [
"linkd"
]

[patch.crates-io.thrussh-encoding]
git = "https://github.com/FintanH/thrussh.git"
branch = "generic-agent"
1 change: 1 addition & 0 deletions bins/linkd.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��:�5-B|��d��kGk���H2�(�ܞ��I
15 changes: 15 additions & 0 deletions bins/linkd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "linkd"
version = "0.1.0"
edition = "2018"
license = "GPL-3.0-or-later"
authors = [
"xla <[email protected]>",
]

[dependencies]
tokio = { version = "1.10", default-features = false, features = [ "macros", "process", "rt-multi-thread" ] }

[dependencies.node-lib]
path = "../../node-lib"
version = "0.1.0"
13 changes: 13 additions & 0 deletions bins/linkd/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright © 2021 The Radicle Link Contributors
//
// This file is part of radicle-link, distributed under the GPLv3 with Radicle
// Linking Exception. For full terms see the included LICENSE file.

use node_lib::node::run;

#[tokio::main]
async fn main() {
if let Err(e) = run().await {
eprintln!("linkd failed: {:?}", e);
}
}
4 changes: 2 additions & 2 deletions e2e/Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bootstrap: cargo run --bin ephemeral-peer -- --secret-key hIfobTmxKMemyXPOC8EmUNdufwi2MsKucEB9EikOyDE --listen 127.0.0.1:54321
peer: sleep 5; cargo run --bin ephemeral-peer -- --bootstrap [email protected]:54321
bootstrap: cd ../bins && echo -n "hIfobTmxKMemyXPOC8EmUNdufwi2MsKucEB9EikOyDE" | cargo run -p linkd -- --signer key --key-format base64 --protocol-listen 127.0.0.1:54321 --tmp-root
peer: sleep 5; cd ../bins && cargo run -p linkd -- --signer key --key-source ephemeral --tmp-root --protocol-listen localhost --bootstrap [email protected]:54321
29 changes: 18 additions & 11 deletions e2e/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ services:
- 'graphite-exporter'
build:
context: ../
dockerfile: e2e/ephemeral-peer.dockerfile
image: ephemeral-peer
dockerfile: e2e/linkd.dockerfile
image: linkd
init: true
ports:
- '12345:12345/udp'
command: |
ephemeral-peer
--secret-key hIfobTmxKMemyXPOC8EmUNdufwi2MsKucEB9EikOyDE
--listen 0.0.0.0:12345
--graphite graphite:9109
command: bash -c 'echo -n "hIfobTmxKMemyXPOC8EmUNdufwi2MsKucEB9EikOyDE" |
linkd
--signer key
--key-format base64
--protocol-listen 0.0.0.0:12345
--tmp-root
--metrics-provider graphite
--graphite-addr graphite:9109'
environment:
- 'RUST_LOG=${RUST_LOG:-debug}'
- 'TRACING_FMT=${TRACING_FMT:-compact}'
Expand All @@ -52,15 +55,19 @@ services:
passive-peer:
depends_on:
- 'bootstrap-peer'
image: ephemeral-peer
image: linkd
init: true
ports:
- '12346/udp'
command: |
ephemeral-peer
--listen 0.0.0.0:12346
linkd
--signer key
--key-source ephemeral
--protocol-listen 0.0.0.0:12346
--tmp-root
--bootstrap hyne66jefcpkobg91qzdy6ysetr8fn3p3d6myce61uwf7s67g3i79e@bootstrap:12345
--graphite graphite:9109
--metrics-provider graphite
--graphite-addr graphite:9109
environment:
- 'RUST_LOG=${RUST_LOG:-debug}'
- 'TRACING_FMT=${TRACING_FMT:-compact}'
Expand Down
11 changes: 6 additions & 5 deletions e2e/ephemeral-peer.dockerfile → e2e/linkd.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ RUN --mount=type=bind,source=.,target=/build,rw \
--mount=type=cache,target=/cache \
set -eux pipefail; \
mkdir -p /cache/target; \
ln -s /cache/target target ; \
cargo build --release --package radicle-link-e2e --bin ephemeral-peer; \
mv target/release/ephemeral-peer /ephemeral-peer
ln -s /cache/target target; \
cd bins; \
cargo build --release --package linkd; \
mv target/release/linkd /linkd

FROM debian:buster-slim
RUN set -eux; \
Expand All @@ -21,5 +22,5 @@ RUN set -eux; \
; \
apt-get autoremove; \
rm -rf /var/lib/apt/lists/*
COPY --from=build /ephemeral-peer /usr/local/bin/ephemeral-peer
CMD ["ephemeral-peer"]
COPY --from=build /linkd /usr/local/bin/linkd
CMD ["linkd"]
10 changes: 8 additions & 2 deletions librad/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is part of radicle-link, distributed under the GPLv3 with Radicle
// Linking Exception. For full terms see the included LICENSE file.

use std::{borrow::Cow, str::FromStr};
use std::{borrow::Cow, fmt::Display, str::FromStr};

pub mod codec;
pub mod connection;
Expand Down Expand Up @@ -43,7 +43,7 @@ pub const PROTOCOL_VERSION: u8 = 2;
/// should be kept short.
///
/// [ALPN]: https://tools.ietf.org/html/rfc7301
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Network {
Main,
Custom(Cow<'static, [u8]>),
Expand All @@ -55,6 +55,12 @@ impl Default for Network {
}
}

impl Display for Network {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

impl FromStr for Network {
type Err = &'static str;

Expand Down
20 changes: 12 additions & 8 deletions librad/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use std::{
env,
fmt,
io,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -37,6 +38,7 @@ pub struct Profile {
}

/// An enumeration of where the root directory for a `Profile` lives.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum RadHome {
/// The system specific directories given by [`directories::ProjectDirs`].
ProjectDirs,
Expand All @@ -45,23 +47,25 @@ pub enum RadHome {
}

impl Default for RadHome {
fn default() -> Self {
Self::new()
}
}

impl RadHome {
/// If `RAD_HOME` is defined then the path supplied there is used and
/// [`RadHome::Root`] is constructed. Otherwise, [`RadHome::ProjectDirs`] is
/// constructed.
pub fn new() -> Self {
fn default() -> Self {
if let Ok(root) = env::var(RAD_HOME) {
Self::Root(Path::new(&root).to_path_buf())
} else {
Self::ProjectDirs
}
}
}

impl fmt::Display for RadHome {
FintanH marked this conversation as resolved.
Show resolved Hide resolved
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl RadHome {
fn config(&self) -> Result<PathBuf, io::Error> {
Ok(match self {
Self::ProjectDirs => project_dirs()?.config_dir().to_path_buf(),
Expand Down Expand Up @@ -151,7 +155,7 @@ impl Profile {
/// `ProjectDirs_DATA_HOME/radicle-link/<profile-id>`.
pub fn load() -> Result<Self, Error> {
let env_profile_id = ProfileId::from_env()?;
let home = RadHome::new();
let home = RadHome::default();
Self::from_home(&home, env_profile_id)
}

Expand Down
40 changes: 40 additions & 0 deletions node-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "node-lib"
version = "0.1.0"
edition = "2018"
license = "GPL-3.0-or-later"
authors = [
"xla <[email protected]>",
]

[lib]
doctest = true
test = false

[dependencies]
anyhow = "1.0"
base64 = "0.13"
env_logger = "0.9"
futures = "0.3"
lazy_static = "1.4"
log = "0.4"
nix = "0.22"
structopt = { version = "0.3", default-features = false }
thiserror = "1.0"
tempfile = "3.2"
tokio = { version = "1.10", default-features = false, features = [ "fs", "io-std", "macros", "process", "rt-multi-thread", "signal" ] }
tracing = { version = "0.1", default-features = false, features = [ "attributes", "std" ] }
tracing-subscriber = "0.2"

[dependencies.rad-clib]
path = "../rad-clib"
version = "0.1.0"

[dependencies.librad]
path = "../librad"
version = "0.1.0"

[dependencies.thrussh-agent]
git = "https://github.com/FintanH/thrussh"
branch = "generic-agent"
features = [ "tokio-agent" ]
Loading