mafintosh / discovery-swarm

A network swarm that uses discovery-channel to find peers
MIT License
375 stars 57 forks source link

utp: true causes whoami to return wrong port #32

Open max-mapper opened 6 years ago

max-mapper commented 6 years ago

when running this code inside a docker container:

var swarm = require('discovery-swarm')   
var defaults = require('datland-swarm-defaults')()
var sw = swarm({
  dns: {
    servers: defaults.dns.server
  }
})

sw.listen(9000, console.log.bind(console))

I get the debug discovery-channel whoami() succeeded, I am: { port: 9000, host: '104.197.167.83' } +113ms

But running this:

var swarm = require('discovery-swarm')   
var defaults = require('datland-swarm-defaults')()
var sw = swarm({
  utp: false,
  dns: {
    servers: defaults.dns.server
  }
})

sw.listen(9000, console.log.bind(console))

I get debug discovery-channel whoami() succeeded, I am: { port: 57969, host: '104.197.167.83' } +118ms

In this case I expect 57969 from both cases, 9000 is the internal port in the docker container and is the wrong port to return

max-mapper commented 6 years ago

I think related to https://github.com/mafintosh/discovery-swarm/pull/11#issuecomment-261333232

mafintosh commented 6 years ago

It's unrelated. The port is the public port the dht sees when using utp (they share a socket in order for hole punching to work)

Why are you explicitly passing a port to listen on instead of having the swarm pick it?