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

fix: add handling of dns multiaddrs + bootstrapping + CLI / Conn changes #547

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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`.
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved

```
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`
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved
files located in this directory. Then, from this folder, you can then run the
example like this:
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved

```
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.
zeeshanlakhani marked this conversation as resolved.
Show resolved Hide resolved

[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
Loading