Skip to content

Commit

Permalink
More P2P docs (#2492)
Browse files Browse the repository at this point in the history
* Remove relay

* restructure p2p

* wip

* cleanup webrtc

* split up P2P docs

* wip

* more wip

* the fork has moved

* finish local network discovery

* Document the relay system

* be less stupid

* a

* remote ip from deploy script

* remove debug from deploy script

* Explain relay setup and usage

* Physical pain

* fix

* error handling for relay setup

* Listeners Relay state + merge it into NLM state

* `node_remote_identity`

* redo libraries hook

* toggle relay active in settings

* Dedicated network settings page

* Stablise P2P debug page

* warning for rspc remote

* Linear links in docs

* fix p2p settings switches

* fix typescript errors on general page

* fix ipv6 listener status

* discovery method in UI

* Remove p2p debug menu on the sidebar

* wip

* lol

* wat

* fix

* another attempt at fixing library hook

* fix

* Remove sync from sidebar

* fix load library code

* I hate this

* Detect connections over the relay

* fix

* fixes

* a

* fix mDNS

* a bunch o fixes

* a bunch of state management fixes

* Metadata sync on connection

* skill issue

* fix markdown

* Clippy cleanup

* Backport #2380

* Update interface/locales/en/common.json

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/local-network-discovery.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/local-network-discovery.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/relay.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/relay.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/relay.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/relay.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/relay.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/sd_p2p.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/sd_p2p.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/sd_p2p_proto.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/overview.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/overview.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/relay.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/sd_p2p_proto.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/sd_p2p_proto.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/transport-layer.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/sd_p2p_proto.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/local-network-discovery.mdx

Co-authored-by: Matthew Yung <[email protected]>

* Update docs/developers/p2p/sd_p2p_proto.mdx

Co-authored-by: Matthew Yung <[email protected]>

* a

* Cleaning binario section

* cleanup Docker message

* idk

* Idempotent listeners

* Manual peers working????

* minor fixes

* crazy idea - don't panic in the event loop

* fixes

* debug

* debug

* LAN badge in network settings

* Use `dns_lookup` instead of `tokio::net::lookup_host`

* fix

* bruh sandwich

* proper dialing

* a

* remove logs

* fix

* Small cleanup

* manual peers state on connected device

* a

* Fix manual discovery state + give it a badge

* Clippy improvements

* flip discovery priority

* Add `addrs` to debug query

* connection candidates in debug

* Fix state

* Clippppppppppppy

* Manual discovery badge

* Flesh out ping example

* Usage guide

* `sd_p2p_proto` examples

* More discovery docs

* More docs work

* docs docs docs and more docs

* PONG

* rename

---------

Co-authored-by: Matthew Yung <[email protected]>
  • Loading branch information
oscartbeaumont and myung03 authored May 30, 2024
1 parent 3428644 commit b015763
Show file tree
Hide file tree
Showing 57 changed files with 3,090 additions and 1,590 deletions.
27 changes: 21 additions & 6 deletions Cargo.lock

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

42 changes: 21 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[workspace]
resolver = "2"
members = [
"core",
"core/crates/*",
"crates/*",
"apps/cli",
"apps/p2p-relay",
"apps/desktop/src-tauri",
"apps/desktop/crates/*",
"apps/mobile/modules/sd-core/core",
"apps/mobile/modules/sd-core/android/crate",
"apps/mobile/modules/sd-core/ios/crate",
"apps/server",
"core",
"core/crates/*",
"crates/*",
"apps/cli",
"apps/p2p-relay",
"apps/desktop/src-tauri",
"apps/desktop/crates/*",
"apps/mobile/modules/sd-core/core",
"apps/mobile/modules/sd-core/android/crate",
"apps/mobile/modules/sd-core/ios/crate",
"apps/server",
]

[workspace.package]
Expand All @@ -21,19 +21,19 @@ repository = "https://github.com/spacedriveapp/spacedrive"

[workspace.dependencies]
prisma-client-rust = { git = "https://github.com/brendonovich/prisma-client-rust", rev = "4f9ef9d38ca732162accff72b2eb684d2f120bab", features = [
"migrations",
"specta",
"sqlite",
"sqlite-create-many",
"migrations",
"specta",
"sqlite",
"sqlite-create-many",
], default-features = false }
prisma-client-rust-cli = { git = "https://github.com/brendonovich/prisma-client-rust", rev = "4f9ef9d38ca732162accff72b2eb684d2f120bab", features = [
"migrations",
"specta",
"sqlite",
"sqlite-create-many",
"migrations",
"specta",
"sqlite",
"sqlite-create-many",
], default-features = false }
prisma-client-rust-sdk = { git = "https://github.com/brendonovich/prisma-client-rust", rev = "4f9ef9d38ca732162accff72b2eb684d2f120bab", features = [
"sqlite",
"sqlite",
], default-features = false }

rspc = { version = "0.1.4" }
Expand Down Expand Up @@ -89,7 +89,7 @@ webp = "0.3.0"

[patch.crates-io]
# Proper IOS Support
if-watch = { git = "https://github.com/oscartbeaumont/if-watch.git", rev = "a92c17d3f85c1c6fb0afeeaf6c2b24d0b147e8c3" }
if-watch = { git = "https://github.com/spacedriveapp/if-watch.git", rev = "a92c17d3f85c1c6fb0afeeaf6c2b24d0b147e8c3" }

# We hack it to the high heavens
rspc = { git = "https://github.com/spacedriveapp/rspc.git", rev = "ab12964b140991e0730c3423693533fba71efb03" }
Expand Down
9 changes: 6 additions & 3 deletions apps/p2p-relay/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

set -e

SERVER="54.176.132.155"
SERVER=""
TARGET_DIR=$(cargo metadata | jq -r .target_directory)
cargo zigbuild --target aarch64-unknown-linux-musl --release

echo "$TARGET_DIR/aarch64-unknown-linux-musl/release/sd-p2p-relay"

scp "$TARGET_DIR/aarch64-unknown-linux-musl/release/sd-p2p-relay" ec2-user@$SERVER:/home/ec2-user/sd-p2p-relay

# ssh ec2-user@$SERVER
# ./sd-p2p-relay init
# Enter the `P2P_SECRET` secret env var from Vercel
# ./sd-p2p-relay
6 changes: 6 additions & 0 deletions apps/server/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,15 @@ ADD --chmod=755 --checksum=sha256:1d127c69218f2cd14964036f2b057c4b2652cda3996c69

COPY --chmod=755 entrypoint.sh /usr/bin/

# P2P config
ENV SD_DOCKER=true

# Expose webserver
EXPOSE 8080

# Expose P2P
EXPOSE 7373

# Create the data directory to store the database
VOLUME [ "/data" ]

Expand Down
7 changes: 5 additions & 2 deletions core/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ model Instance {
// Enum: sd_core::node::RemoteIdentity
remote_identity Bytes
node_id Bytes
metadata Bytes? // TODO: This should not be optional
// Enum: uuid::Uuid
node_id Bytes
// Enum: sd_core::node::RemoteIdentity
node_remote_identity Bytes? // TODO: This should not be optional
metadata Bytes? // TODO: This should not be optional
last_seen DateTime // Time core started for owner, last P2P message for P2P node
date_created DateTime
Expand Down
10 changes: 9 additions & 1 deletion core/src/api/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
}

mod library {
use std::str::FromStr;

use sd_p2p::RemoteIdentity;

use crate::util::MaybeUndefined;

use super::*;
Expand Down Expand Up @@ -75,6 +79,7 @@ mod library {
library.instance_uuid,
library.identity.to_remote_identity(),
node_config.id,
node_config.identity.to_remote_identity(),
&node.p2p.peer_metadata(),
)
.await?;
Expand Down Expand Up @@ -139,6 +144,7 @@ mod library {
library.instance_uuid,
library.identity.to_remote_identity(),
node_config.id,
node_config.identity.to_remote_identity(),
node.p2p.peer_metadata(),
)
.await?;
Expand All @@ -152,7 +158,9 @@ mod library {
instance.uuid,
instance.identity,
instance.node_id,
node.p2p.peer_metadata(),
RemoteIdentity::from_str(&instance.node_remote_identity)
.expect("malformed remote identity in the DB"),
instance.metadata,
)
.await?;
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
invalidate_query,
node::{
config::{NodeConfig, NodeConfigP2P, NodePreferences},
config::{is_in_docker, NodeConfig, NodeConfigP2P, NodePreferences},
get_hardware_model_name, HardwareModel,
},
old_job::JobProgressEvent,
Expand Down Expand Up @@ -116,6 +116,7 @@ struct NodeState {
config: SanitisedNodeConfig,
data_path: String,
device_model: Option<String>,
is_in_docker: bool,
}

pub(crate) fn mount() -> Arc<Router> {
Expand Down Expand Up @@ -151,6 +152,7 @@ pub(crate) fn mount() -> Arc<Router> {
.expect("Found non-UTF-8 path")
.to_string(),
device_model: Some(device_model),
is_in_docker: is_in_docker(),
})
})
})
Expand Down
24 changes: 17 additions & 7 deletions core/src/api/nodes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use crate::{
invalidate_query,
node::config::{P2PDiscoveryState, Port},
Expand All @@ -20,10 +22,12 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
pub struct ChangeNodeNameArgs {
pub name: Option<String>,
pub p2p_port: Option<Port>,
pub p2p_ipv4_enabled: Option<bool>,
pub p2p_ipv6_enabled: Option<bool>,
pub p2p_disabled: Option<bool>,
pub p2p_ipv6_disabled: Option<bool>,
pub p2p_relay_disabled: Option<bool>,
pub p2p_discovery: Option<P2PDiscoveryState>,
pub p2p_remote_access: Option<bool>,
pub p2p_manual_peers: Option<HashSet<String>>,
pub image_labeler_version: Option<String>,
}
R.mutation(|node, args: ChangeNodeNameArgs| async move {
Expand All @@ -48,17 +52,23 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
if let Some(port) = args.p2p_port {
config.p2p.port = port;
};
if let Some(enabled) = args.p2p_ipv4_enabled {
config.p2p.ipv4 = enabled;
if let Some(enabled) = args.p2p_disabled {
config.p2p.disabled = enabled;
};
if let Some(enabled) = args.p2p_ipv6_disabled {
config.p2p.disable_ipv6 = enabled;
};
if let Some(enabled) = args.p2p_ipv6_enabled {
config.p2p.ipv6 = enabled;
if let Some(enabled) = args.p2p_relay_disabled {
config.p2p.disable_relay = enabled;
};
if let Some(discovery) = args.p2p_discovery {
config.p2p.discovery = discovery;
};
if let Some(remote_access) = args.p2p_remote_access {
config.p2p.remote_access = remote_access;
config.p2p.enable_remote_access = remote_access;
};
if let Some(manual_peers) = args.p2p_manual_peers {
config.p2p.manual_peers = manual_peers;
};

#[cfg(feature = "ai")]
Expand Down
Loading

0 comments on commit b015763

Please sign in to comment.