diff --git a/go/daemon/config.go b/go/daemon/config.go index b717eb1..8423ffb 100644 --- a/go/daemon/config.go +++ b/go/daemon/config.go @@ -8,14 +8,34 @@ import ( "isle/daemon/network" ) +// getDeprecatedNetworkConfig will return the NetworkConfig configured in the +// deprecated configuration format, or nil if the deprecated format is not used. +// +// In the deprecated format it is not possible to explicitly know which network +// a NetworkConfig is intended for, so the Daemon can only allow a single +// network to be joined when using this format. +// +// DEPRECATED +func getDeprecatedNetworkConfig( + networkConfigs map[string]daecommon.NetworkConfig, +) *daecommon.NetworkConfig { + if len(networkConfigs) != 1 { + return nil + } + + if c, ok := networkConfigs[daecommon.DeprecatedNetworkID]; ok { + return &c + } + + return nil +} + func pickNetworkConfig( networkConfigs map[string]daecommon.NetworkConfig, creationParams bootstrap.CreationParams, ) *daecommon.NetworkConfig { - if len(networkConfigs) == 1 { // DEPRECATED - if c, ok := networkConfigs[daecommon.DeprecatedNetworkID]; ok { - return &c - } + if c := getDeprecatedNetworkConfig(networkConfigs); c != nil { + return c } for searchStr, networkConfig := range networkConfigs { diff --git a/go/daemon/daemon.go b/go/daemon/daemon.go index 74ad137..5d1e2f8 100644 --- a/go/daemon/daemon.go +++ b/go/daemon/daemon.go @@ -71,6 +71,11 @@ func New( return nil, fmt.Errorf("listing loadable networks: %w", err) } + if getDeprecatedNetworkConfig(daemonConfig.Networks) != nil && + len(loadableNetworks) > 1 { + return nil, errors.New("Deprecated config format cannot be used when there are more than one loadable networks") + } + if err := validateConfig( ctx, networkLoader, daemonConfig, loadableNetworks, ); err != nil { @@ -131,6 +136,13 @@ func (d *Daemon) CreateNetwork( d.l.Lock() defer d.l.Unlock() + if getDeprecatedNetworkConfig(d.daemonConfig.Networks) != nil && + len(d.networks) > 0 { + return network.ErrInvalidConfig.WithData( + "Cannot use deprecated configuration file format while joined to more than one network", + ) + } + var ( networkConfig = pickNetworkConfig( d.daemonConfig.Networks, creationParams, @@ -182,6 +194,13 @@ func (d *Daemon) JoinNetwork( d.l.Lock() defer d.l.Unlock() + if getDeprecatedNetworkConfig(d.daemonConfig.Networks) != nil && + len(d.networks) > 0 { + return network.ErrInvalidConfig.WithData( + "Cannot use deprecated configuration file format while joined to more than one network", + ) + } + var ( creationParams = newBootstrap.Bootstrap.NetworkCreationParams networkID = creationParams.ID