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,
AcceptProxyIPs: raw.AcceptProxyIPs,
MaxUserNetworks: raw.MaxUserNetworks,
MultiUpstream: raw.MultiUpstream,
Debug: debug,
MOTD: motd,
}

View file

@ -51,6 +51,7 @@ type Server struct {
AcceptProxyIPs IPSet
MaxUserNetworks int
MultiUpstream bool
}
func Defaults() *Server {
@ -63,6 +64,7 @@ func Defaults() *Server {
SQLDriver: "sqlite3",
SQLSource: "soju.db",
MaxUserNetworks: -1,
MultiUpstream: true,
}
}
@ -138,6 +140,16 @@ func parse(cfg scfg.Block) (*Server, error) {
if srv.MaxUserNetworks, err = strconv.Atoi(max); err != nil {
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:
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
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
soju exposes an IRC service called *BouncerServ* to manage the bouncer.

View file

@ -1171,7 +1171,7 @@ func (dc *downstreamConn) welcome() error {
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
}

View file

@ -61,6 +61,7 @@ type Config struct {
HTTPOrigins []string
AcceptProxyIPs config.IPSet
MaxUserNetworks int
MultiUpstream bool
MOTD string
}
@ -85,7 +86,11 @@ func NewServer(db Database) *Server {
listeners: make(map[net.Listener]struct{}),
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
}