Skip to content

Commit

Permalink
Fill registration URL for websocket proxy even when not overriding co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
tulir committed Apr 10, 2024
1 parent ff0000e commit bcbc431
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
29 changes: 17 additions & 12 deletions cmd/bbctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,7 @@ func doGenerateBridgeConfig(ctx *cli.Context, bridge string) (*generatedBridgeCo
var listenAddress string
var listenPort uint16
if !websocket {
ipSuffix := bridgeIPSuffix[bridgeType]
if ipSuffix == "" {
ipSuffix = "1"
}
listenAddress = "127.29.3." + ipSuffix
// macOS is weird and doesn't support loopback addresses properly,
// it only routes 127.0.0.1/32 rather than 127.0.0.0/8
if runtime.GOOS == "darwin" {
listenAddress = "127.0.0.1"
}
listenPort = uint16(30000 + (crc32.ChecksumIEEE([]byte(bridge)) % 30000))
reg.Registration.URL = fmt.Sprintf("http://%s:%d", listenAddress, listenPort)
listenAddress, listenPort, reg.Registration.URL = getBridgeWebsocketProxyConfig(bridge, bridgeType)
}
cfg, err := bridgeconfig.Generate(bridgeType, bridgeconfig.Params{
HungryAddress: reg.HomeserverURL,
Expand All @@ -322,6 +311,22 @@ func doGenerateBridgeConfig(ctx *cli.Context, bridge string) (*generatedBridgeCo
}, err
}

func getBridgeWebsocketProxyConfig(bridgeName, bridgeType string) (listenAddress string, listenPort uint16, url string) {
ipSuffix := bridgeIPSuffix[bridgeType]
if ipSuffix == "" {
ipSuffix = "1"
}
listenAddress = "127.29.3." + ipSuffix
// macOS is weird and doesn't support loopback addresses properly,
// it only routes 127.0.0.1/32 rather than 127.0.0.0/8
if runtime.GOOS == "darwin" {
listenAddress = "127.0.0.1"
}
listenPort = uint16(30000 + (crc32.ChecksumIEEE([]byte(bridgeName)) % 30000))
url = fmt.Sprintf("http://%s:%d", listenAddress, listenPort)
return
}

func generateBridgeConfig(ctx *cli.Context) error {
if ctx.NArg() == 0 {
return UserError{"You must specify a bridge to generate a config for"}
Expand Down
3 changes: 3 additions & 0 deletions cmd/bbctl/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ func runBridge(ctx *cli.Context) error {
var cancelWS context.CancelFunc
wsProxyClosed := make(chan struct{})
if needsWebsocketProxy {
if cfg.Registration.URL == "" {
_, _, cfg.Registration.URL = getBridgeWebsocketProxyConfig(bridgeName, cfg.BridgeType)
}
wg.Add(2)
log.Printf("Starting websocket proxy")
as = appservice.Create()
Expand Down

0 comments on commit bcbc431

Please sign in to comment.