various: make AddressChooser an interface
See https://vanadium-review.googlesource.com/#/c/12694/ for rationale.
MultiPart: 3/4
Change-Id: Ibeb150e1dc5498d62e933ed4b29ca7f457ade9b4
diff --git a/runtime/factories/gce/gce.go b/runtime/factories/gce/gce.go
index 9fe80da..b38548b 100644
--- a/runtime/factories/gce/gce.go
+++ b/runtime/factories/gce/gce.go
@@ -58,9 +58,9 @@
if ip, err := gce.ExternalIPAddress(); err != nil {
return nil, nil, nil, err
} else {
- listenSpec.AddressChooser = func(network string, addrs []net.Addr) ([]net.Addr, error) {
+ listenSpec.AddressChooser = netstate.AddressChooserFunc(func(network string, addrs []net.Addr) ([]net.Addr, error) {
return []net.Addr{netstate.NewNetAddr("wsh", ip.String())}, nil
- }
+ })
}
runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, nil, "", commonFlags.RuntimeFlags(), nil)
diff --git a/runtime/factories/generic/generic.go b/runtime/factories/generic/generic.go
index 9de2b92..eabda93 100644
--- a/runtime/factories/generic/generic.go
+++ b/runtime/factories/generic/generic.go
@@ -43,7 +43,7 @@
lf := commonFlags.ListenFlags()
listenSpec := rpc.ListenSpec{
Addrs: rpc.ListenAddrs(lf.Addrs),
- AddressChooser: internal.IPAddressChooser,
+ AddressChooser: internal.IPAddressChooser{},
Proxy: lf.ListenProxy,
}
diff --git a/runtime/factories/roaming/roaming.go b/runtime/factories/roaming/roaming.go
index 40d82e0..5424691 100644
--- a/runtime/factories/roaming/roaming.go
+++ b/runtime/factories/roaming/roaming.go
@@ -71,12 +71,12 @@
// 1:1 NAT configuration.
if !internal.HasPublicIP(logger.Global()) {
if addr := internal.GCEPublicAddress(logger.Global()); addr != nil {
- listenSpec.AddressChooser = func(string, []net.Addr) ([]net.Addr, error) {
+ listenSpec.AddressChooser = netstate.AddressChooserFunc(func(string, []net.Addr) ([]net.Addr, error) {
// TODO(cnicolaou): the protocol at least should
// be configurable, or maybe there's a RuntimeFactory specific
// flag to configure both the protocol and address.
return []net.Addr{netstate.NewNetAddr("wsh", addr.String())}, nil
- }
+ })
runtime, ctx, shutdown, err := rt.Init(ctx, ac, nil, &listenSpec, nil, "", commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {
return nil, nil, shutdown, err
@@ -117,7 +117,7 @@
cleanupCh := make(chan struct{})
watcherCh := make(chan struct{})
- listenSpec.AddressChooser = internal.IPAddressChooser
+ listenSpec.AddressChooser = internal.IPAddressChooser{}
runtime, ctx, shutdown, err := rt.Init(ctx, ac, nil, &listenSpec, publisher, SettingsStreamName, commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {
@@ -175,7 +175,7 @@
ch <- irpc.NewRmAddrsSetting(removed.AsNetAddrs())
}
// We will always send the best currently available address
- if chosen, err := listenSpec.AddressChooser(listenSpec.Addrs[0].Protocol, cur.AsNetAddrs()); err == nil && chosen != nil {
+ if chosen, err := listenSpec.AddressChooser.ChooseAddress(listenSpec.Addrs[0].Protocol, cur.AsNetAddrs()); err == nil && chosen != nil {
vlog.VI(2).Infof("Sending added and chosen: %s", chosen)
ch <- irpc.NewAddAddrsSetting(chosen)
} else {
diff --git a/runtime/factories/static/static.go b/runtime/factories/static/static.go
index c0873bb..c92732b 100644
--- a/runtime/factories/static/static.go
+++ b/runtime/factories/static/static.go
@@ -53,9 +53,9 @@
// running on GCE.
if !internal.HasPublicIP(logger.Global()) {
if addr := internal.GCEPublicAddress(logger.Global()); addr != nil {
- listenSpec.AddressChooser = func(string, []net.Addr) ([]net.Addr, error) {
+ listenSpec.AddressChooser = rpc.AddressChooserFunc(func(string, []net.Addr) ([]net.Addr, error) {
return []net.Addr{addr}, nil
- }
+ })
runtime, ctx, shutdown, err := rt.Init(ctx, ac, nil, &listenSpec, nil, "", commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {
return nil, nil, nil, err
@@ -67,7 +67,7 @@
return runtime, ctx, runtimeFactoryShutdown, nil
}
}
- listenSpec.AddressChooser = internal.IPAddressChooser
+ listenSpec.AddressChooser = internal.IPAddressChooser{}
runtime, ctx, shutdown, err := rt.Init(ctx, ac, nil, &listenSpec, nil, "", commonFlags.RuntimeFlags(), reservedDispatcher)
if err != nil {