ssbc / multiserver

A single interface that can work with multiple protocols, and multiple transforms of those protocols (eg, security layer)
MIT License
104 stars 28 forks source link

support multiple scopes on one server #29

Closed dominictarr closed 5 years ago

dominictarr commented 5 years ago

As suggested in https://github.com/ssbc/ssb-config/issues/24#issuecomment-434251335 I implemented support for multiple scopes.

This enables you to say host a server at ["device", "local"] which will make scuttlebot/bin.js work unchanged, but will also allow peers on the local network to connect to the same encrypted connection. also, without needing extensive configuration.

I think this gets us both explicit binding as you wanted @regular and also means bin works (even with old sbot or git-ssb etc).

to listen on all addresses, you also don't need loads of lines of config (which are easy to mess up)

regular commented 5 years ago

to listen on all addresses, you also don't need loads of lines of config (which are easy to mess up)

hm, that wasn't really ever a problem, because you would simply put host: "::" in your config, which is what I suggested to be the default to have backward compatibility in https://github.com/ssbc/ssb-ws/pull/12#issue-225722000 and https://github.com/ssbc/multiserver/pull/25#issue-225439589

As expressed in https://github.com/ssbc/ssb-config/issues/24#issuecomment-434598198 , I have a feeling that scopes are not the best abstraction moving forward, they make it hard to express your explicit config desires.

It also looks like an increase of code complexity compared to simply having multiple instances of the same plugin, each one responsible for a single port/address combination, as I proposed, so I don''t really see the benefits of your solution. I might be missing something though.

dominictarr commented 5 years ago

@regular the difficulty is the relationship between scopes and network interfaces. for example, you can bind :: but when you call getAddress(<scope>) what address does it return? If i put local scope, it doesn't get included in device. if I put public scope, it's not included in local.

If an address is on exactly one scope, then you need to define several servers to handle multiple scopes. say, to be backwards compatibile with 11, a peer needs to listen on at least localhost and on the local network. so device and local scopes, so that scuttlebot/bin.js can connect, and also the address can be broadcast to other wifi peers, who can also connect.

So, alternatively, you could have scopes ordered - so a getAddress('device') includes local and public scoped addresses... but public may include non-ip transport protocols such as onion. (I know tor is built on top of tcp/ip, but that implementation detail is completely hidden from the user)

On my laptop node, I have a net server that is exposed to the local network, but it's not a public scope, meaning the entire internet can't connect, not unless they are on the same network as me. So when I do getAddress('public') I want it to return my ssb-tunnel address (which is long lived) but not my wifi address, which isn't.

However, my pub does have a static ip address, so I want the net server to include the public scope in that case.

dominictarr commented 5 years ago

merged #32 instead