ssbc / ssb-config

standard configuration for ssb
MIT License
23 stars 18 forks source link

connections/host/port/ws refactor + tests #31

Closed mixmix closed 5 years ago

mixmix commented 5 years ago

The purpose of the PR is to close over some dangerous looseness in the connection setting behaviour.

When I say "legacy config" in this PR I mean config.host config.port config.ws, while "new config" is connections.incoming

Possible pathways

  1. DEFAULT MODE : don't add anything and you get happy new and old config provided
  2. LEGACY MODE : set any of the old style config (host port ws)
    • default connections.incoming is generated based on what you provided
    • host, port, ws.port are then derived from the that connections.incoming
  3. NEW MODE : set connections.incoming
    • host, port, ws.port are then derived from the that connections.incoming
  4. MIXED MODE !! : set legacy things and connections.incoming
    • just works ^:tm:
    • if you port host ws lead to contradictions with your declared connections.incoming an error is thrown.

The algorithm

  1. see what building the config is based on opts RC
  2. if no connections.incoming set that
    • based on anything in config.host config.port config.ws picked up along the way
    • fall back to some default (e.g. net port 8008)
  3. check if the connections.incoming contradicts the the legacy config
  4. over-write the legacy config based on the new config
    • this ensures that legacy setup is always catered for, and also guards against divergence

TODO:

mixmix commented 5 years ago

@dominictarr here's a juicy testing PR :watermelon: :sweat_drops:

EDIT: this adds tests AND changes behaviour

dominictarr commented 5 years ago

merged into 3.2.0