marcopiraccini / sd-swim

Self- discovery version of SWIM membership protocol with metadata distribution
MIT License
8 stars 7 forks source link

me accessor should always return a host #3

Closed mcollina closed 7 years ago

mcollina commented 7 years ago

otherwise we cannot do:

a = new Swim({ port: 0 })
a.on('up', function () {
  b = new Swim({ port: 0, hosts: [a.me] })
})
marcopiraccini commented 7 years ago

This (host not known) happens with a single/unjoined node. The point is that a node doesn't know his host until a JOIN with another host is done. The host indeed is deducted during the JOIN phase from the receiving UDP messages (see: https://github.com/marcopiraccini/sd-swim#join-protocol)

What we could do is:

mcollina commented 7 years ago

This is useful mostly in unit tests. I'm ok if we return 'localhost' in me if there is no host, or that we use https://www.npmjs.com/package/network-address in that case.

As we are in unit tests, host might be ok to be 'localhost'.

marcopiraccini commented 7 years ago

https://www.npmjs.com/package/network-address is a good module, but it takes the first interface found so it's often "wrong". So defaulting to 127.0.0.1 should be the safer choice for running tests.

marcopiraccini commented 7 years ago

Added and here the test: https://github.com/marcopiraccini/sd-swim/blob/master/test/sd-swim.js#L189

mcollina commented 7 years ago

Thanks!!