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

[Feature] lan discovery (broadcast/multicast?) #115

Open
freddi301 opened this issue Jul 11, 2022 · 3 comments
Open

[Feature] lan discovery (broadcast/multicast?) #115

freddi301 opened this issue Jul 11, 2022 · 3 comments

Comments

@freddi301
Copy link

In alternative is there a way to connect directly to a peer by ip:port?

@robbiemu
Copy link

robbiemu commented Mar 6, 2023

I believe this is the documentation site. this is provides a friendly wrapper around/is based on @hyperswarm/dht

"In the Hyperswarm DHT, peers are identified by a public key, not by an IP address. If you know someone's public key, you can connect to them regardless of where they're located". The underlying p2p mechanism is described in https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf.

I don't believe you can do that without replacing @hyperswarm/dht -- probably out of scope for this project.

What I am wondering is, how do the dht nodes traffic their information? I havent actually read that PDF yet :P -- but I dont expect that the server related aspect of it is covered there.

@cjmont
Copy link

cjmont commented Oct 3, 2023

Connecting to different peers with specific IPs in a P2P network using Hyperswarm is not the typical way to use the library, as Hyperswarm is designed to handle peer discovery and connection management for you, using a Distributed Hash Table (DHT) for peer discovery based on a specific "topic."

However, if you need to establish connections with specific IPs, you might need to use a direct connection solution using the net module in Node.js, as mentioned in previous answers, or look for a different P2P network library that allows direct connections to specific IPs and ports.

Example of Direct Connection with Node.js net:

Server (IP: 192.168.1.2, Port: 3000)

const net = require('net');

const server = net.createServer((socket) => {
  console.log('New peer connected');

  socket.on('data', (data) => {
    console.log('Data received:', data.toString());
  });

  socket.write('Hello from the server');
});

server.listen(3000, '192.168.1.2', () => {
  console.log('Server listening on 192.168.1.2:3000');
});

Client (Connecting to 192.168.1.2:3000)

const net = require('net');

const socket = net.createConnection(3000, '192.168.1.2', () => {
  console.log('Connected to the server');

  socket.on('data', (data) => {
    console.log('Data received:', data.toString());
  });

  socket.write('Hello from the client');
});

This example establishes a direct TCP connection between a client and a server using specific IP addresses and ports. If you need a full P2P solution with the ability to connect to specific peers by IP and port, you might need to look for a different library or build a custom solution that combines Hyperswarm for peer discovery and direct TCP connections for specific peers.

Keep in mind that direct connections can be problematic if peers are behind NATs or firewalls, and you might need to implement NAT traversal techniques to establish successful connections in such cases.

@freddi301
Copy link
Author

My scenario was developing a p2p application.
What i had to do is to develop a seprata module for LAN connections.
My quetion here is if hyperswarm could be shipped with LAN discovery incorporated to make the use of it more seamless.

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

No branches or pull requests

3 participants