Skip to content

Commit

Permalink
fix: add handling of dns multiaddrs
Browse files Browse the repository at this point in the history
refactor: transport handling for ws & quic as fallback

Includes:

- dns fallback update
- CLI: removal of -w for running workflows; it's now a positional argument (the first one on run)
  * related to #489
- CLI: node command which showcases nodeinfo, e.g. peer_id and listener addrs/connections
  * related to #489
- Closes #492 with local node bootstrapping
- Closes #297
- Closes #497
  • Loading branch information
zeeshanlakhani committed Feb 5, 2024
1 parent d420416 commit c87404e
Show file tree
Hide file tree
Showing 24 changed files with 677 additions and 108 deletions.
52 changes: 49 additions & 3 deletions .github/workflows/tests_and_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run-checks:
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' || needs.changes.outputs.examples == 'true' }}
if: ${{ needs.changes.outputs.rust == 'true' }}
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' }}
env:
RUSTFLAGS: -Dwarnings -Ctarget-feature=+crt-static
RUSTFLAGS: -Dwarnings -Ctarget-feature=+crt-static
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -262,6 +262,9 @@ jobs:
run-cargo-tests:
needs: changes
if: ${{ needs.changes.outputs.rust == 'true' }}
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
runs-on: ubuntu-latest
steps:
- name: Setup IPFS
Expand All @@ -283,11 +286,14 @@ jobs:
shared-key: test-all-stable-ubuntu-latest
save-if: ${{ github.event_name == 'push' }}

- name: Sccache
uses: mozilla-actions/[email protected]

- name: Run Tests (all-features)
run: cargo test --workspace --all-features

run-docs:
needs: changes
needs: [changes]
if: ${{ needs.changes.outputs.rust == 'true' }}
env:
SCCACHE_GHA_ENABLED: "true"
Expand All @@ -306,6 +312,7 @@ jobs:
- name: Cache Project
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
shared-key: doc
save-if: ${{ github.event_name == 'push' }}

Expand All @@ -316,3 +323,42 @@ jobs:
env:
RUSTDOCFLAGS: -Dwarnings
run: cargo doc --workspace --document-private-items

build-and-run-examples:
needs: changes
if: ${{ needs.changes.outputs.examples == 'true' }}
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
runs-on: ubuntu-latest
steps:
- name: Setup IPFS
uses: ibnesayeed/setup-ipfs@master
with:
run_daemon: false

- name: Checkout Repository
uses: actions/checkout@v4

- name: Use mold-linker
uses: rui314/setup-mold@v1

- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Cache Project
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
shared-key: cargo-examples
save-if: ${{ github.event_name == 'push' }}

- name: Sccache
uses: mozilla-actions/[email protected]

- name: Build example-websocket-relay
run: cargo build -p websocket-relay

- name: Run example-websocket-relay
shell: bash
run: timeout 10s cargo run -p websocket-relay || true
32 changes: 31 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 33 additions & 26 deletions examples/websocket-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To get started, please install:

## Usage

1. Run `cargo run -- start` to start the runtime and an IPFS daemon as a
1. Run `cargo run` to start the runtime and an IPFS daemon as a
background process. This runtime includes ANSI-coded logging by default.

2. In a separate terminal window, run `npm install --prefix relay-app` to
Expand All @@ -61,38 +61,45 @@ if they've been previously run.

## Tips & Common Issues

On macOS, for example, a simple homebrew install would install everything you
need: `brew install rust npm ipfs`
- On macOS, for example, a simple homebrew install would install everything you
need: `brew install rust npm ipfs`.

We have packaged homestar binaries using brew, so
`brew install fission-codes/fission/homestar` will install everything you need,
including `ipfs`. You will still need `npm` to run this example. From this folder,
you can then run the example like this:
- Running `homestar` via `cargo run` here requires a minimum Rust version of
`1.73.0`. If you've got an older install of rust, update it with
`rustup update`.

```
homestar start --db homestar.db
```
- You do not have to start Kubo (IPFS) on your own. The example will do this
for you, and use `examples/websocket-relay/tmp/.ipfs` as a local blockstore.
Feel free to discard it when you don't need it.

Running `homestar` via `cargo run` requires a minimum Rust version of
`1.73.0`. If you've got an older install of rust, update it with
`rustup update`.
- If you're already running an IPFS instance, for example [IPFS Desktop][ipfs-desktop],
the application will check for it and not start a new, local one.
However, the application expects a default IPFS host and port. The expected
IPFS `host` and `port` can be updated in the `homestar` network settings:

You do not have to start Kubo (IPFS) on your own. The example will do this
for you, and use `examples/websocket-relay/tmp/.ipfs` as a local blockstore.
Feel free to discard it when you don't need it.
``` toml
[node]

If you're already running an IPFS instance, for example [IPFS Desktop][ipfs-desktop],
the application will check for it and not start a new, local one.
However, the application expects a default IPFS host and port. The expected
IPFS `host` and `port` can be updated in the `homestar` network settings:
[node.network.ipfs]
host = "127.0.0.1"
port = 5001
```

``` toml
[node]
- We have officially packaged homestar binaries using brew, so
`brew install fission-codes/fission/homestar` will install mostly everything
you need, including `ipfs`. You will still need `npm` to run this example, and
you'll have to manually `ipfs add` the `synthcat.ping` and `example_test.wasm`
files located in this directory. Then, from this folder, you can then run the
example like this:

```
homestar start --db homestar.db
```

Afterward, as mentioned above, you can then run `npm install --prefix relay-app` to
install dependencies and `npm run --prefix relay-app dev` to start the
relay web application (UI) on `http://localhost:5173/` by default.

[node.network.ipfs]
host = "127.0.0.1"
port = 5001
```

[@fission-codes/homestar]: https://www.npmjs.com/package/@fission-codes/homestar
[install-ipfs]: https://docs.ipfs.tech/install/
Expand Down
21 changes: 19 additions & 2 deletions examples/websocket-relay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use homestar_runtime::{db::Database, Db, Logger, Runner, Settings};
use miette::Result;
use retry::{delay::Fixed, retry};
use std::{
fs,
net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpStream},
path::PathBuf,
process::{Child, Command, Stdio},
};
use sysinfo::{System, SystemExt};
Expand Down Expand Up @@ -37,6 +39,7 @@ fn main() -> Result<()> {
}
}

#[cfg(not(feature = "ci"))]
Ok(())
}

Expand All @@ -47,6 +50,7 @@ fn ipfs_setup() -> Option<Child> {
println!("`ipfs` was found!");
None
} else {
let _ = fs::create_dir("./tmp");
let mut ipfs_daemon = Command::new("ipfs")
.args(["--repo-dir", "./tmp/.ipfs", "--offline", "daemon", "--init"])
.stderr(Stdio::piped())
Expand Down Expand Up @@ -77,7 +81,16 @@ fn ipfs_setup() -> Option<Child> {
let mut add_image_args = args.clone();
let mut add_wasm_args = args.clone();

add_image_args.append(&mut vec!["add", "--cid-version", "1", "./synthcat.png"]);
let mut image_file = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
image_file.push("synthcat.png");
let image_file = fs::canonicalize(image_file).expect("synthcat.png to be found");

add_image_args.append(&mut vec![
"add",
"--cid-version",
"1",
image_file.to_str().unwrap(),
]);

let ipfs_add_img = Command::new("ipfs")
.args(add_image_args)
Expand All @@ -87,11 +100,15 @@ fn ipfs_setup() -> Option<Child> {

println!("synthcat.png added to local IPFS instance");

let mut wasm_file = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
wasm_file.push("example_test.wasm");
let wasm_file = fs::canonicalize(wasm_file).expect("example_test.wasm to be found");

add_wasm_args.append(&mut vec![
"add",
"--cid-version",
"1",
"./example_test.wasm",
wasm_file.to_str().unwrap(),
]);

let ipfs_add_wasm = Command::new("ipfs")
Expand Down
5 changes: 5 additions & 0 deletions homestar-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ faststr = { workspace = true }
flume = { version = "0.11", default-features = false, features = ["async"] }
fnv = { version = "1.0", default-features = false }
futures = { workspace = true }
hickory-resolver = { version = "0.24", default-features = false }
homestar-invocation = { version = "0.1", path = "../homestar-invocation", features = [
"diesel",
] }
Expand All @@ -88,6 +89,7 @@ jsonrpsee = { version = "0.21", default-features = false, features = [
] }
libipld = { workspace = true }
libp2p = { version = "0.53", default-features = false, features = [
"dns",
"kad",
"request-response",
"rendezvous",
Expand All @@ -97,12 +99,15 @@ libp2p = { version = "0.53", default-features = false, features = [
"mdns",
"gossipsub",
"request-response",
"rsa",
"tokio",
"tcp",
"noise",
"cbor",
"yamux",
"serde",
"quic",
"websocket",
] }
libsqlite3-sys = { workspace = true }
maplit = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions homestar-runtime/config/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ transport_connection_timeout = 60
max_connected_peers = 32
max_announce_addresses = 10
dial_interval = 30
bootstrap_interval = 30

[node.network.libp2p.quic]
enable = true

[node.network.libp2p.mdns]
enable = true
Expand Down
Loading

0 comments on commit c87404e

Please sign in to comment.