Peer Discovery across different Networks

Hi everyone!
I started playing with IPFS a couple of weeks ago and i managed to build a live chat system with integrated file sharing across the peers, nothing crazy.

Basically when User A joins a chat i subscribe to a specific PubSub and send some messages around to the other Peers.
There is obviously no problem in discovering local Peers and i always get connected to my devices under the same WiFi.

So at this point i decided to try across different networks and my iPhone on cellular cannot discover my laptop (on WiFi), i even tried hosting my own js-libp2p-webrtc-star signaling server (with SSL and stuff) but nothing helped.

Any suggestion?
Here is the configuration im using in the browser IPFS instance so far:

const conf: any = {
  peerId,
  addresses: {
    listen: [
      '/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
      '/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
    ],
  },
  dialer: {
    maxParallelDials: 150, // 150 total parallel multiaddr dials
    maxDialsPerPeer: 4, // Allow 4 multiaddrs to be dialed per peer in parallel
    dialTimeout: 10e3, // 10 second dial timeout per peer dial
    resolvers: {
      dnsaddr: dnsaddrResolver
    },
    addressSorter: publicAddressesFirst
  },
  modules: {
    transport: [WS, WebRTCStar],
    streamMuxer: [MPLEX],
    connEncryption: [NOISE],
    peerDiscovery: [Bootstrap],
    pubsub: GossipSub,
    dht: KadDHT,
  },
  
  transportManager: {
    // https://github.com/libp2p/js-libp2p/blob/0a6bc0d1013dfd80ab600e8f74c1544b433ece29/doc/CONFIGURATION.md#configuring-transport-manager
    // We don't want js-ipfs boot to fail when all webrtc signaling servers are down
    faultTolerance: FaultTolerance.NO_FATAL
  },
  config: {
    peerDiscovery: {
      autoDial: true,
      [Bootstrap.tag]: {
        enabled: true,
        list: bootstrapList
      },
      // [WebRTCStar.discovery.tag]
      [WebRTCStar.tag]: {
        enabled: true
      }
    },
    dht: {
      enabled: true,
      kBucketSize: 20,
      randomWalk: {
        enabled: true,
        interval: 10e3, // This is set low intentionally, so more peers are discovered quickly. Higher intervals are recommended
        timeout: 2e3 // End the query quickly since we're running so frequently
      }
    },
    pubsub: {
      enabled: true,
      emitSelf: true
    },
    nat: {
      enabled: true,
      ttl: 7200, // TTL for port mappings (min 20 minutes)
      keepAlive: true, // Refresh port mapping after TTL expires
      pmp: {
        enabled: false, // defaults to false
      }
    },
    relay: {
      enabled: true,
      hop: {
        enabled: true,
        active: true
      }
    }
  },
  metrics: {
    enabled: false
  },
  peerStore: {
    persistence: true,
    threshold: 1
  }
}

SIDE NOTE: connecting my iPhone to the office VPN ends up “fixing” the issue and my laptop can see the iphone peer but this is happening in the VPN subnet of course, im suspecting something about advertising maybe.

1 Like

Do you use your own bootstrap nodes?

Hello there!
I tried with my own libp2p-webrtc-star signaling server! No luck!

But maybe there is something in my configuration…
I’m running my signaling server on a DigitalOcean server, I thought that having a single public and shared signaling server was enough but I can’t make my peers talk via pub sub :frowning:

Update

So far i’m still unable to connect peers across different Networks.

My Setup

  • IPFS Browser App on Device A connected via home WiFi

  • IPFS Browser App on Device A connected via mobile LTE

  • Self Hosted webrtc-start signaling server with HTTP

  • Both IPFS instances connect only to this signaling server

After many struggles it looks like my Devices are actually seeing each other,
by adding this method:

ipfs.libp2p.on('peer:discovery', (peer) => {
      console.log('discovered', peer)
    });

i noticed that each Device was logging the other Device PeerID correctly.

In this situation it seems that actual data can be transferred from Device A <-> Device B so it looks to me like the connection is working.

The problem is PubSub is not aware of peers yet, any idea why peers seems to be discovered but pubsub is not aware of it? Thanks!

2 Likes