ssbc / multiserver-scopes

6 stars 0 forks source link

Should this module also accept a host and return an array? #1

Open christianbundy opened 5 years ago

christianbundy commented 5 years ago

Hey @regular! I've been working on the problem where multiserver listens on :: but multiserver.stringify() uses this module seems to only return a single address, which is causing connectivity issues because it's not broadcasting all of the addresses that it's actually listening on. When ssb-config sets the host as :: Node understands that means "listen on all interfaces" but then when we call multiserver.stringify() it only returns the address for one interface..

I've opened https://github.com/ssbc/ssb-config/pull/53/files as a workaround to resolve this, but I'm realizing that this problem may be worth resolving in multiserver and multiserver-scopes instead. Here's what I'm thinking:

Before

host('local') // => '192.168.0.109'

After

host('local', '::') // => [ '192.168.0.109', '172.18.0.1', 'fce2:9811:4862:81a7:bb08:91d6:2e41:d220' ]

host('local', '0.0.0.0') // => [ '192.168.0.109', '172.18.0.1' ]
regular commented 5 years ago

hmmm ... or maybe :: would cause multiserver to iterate through all the scopes, ask multiserver-scopes for the address for each one of them in turn and collect the results?

or, maybe better: multiserver-scopes has a function that returns address that cover all scopes?

host('local', '::') doesn't make a whole lot of sense if you look at it without the context you gave, so I'm not a big fan.

christianbundy commented 5 years ago

Thanks for the quick response! Do you think the ssb-config workaround is a reasonable enough workaround (if config.host == null, enumerate interfaces automatically) or do you think that will break things for you?

multiserver to iterate through all the scopes, ask multiserver-scopes for the address for each one of them in turn and collect the results

In this system would multiserver-scopes be returning a single address or an array? I think I'm lacking context for why host('local') only returns one address (e.g. maybe I have both an IPv4 and IPv6 address on the LAN), so it's very possible that I'm just missing the bigger picture.

christianbundy commented 5 years ago

Thinking about this more, I think I'm making two distinct proposals that would fix behavior for multiserver listening on the :: and 0.0.0.0 meta-addresses:

  1. multiserver-scopes returns an array when multiple addresses are available
    • device: ['127.0.0.1', '::1']
    • local: [ '192.168.0.42', '10.0.0.1' ]
    • public: [ '1.2.3.4', '5.6.7.8' ]
  2. multiserver-scopes accepts an optional family argument to specify IPv4 or IPv6
    • scopes('device', 'IPv4') // => ['127.0.0.1']
    • scopes('device', 'IPv6') // => [ '::1' ]
regular commented 5 years ago

@christianbundy both sound fine to me. My feeling was that nobody had a clear grasp on what scopes actually are (certainly I don't). That's why I created this module, so that the definition of scopes would eventually end up here and would be defined by code at one place.

regular commented 5 years ago

@christianbundy I agree that host() should return an array. You are right, to assume that there's just one IP in each scope is silly. The reason it does not is that the underlying non-private-ip module simply returns the first IP that matches a predicate. Using os.networkInterfaces() directly in multiserver-scopes@2 makes sense to me.