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

js-peer: add ability to connect via peerID #210

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Nkovaturient
Copy link

@Nkovaturient Nkovaturient commented Feb 3, 2025

Issue: #177

  • PR created as part and discussion, here -> Issue

Aims:

  • Example where two peers find each other with the peer-id only (in the best case with a dht for detecting the multiadders)
  • Function to fetch peerinfo, connect thru known peers in peerStore
  • DHT lookup attempts
  • Compnent to render the list of peerIds connected with the entered peerID

Description:
1)findByPeerId function aims to find through PeerStore or DHT Lookup
2)DHT response and peerResponse as fallback

Fix needed:

  • peerInfo response is retrieving a list of mutiaddrs alongwith bootstrap addrs, however on clicking connect thru either of them, an error of NoValidAddressesError: The dial request has no valid addresses or "DHT lookup failed"

  • OUTPUT from PEERINFO obj(mainly thru Known Peer, not DHT)

addresses
: 
(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
id
: 
Ed25519PeerId {type: 'Ed25519', multihash: Digest, publicKey: Ed25519PublicKey, string: undefined, Symbol(@libp2p/peer-id): true}
metadata
: 
Map(3) {'AgentVersion' => Uint8Array(64), 'last-dial-success' => Uint8Array(13), 'ProtocolVersion' => Uint8Array(0)}
peerRecordEnvelope
: 
Uint8Array(737) [10, 36, 8, 1, 18, 32, 87, 101, 178, 119, 212, 235, 230, 116, 127, 160, 63, 160, 129, 209, 158, 114, 12, 73, 56, 97, 94, 174, 237, 156, 100, 176, 89, 177, 213, 203, 191, 239, 18, 2, 3, 1, 26, 242, 4, 10, 38, 0, 36, 8, 1, 18, 32, 87, 101, 178, 119, 212, 235, 230, 116, 127, 160, 63, 160, 129, 209, 158, 114, 12, 73, 56, 97, 94, 174, 237, 156, 100, 176, 89, 177, 213, 203, 191, 239, 16, 199, 222, 166, 171, 183, 153, 254, 142, 24, 26, 50, 10, 48, 4, …]
protocols
: 
(10) ['/floodsub/1.0.0', '/ipfs/id/1.0.0', '/ipfs/id/push/1.0.0', '/ipfs/kad/1.0.0', '/ipfs/ping/1.0.0', '/libp2p/circuit/relay/0.2.0/hop', '/libp2p/circuit/relay/0.2.0/stop', '/meshsub/1.0.0', '/meshsub/1.1.0', '/meshsub/1.2.0']
tags
: 
Map(7) {'kad-close' => {…}, 'kad-peer' => {…}, 'keep-alive-circuit-relay' => {…}, 'keep-alive-kad-dht' => {…}, 'universal-connectivity' => {…}, …}

Screenshot (476)

Screenshot (476)

  • why DHT lookup is failing?
  • How to fetch peerInfo by entering peerId of known connections with valid addrs

Copy link
Collaborator

@2color 2color left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, Neha.

Before a proper review:

  • Can you please run prettier on the files you edited in this PR to format changes (I've opened js-peer: add prettier for consistent styling #211 to address this). A lot of changes in this PR are code style changes adding unnecessary noise that makes reviewing harder.
  • Can you please remove any commented out code that isn't relevant for this.

@2color 2color changed the title Feat: Connect via peerID js-peer: add ability to connect via peerID Feb 4, 2025
@Nkovaturient
Copy link
Author

Thanks for the PR, Neha.

Before a proper review:

  • Can you please run prettier on the files you edited in this PR to format changes (I've opened js-peer: add prettier for consistent styling #211 to address this). A lot of changes in this PR are code style changes adding unnecessary noise that makes reviewing harder.
  • Can you please remove any commented out code that isn't relevant for this.

Roger that! @2color

@Nkovaturient
Copy link
Author

Hey, @2color
wanna update you with recent commits:-

  • ran prettier on files and code changes
  • modified kadDHT to peerRouting methods-indeed an effective way of finding peers
  • updated the peerFind handler in index.tsx
    Screenshot (486)

@Nkovaturient
Copy link
Author

Hey, kindly review and provide guidance--
summary of the key changes made for peer connectivity:

Basically findBypeerID is fetching a list of multiaddrs --> in peer-maddr.tsx -we are filtering it with valid transport stack --> then trying to connect with either of them handleConnect

Connection Handling:

  • Fixed connection object creation to use actual libp2p connection
  • Updated connection type interface to match simplified structure
  • Added proper connection state management

Transport Protocol Validation:

  • Added checks for WebTransport + certhash
  • Added checks for WebRTC + QUIC + certhash
  • Added external address validation

Connection Flow:

  • Parse multiaddr to extract peerID
  • Validate transport stack
  • Attempt connection via connectToMultiaddr
  • Store successful connection in state
  • Clear resolved multiaddrs after connection
  • Handle connection errors with user feedback

UI Improvements:

  • Added connection priority system
  • Show transport protocol badges
  • Display connection status indicators
  • Added loading states during connection

Screenshot (487)
Screenshot (488)

Screenshot (489)

@Nkovaturient
Copy link
Author

@2color any updates/guidance?

Copy link
Collaborator

@2color 2color left a comment

Choose a reason for hiding this comment

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

This is starting to take shape nicely. See comments.

Main points:

@Nkovaturient
Copy link
Author

@2color Thanks a bunch for reviewing it.
I shall get back to you with an update.

@Nkovaturient
Copy link
Author

Hello there, @2color
I have updated with the following changes:-

  • Remove the redundant findPeerById function and use libp2p.dial() directly
  • Move connection state management to the context
  • Create a dedicated PeerConnect component for the UI
  • Simplify the connection logic by leveraging js-libp2p's built-in peer routing
  • Remove the unnecessary peer multiaddr list component since we're connecting directly via PeerID

https://www.loom.com/share/8d3333d1d316419b8a882e4cb4f648f3?sid=b65f2e97-a290-424a-a0ad-1a6b608965c0

Copy link
Collaborator

@2color 2color left a comment

Choose a reason for hiding this comment

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

Thanks @Nkovaturient.

I just took a look at this and think we can simplify this further. Instead of adding a new component to connect to PeerIDs, let's repurpose the existing multiaddr input and also allow PeerIDs there too.

In the handler (what's now called handleConnectToMultiaddr), you can use heuristics (like inspecting the first char /) or just try parsing as PeerID and if that fails, try creating a Multiaddr.

Final note, before committing, please run npm run format.

@Nkovaturient
Copy link
Author

Sure @2color , that would be an efficient approach, lemme modify it as desired

@Nkovaturient
Copy link
Author

Hey @2color , why was the bootstrap module removed from main?
Albeit short-term, It was an efficient module for anyone getting started with uc and avoiding unnecessary err of no addresses discovered

@Nkovaturient
Copy link
Author

#225

Got it, okay 👍

@Nkovaturient
Copy link
Author

@2color , websockets connections are failing to establish connections on Chrome and Edge browser. I have tried refreshing a lot but to no avail ...??

Screenshot (516)

Screenshot (517)

@2color
Copy link
Collaborator

2color commented Feb 27, 2025

@Nkovaturient Are you getting these errors with the latest main branch too?

Can you also share the result of https://test-ipv6.com/? I pushed a fix (34b6b35) that may cause be related to this.

@Nkovaturient
Copy link
Author

@Nkovaturient Are you getting these errors with the latest main branch too?

Can you also share the result of https://test-ipv6.com/? I pushed a fix (34b6b35) that may cause be related to this.

Yeah, I have updated with the main branch yet the same errors. pkg update and fix (34b6b35) seems okay, I have not been able to open the server since the bootstraplistenaddr were removed and replaced by ipv4 and websockets nonetheless the relaylistenaddr

ipv6 tests
Screenshot (518)

@2color
Copy link
Collaborator

2color commented Mar 12, 2025

The latest changes undo the functionality intended to be introduced by this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants