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

feat(p2p): implement connect and lookup #372

Merged
merged 1 commit into from
Oct 21, 2022
Merged

feat(p2p): implement connect and lookup #372

merged 1 commit into from
Oct 21, 2022

Conversation

ramfox
Copy link
Contributor

@ramfox ramfox commented Oct 20, 2022

This PR cleans up a bunch of messy connect behaviour

Adds lookup behaviour

  • if we don't already have the peer's information, attempt to dial the peer & get the information that way.
  • you can attempt to lookup the node via only the PeerId, it follows the same pattern as connect first attempting to find the peer on the dht
  • you can use a multiaddr to dial/lookup the peer directly

This needs a follow-up PR to clean up:

  • iroh p2p lookup success output
  • iroh p2p lookup & iroh p2p connect error output

@ramfox ramfox added this to the v0.1.0 milestone Oct 20, 2022
@ramfox ramfox requested a review from dignifiedquire October 20, 2022 05:14
@ramfox ramfox self-assigned this Oct 20, 2022
@ramfox ramfox requested review from b5 and rklaehn October 20, 2022 05:15
Copy link
Contributor

@rklaehn rklaehn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, but if you have some time I would like to try it out as well..

iroh-rpc-types/proto/p2p.proto Show resolved Hide resolved
iroh-p2p/src/node.rs Outdated Show resolved Hide resolved
iroh-p2p/src/node.rs Show resolved Hide resolved
iroh-p2p/src/rpc.rs Show resolved Hide resolved
Copy link
Contributor

@faassen faassen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few comments focusing on the API and CLI.

iroh-api/src/p2p.rs Outdated Show resolved Hide resolved
iroh-api/src/p2p.rs Outdated Show resolved Hide resolved
iroh-api/src/p2p.rs Show resolved Hide resolved
iroh-rpc-client/src/network.rs Outdated Show resolved Hide resolved
iroh-rpc-client/src/network.rs Outdated Show resolved Hide resolved
iroh-rpc-client/src/network.rs Outdated Show resolved Hide resolved
iroh/tests/cmd/lookup.trycmd Show resolved Hide resolved
rklaehn
rklaehn previously approved these changes Oct 20, 2022
Copy link
Contributor

@rklaehn rklaehn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some basic tests with this. Works on my machine 👍

iroh on  ramfox/connect [$?] via 🦀 v1.63.0 
❯ cargo run -p iroh -- p2p connect /ip4/192.168.100.126/tcp/4001/p2p/12D3KooWBK6nRXqdZBZW6UKQgV4M1nhJAewjkS3iqZqPkza9R8UN
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/iroh p2p connect /ip4/192.168.100.126/tcp/4001/p2p/12D3KooWBK6nRXqdZBZW6UKQgV4M1nhJAewjkS3iqZqPkza9R8UN`
Connected!

iroh on  ramfox/connect [$?] via 🦀 v1.63.0 
❯ cargo run -p iroh -- p2p lookup                                                                                        
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
     Running `target/debug/iroh p2p lookup`
peer id: 12D3KooWCLb7tdXfUWSxNhqdFW2RunQTnXPyWaZN6uUguRenMfM2
listening addresses: ["/ip4/127.0.0.1/tcp/4444", "/ip4/192.168.100.17/tcp/4444", "/ip4/109.97.120.25/tcp/4444", "/ip6/64:ff9b::6d61:7819/tcp/4444", "/ip4/10.142.15.221/tcp/57264", "/ip4/109.97.120.25/tcp/57900/ws", "/ip4/100.121.168.64/tcp/4444"]
protocols: []
protocol version: 
observed addresses: ["/ip4/109.97.120.25/tcp/4444", "/ip6/64:ff9b::6d61:7819/tcp/4444", "/ip4/10.142.15.221/tcp/57264", "/ip4/109.97.120.25/tcp/57900/ws", "/ip4/100.121.168.64/tcp/4444"]


iroh on  ramfox/connect [$?] via 🦀 v1.63.0 
❯ cargo run -p iroh -- p2p lookup 12D3KooWBK6nRXqdZBZW6UKQgV4M1nhJAewjkS3iqZqPkza9R8UN                                   
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/iroh p2p lookup 12D3KooWBK6nRXqdZBZW6UKQgV4M1nhJAewjkS3iqZqPkza9R8UN`
peer id: 12D3KooWBK6nRXqdZBZW6UKQgV4M1nhJAewjkS3iqZqPkza9R8UN
listening addresses: ["/ip4/192.168.100.126/udp/4001/quic", "/ip4/192.168.100.126/tcp/4001", "/ip4/109.97.120.25/tcp/4001", "/ip4/109.97.120.25/udp/20325/quic", "/ip4/109.97.120.25/tcp/20323"]
protocols: ["/p2p/id/delta/1.0.0", "/ipfs/id/1.0.0", "/ipfs/id/push/1.0.0", "/ipfs/ping/1.0.0", "/libp2p/circuit/relay/0.1.0", "/libp2p/circuit/relay/0.2.0/stop", "/ipfs/lan/kad/1.0.0", "/libp2p/autonat/1.0.0", "/ipfs/bitswap/1.2.0", "/ipfs/bitswap/1.1.0", "/ipfs/bitswap/1.0.0", "/ipfs/bitswap", "/x/", "/libp2p/circuit/relay/0.2.0/hop", "/ipfs/kad/1.0.0", "/libp2p/dcutr"]
protocol version: ipfs/0.1.0
observed addresses: ["/ip4/192.168.100.17/tcp/4444"]

It is a bit hard to figure out if it worked without ipfs p2p peers or something like htat, but I guess that would be the next thing...

@ramfox
Copy link
Contributor Author

ramfox commented Oct 20, 2022

It is a bit hard to figure out if it worked without ipfs p2p peers or something like htat, but I guess that would be the next thing...

Great point. I'll make an issue that can go into 0.1.1

@ramfox ramfox requested a review from rklaehn October 20, 2022 16:34
@ramfox ramfox force-pushed the ramfox/connect branch 5 times, most recently from a560260 to d286ab7 Compare October 21, 2022 02:40
Copy link
Member

@b5 b5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smoke tested. Am excited. let's merge!

b5
b5 previously approved these changes Oct 21, 2022
iroh-p2p/src/rpc.rs Outdated Show resolved Hide resolved
iroh/src/p2p.rs Outdated
}
P2pCommands::Connect { addr } => match p2p.connect(&addr.0).await {
Ok(_) => {
println!("Connected!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe print to what we connected? seems like it would be a bit clearer

iroh/src/p2p.rs Outdated Show resolved Hide resolved
@ramfox ramfox force-pushed the ramfox/connect branch 2 times, most recently from 8bebc5c to f68ceda Compare October 21, 2022 18:39
b5
b5 previously approved these changes Oct 21, 2022
@b5 b5 merged commit a93dfb4 into main Oct 21, 2022
@Arqu Arqu deleted the ramfox/connect branch December 1, 2022 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
5 participants