Add config option to globally disable multi-upstream mode

Closes: https://todo.sr.ht/~emersion/soju/122
This commit is contained in:
Simon Ser 2021-11-17 11:41:11 +01:00
parent 61e6b2efa4
commit 3941f67380
5 changed files with 24 additions and 2 deletions

View File

@ -92,6 +92,7 @@ func loadConfig() (*config.Server, *soju.Config, error) {
HTTPOrigins: raw.HTTPOrigins, HTTPOrigins: raw.HTTPOrigins,
AcceptProxyIPs: raw.AcceptProxyIPs, AcceptProxyIPs: raw.AcceptProxyIPs,
MaxUserNetworks: raw.MaxUserNetworks, MaxUserNetworks: raw.MaxUserNetworks,
MultiUpstream: raw.MultiUpstream,
Debug: debug, Debug: debug,
MOTD: motd, MOTD: motd,
} }

View File

@ -51,6 +51,7 @@ type Server struct {
AcceptProxyIPs IPSet AcceptProxyIPs IPSet
MaxUserNetworks int MaxUserNetworks int
MultiUpstream bool
} }
func Defaults() *Server { func Defaults() *Server {
@ -63,6 +64,7 @@ func Defaults() *Server {
SQLDriver: "sqlite3", SQLDriver: "sqlite3",
SQLSource: "soju.db", SQLSource: "soju.db",
MaxUserNetworks: -1, MaxUserNetworks: -1,
MultiUpstream: true,
} }
} }
@ -138,6 +140,16 @@ func parse(cfg scfg.Block) (*Server, error) {
if srv.MaxUserNetworks, err = strconv.Atoi(max); err != nil { if srv.MaxUserNetworks, err = strconv.Atoi(max); err != nil {
return nil, fmt.Errorf("directive %q: %v", d.Name, err) return nil, fmt.Errorf("directive %q: %v", d.Name, err)
} }
case "multi-upstream-mode":
var str string
if err := d.ParseParams(&str); err != nil {
return nil, err
}
v, err := strconv.ParseBool(str)
if err != nil {
return nil, fmt.Errorf("directive %q: %v", d.Name, err)
}
srv.MultiUpstream = v
default: default:
return nil, fmt.Errorf("unknown directive %q", d.Name) return nil, fmt.Errorf("unknown directive %q", d.Name)
} }

View File

@ -152,6 +152,10 @@ The following directives are supported:
Path to the MOTD file. The bouncer MOTD is sent to clients which aren't Path to the MOTD file. The bouncer MOTD is sent to clients which aren't
bound to a specific network. By default, no MOTD is sent. bound to a specific network. By default, no MOTD is sent.
*multi-upstream-mode* true|false
Globally enable or disable multi-upstream mode. By default, multi-upstream
mode is enabled.
# IRC SERVICE # IRC SERVICE
soju exposes an IRC service called *BouncerServ* to manage the bouncer. soju exposes an IRC service called *BouncerServ* to manage the bouncer.

View File

@ -1171,7 +1171,7 @@ func (dc *downstreamConn) welcome() error {
return err return err
} }
if dc.network == nil && !dc.caps["soju.im/bouncer-networks"] { if dc.network == nil && !dc.caps["soju.im/bouncer-networks"] && dc.srv.Config().MultiUpstream {
dc.isMultiUpstream = true dc.isMultiUpstream = true
} }

View File

@ -61,6 +61,7 @@ type Config struct {
HTTPOrigins []string HTTPOrigins []string
AcceptProxyIPs config.IPSet AcceptProxyIPs config.IPSet
MaxUserNetworks int MaxUserNetworks int
MultiUpstream bool
MOTD string MOTD string
} }
@ -85,7 +86,11 @@ func NewServer(db Database) *Server {
listeners: make(map[net.Listener]struct{}), listeners: make(map[net.Listener]struct{}),
users: make(map[string]*user), users: make(map[string]*user),
} }
srv.config.Store(&Config{Hostname: "localhost", MaxUserNetworks: -1}) srv.config.Store(&Config{
Hostname: "localhost",
MaxUserNetworks: -1,
MultiUpstream: true,
})
return srv return srv
} }