diff --git a/go/beacon_srv/internal/beaconing/originator_test.go b/go/beacon_srv/internal/beaconing/originator_test.go index 9c3dbfbc55..8b596f48a7 100644 --- a/go/beacon_srv/internal/beaconing/originator_test.go +++ b/go/beacon_srv/internal/beaconing/originator_test.go @@ -29,7 +29,6 @@ import ( "github.com/scionproto/scion/go/beacon_srv/internal/beacon" "github.com/scionproto/scion/go/beacon_srv/internal/ifstate" "github.com/scionproto/scion/go/beacon_srv/internal/onehop" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl" "github.com/scionproto/scion/go/lib/ctrl/seg" @@ -72,9 +71,9 @@ func TestOriginatorRun(t *testing.T) { Sender: onehop.Sender{ IA: xtest.MustParseIA("1-ff00:0:110"), Conn: conn, - Addr: &addr.AppAddr{ - L3: addr.HostFromIPStr("127.0.0.1"), - L4: 4242, + Addr: &net.UDPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 4242, }, MAC: mac, }, @@ -126,9 +125,9 @@ func TestOriginatorRun(t *testing.T) { Sender: onehop.Sender{ IA: xtest.MustParseIA("1-ff00:0:110"), Conn: conn, - Addr: &addr.AppAddr{ - L3: addr.HostFromIPStr("127.0.0.1"), - L4: 4242, + Addr: &net.UDPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 4242, }, MAC: mac, }, diff --git a/go/beacon_srv/internal/beaconing/propagator_test.go b/go/beacon_srv/internal/beaconing/propagator_test.go index 65af6fcff1..c222eb4717 100644 --- a/go/beacon_srv/internal/beaconing/propagator_test.go +++ b/go/beacon_srv/internal/beaconing/propagator_test.go @@ -29,7 +29,6 @@ import ( "github.com/scionproto/scion/go/beacon_srv/internal/beaconing/mock_beaconing" "github.com/scionproto/scion/go/beacon_srv/internal/ifstate" "github.com/scionproto/scion/go/beacon_srv/internal/onehop" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest" "github.com/scionproto/scion/go/lib/scrypto" @@ -161,9 +160,9 @@ func TestPropagatorRun(t *testing.T) { Sender: onehop.Sender{ IA: topoProvider.Get().IA(), Conn: conn, - Addr: &addr.AppAddr{ - L3: addr.HostFromIPStr("127.0.0.1"), - L4: 4242, + Addr: &net.UDPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 4242, }, MAC: macSender, }, @@ -233,9 +232,9 @@ func TestPropagatorRun(t *testing.T) { Sender: onehop.Sender{ IA: topoProvider.Get().IA(), Conn: conn, - Addr: &addr.AppAddr{ - L3: addr.HostFromIPStr("127.0.0.1"), - L4: 4242, + Addr: &net.UDPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 4242, }, MAC: macSender, }, diff --git a/go/beacon_srv/internal/keepalive/BUILD.bazel b/go/beacon_srv/internal/keepalive/BUILD.bazel index 5c83cc5ec6..8bdf7a7e94 100644 --- a/go/beacon_srv/internal/keepalive/BUILD.bazel +++ b/go/beacon_srv/internal/keepalive/BUILD.bazel @@ -37,7 +37,6 @@ go_test( "//go/beacon_srv/internal/ifstate:go_default_library", "//go/beacon_srv/internal/keepalive/mock_keepalive:go_default_library", "//go/beacon_srv/internal/onehop:go_default_library", - "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", "//go/lib/ctrl:go_default_library", "//go/lib/ctrl/ifid:go_default_library", diff --git a/go/beacon_srv/internal/keepalive/sender_test.go b/go/beacon_srv/internal/keepalive/sender_test.go index 5762e8d791..3d2aee1022 100644 --- a/go/beacon_srv/internal/keepalive/sender_test.go +++ b/go/beacon_srv/internal/keepalive/sender_test.go @@ -16,6 +16,7 @@ package keepalive import ( "context" + "net" "testing" "github.com/golang/mock/gomock" @@ -23,7 +24,6 @@ import ( "github.com/stretchr/testify/require" "github.com/scionproto/scion/go/beacon_srv/internal/onehop" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl" "github.com/scionproto/scion/go/lib/infra" @@ -49,9 +49,9 @@ func TestSenderRun(t *testing.T) { Sender: &onehop.Sender{ IA: xtest.MustParseIA("1-ff00:0:111"), Conn: conn, - Addr: &addr.AppAddr{ - L3: addr.HostFromIPStr("127.0.0.1"), - L4: 4242, + Addr: &net.UDPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 4242, }, MAC: mac, }, diff --git a/go/beacon_srv/internal/onehop/sender.go b/go/beacon_srv/internal/onehop/sender.go index c3e4f315aa..b9f6a293ac 100644 --- a/go/beacon_srv/internal/onehop/sender.go +++ b/go/beacon_srv/internal/onehop/sender.go @@ -61,7 +61,7 @@ type Sender struct { // IA is the ISD-AS of the local AS. IA addr.IA // Addr is the address that is set as the source. - Addr *addr.AppAddr + Addr *net.UDPAddr // Conn is used to send the packets. Conn snet.PacketConn // macMtx protects the MAC. @@ -90,12 +90,12 @@ func (s *Sender) CreatePkt(msg *Msg) (*snet.SCIONPacket, error) { Destination: msg.Dst, Source: snet.SCIONAddress{ IA: s.IA, - Host: s.Addr.L3, + Host: addr.HostFromIP(s.Addr.IP), }, Path: (*spath.Path)(path), Extensions: []common.Extension{&layers.ExtnOHP{}}, L4Header: &l4.UDP{ - SrcPort: s.Addr.L4, + SrcPort: uint16(s.Addr.Port), }, Payload: msg.Pld, }, diff --git a/go/beacon_srv/internal/onehop/sender_test.go b/go/beacon_srv/internal/onehop/sender_test.go index ac7576f27c..73818434b1 100644 --- a/go/beacon_srv/internal/onehop/sender_test.go +++ b/go/beacon_srv/internal/onehop/sender_test.go @@ -81,9 +81,9 @@ func TestSenderCreatePkt(t *testing.T) { Convey("CreatePkt creates a correct packet", t, func() { s := &Sender{ IA: xtest.MustParseIA("1-ff00:0:110"), - Addr: &addr.AppAddr{ - L3: addr.HostFromIPStr("127.0.0.1"), - L4: 4242, + Addr: &net.UDPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 4242, }, MAC: createMac(t), } @@ -102,9 +102,9 @@ func TestSenderSend(t *testing.T) { s := &Sender{ IA: xtest.MustParseIA("1-ff00:0:110"), Conn: conn, - Addr: &addr.AppAddr{ - L3: addr.HostFromIPStr("127.0.0.1"), - L4: 4242, + Addr: &net.UDPAddr{ + IP: net.ParseIP("127.0.0.1"), + Port: 4242, }, MAC: createMac(t), } diff --git a/go/beacon_srv/main.go b/go/beacon_srv/main.go index 47fd7fd786..17a6b9a847 100644 --- a/go/beacon_srv/main.go +++ b/go/beacon_srv/main.go @@ -20,6 +20,7 @@ import ( "flag" "fmt" "hash" + "net" "os" "path/filepath" "sync" @@ -294,6 +295,11 @@ func (t *periodicTasks) Start() error { if topoAddress == nil { return serrors.New("Unable to find topo address") } + bs := &net.UDPAddr{ + IP: topoAddress.L3.IP(), + Port: int(topoAddress.L4), + } + var err error if t.registrars, err = t.startSegRegRunners(); err != nil { return err @@ -301,13 +307,13 @@ func (t *periodicTasks) Start() error { if t.revoker, err = t.startRevoker(); err != nil { return err } - if t.keepalive, err = t.startKeepaliveSender(topoAddress); err != nil { + if t.keepalive, err = t.startKeepaliveSender(bs); err != nil { return err } - if t.originator, err = t.startOriginator(topoAddress); err != nil { + if t.originator, err = t.startOriginator(bs); err != nil { return err } - if t.propagator, err = t.startPropagator(topoAddress); err != nil { + if t.propagator, err = t.startPropagator(bs); err != nil { return err } @@ -341,7 +347,7 @@ func (t *periodicTasks) startRevoker() (*periodic.Runner, error) { cfg.BS.ExpiredCheckInterval.Duration), nil } -func (t *periodicTasks) startKeepaliveSender(a *addr.AppAddr) (*periodic.Runner, error) { +func (t *periodicTasks) startKeepaliveSender(a *net.UDPAddr) (*periodic.Runner, error) { s := &keepalive.Sender{ Sender: &onehop.Sender{ Conn: t.conn, @@ -356,7 +362,7 @@ func (t *periodicTasks) startKeepaliveSender(a *addr.AppAddr) (*periodic.Runner, cfg.BS.KeepaliveInterval.Duration), nil } -func (t *periodicTasks) startOriginator(a *addr.AppAddr) (*periodic.Runner, error) { +func (t *periodicTasks) startOriginator(a *net.UDPAddr) (*periodic.Runner, error) { topo := t.topoProvider.Get() if !topo.Core() { return nil, nil @@ -392,7 +398,7 @@ func (t *periodicTasks) startOriginator(a *addr.AppAddr) (*periodic.Runner, erro cfg.BS.OriginationInterval.Duration), nil } -func (t *periodicTasks) startPropagator(a *addr.AppAddr) (*periodic.Runner, error) { +func (t *periodicTasks) startPropagator(a *net.UDPAddr) (*periodic.Runner, error) { topo := t.topoProvider.Get() signer, err := t.createSigner(topo.IA()) if err != nil { diff --git a/go/examples/discovery_client/BUILD.bazel b/go/examples/discovery_client/BUILD.bazel index 2b9bf31cde..b4ada34b41 100644 --- a/go/examples/discovery_client/BUILD.bazel +++ b/go/examples/discovery_client/BUILD.bazel @@ -7,7 +7,6 @@ go_library( importpath = "github.com/scionproto/scion/go/examples/discovery_client", visibility = ["//visibility:private"], deps = [ - "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", "//go/lib/discovery:go_default_library", "//go/lib/discovery/topofetcher:go_default_library", diff --git a/go/examples/discovery_client/client.go b/go/examples/discovery_client/client.go index 4f8c5cc9a8..5c9318e58c 100644 --- a/go/examples/discovery_client/client.go +++ b/go/examples/discovery_client/client.go @@ -20,12 +20,11 @@ import ( "fmt" "io/ioutil" "net" + "net/url" "os" - "strconv" "sync" "time" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/discovery" "github.com/scionproto/scion/go/lib/discovery/topofetcher" @@ -45,8 +44,6 @@ var ( timeout = flag.Duration("timeout", 2*time.Second, "Timeout for single request") ds = flag.String("addr", "", "Discovery service to query for initial topology "+ "(form \"host:port\" or \"[host]:port\"") - // FIXME(roosd): Use AppAddr parsing once code base does no longer assume L4 is UDP. - dsAddr addr.AppAddr ) func main() { @@ -118,19 +115,8 @@ func validateFlags() error { if *ds != "" && *topoPath != "" { return serrors.New("Both topology and discovery service address specified") } - if *ds != "" { - host, port, err := net.SplitHostPort(*ds) - if err != nil { - return common.NewBasicError("Unable to parse discovery service address", err) - } - if dsAddr.L3 = addr.HostFromIPStr(host); dsAddr.L3 == nil { - return common.NewBasicError("Unable to parse host", nil, "host", host) - } - p, err := strconv.Atoi(port) - if err != nil { - return common.NewBasicError("Unable to parse port", nil, "port", port) - } - dsAddr.L4 = uint16(p) + if _, err := url.Parse(*ds); err != nil { + return err } return nil } @@ -140,11 +126,19 @@ func getTopo() (*topology.Topo, error) { log.Info("Fetch initial topology from discovery service", "addr", ds) ctx, cancelF := context.WithTimeout(context.Background(), *timeout) defer cancelF() - return discovery.FetchTopo(ctx, discovery.FetchParams{ + + a, err := net.ResolveUDPAddr("udp", *ds) + if err != nil { + return nil, err + } + + ret, _, err := discovery.FetchTopoRaw(ctx, discovery.FetchParams{ File: file(), Mode: mode(), Https: *https, - }, &dsAddr, nil) + }, a, + nil) + return ret, err } log.Info("Load initial topology from disk", "topo", topoPath) return topology.LoadFromFile(*topoPath) diff --git a/go/lib/discovery/BUILD.bazel b/go/lib/discovery/BUILD.bazel index 9fa8db7205..8e782ec5df 100644 --- a/go/lib/discovery/BUILD.bazel +++ b/go/lib/discovery/BUILD.bazel @@ -9,7 +9,6 @@ go_library( importpath = "github.com/scionproto/scion/go/lib/discovery", visibility = ["//visibility:public"], deps = [ - "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", "//go/lib/periodic:go_default_library", "//go/lib/serrors:go_default_library", diff --git a/go/lib/discovery/common.go b/go/lib/discovery/common.go index 5e694ac976..f981e93106 100644 --- a/go/lib/discovery/common.go +++ b/go/lib/discovery/common.go @@ -16,8 +16,8 @@ package discovery import ( "fmt" + "net" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/periodic" "github.com/scionproto/scion/go/lib/topology" ) @@ -35,11 +35,11 @@ type InstancePool interface { type InstanceInfo interface { fmt.Stringer // Update updates the address. - Update(*addr.AppAddr) + Update(*net.UDPAddr) // Key returns the key of the instance. Key() string // Addr returns the address of the instance. - Addr() *addr.AppAddr + Addr() *net.UDPAddr // FailCount returns a number indicating how often // the instance has failed. FailCount() int diff --git a/go/lib/discovery/discovery.go b/go/lib/discovery/discovery.go index a8a363a5ec..985d7f401b 100644 --- a/go/lib/discovery/discovery.go +++ b/go/lib/discovery/discovery.go @@ -66,11 +66,11 @@ import ( "context" "fmt" "io/ioutil" + "net" "net/http" "golang.org/x/net/context/ctxhttp" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/topology" @@ -115,19 +115,10 @@ const ( Base = "discovery/v1" ) -// FetchTopo fetches the topology with the specified parameters from the -// discovery service. If client is nil, the default http client is used. -func FetchTopo(ctx context.Context, params FetchParams, ds *addr.AppAddr, - client *http.Client) (*topology.Topo, error) { - - topo, _, err := FetchTopoRaw(ctx, params, ds, client) - return topo, err -} - // FetchTopoRaw fetches the topology with the specified parameters from the // discovery service. If client is nil, the default http client is used. // Both the topology and the raw response body are returned. -func FetchTopoRaw(ctx context.Context, params FetchParams, ds *addr.AppAddr, +func FetchTopoRaw(ctx context.Context, params FetchParams, ds *net.UDPAddr, client *http.Client) (*topology.Topo, common.RawBytes, error) { url, err := createURL(params, ds) @@ -154,7 +145,7 @@ func FetchTopoRaw(ctx context.Context, params FetchParams, ds *addr.AppAddr, } // createURL builds the url to the topology file. -func createURL(params FetchParams, ds *addr.AppAddr) (string, error) { +func createURL(params FetchParams, ds *net.UDPAddr) (string, error) { if ds == nil { return "", serrors.New("Addr not set") } @@ -162,7 +153,7 @@ func createURL(params FetchParams, ds *addr.AppAddr) (string, error) { if params.Https { protocol = "https" } - return fmt.Sprintf("%s://%s:%d/%s", protocol, ds.L3.IP(), ds.L4, + return fmt.Sprintf("%s://%s:%d/%s", protocol, ds.IP, ds.Port, Path(params.Mode, params.File)), nil } diff --git a/go/lib/discovery/discoveryinfo/BUILD.bazel b/go/lib/discovery/discoveryinfo/BUILD.bazel index e6580f2273..111ae55bbc 100644 --- a/go/lib/discovery/discoveryinfo/BUILD.bazel +++ b/go/lib/discovery/discoveryinfo/BUILD.bazel @@ -1,12 +1,16 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = ["info.go"], importpath = "github.com/scionproto/scion/go/lib/discovery/discoveryinfo", visibility = ["//visibility:public"], - deps = [ - "//go/lib/addr:go_default_library", - "//go/lib/discovery:go_default_library", - ], + deps = ["//go/lib/discovery:go_default_library"], +) + +go_test( + name = "go_default_test", + srcs = ["info_test.go"], + embed = [":go_default_library"], + deps = ["@com_github_stretchr_testify//assert:go_default_library"], ) diff --git a/go/lib/discovery/discoveryinfo/info.go b/go/lib/discovery/discoveryinfo/info.go index aee7f6a1e2..c2f5105522 100644 --- a/go/lib/discovery/discoveryinfo/info.go +++ b/go/lib/discovery/discoveryinfo/info.go @@ -17,10 +17,10 @@ package discoveryinfo import ( "fmt" "math" + "net" "sync" "time" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/discovery" ) @@ -36,7 +36,7 @@ var _ discovery.InstanceInfo = (*Info)(nil) // Info keeps track of the discovery service and its health. type Info struct { mu sync.Mutex - addr *addr.AppAddr + addr *net.UDPAddr key string lastFail time.Time lastExp time.Time @@ -44,7 +44,7 @@ type Info struct { } // New creates a new info with the specified key and address. -func New(key string, addr *addr.AppAddr) *Info { +func New(key string, addr *net.UDPAddr) *Info { return &Info{ addr: addr, key: key, @@ -54,11 +54,12 @@ func New(key string, addr *addr.AppAddr) *Info { } // Update updates the address. If changed, the fail count is reset. -func (h *Info) Update(a *addr.AppAddr) { +func (h *Info) Update(a *net.UDPAddr) { h.mu.Lock() defer h.mu.Unlock() - if !a.Equal(h.addr) { - h.addr = a.Copy() + if !h.addr.IP.Equal(a.IP) || h.addr.Port != a.Port { + h.addr.IP = append(h.addr.IP[:0:0], a.IP...) + h.addr.Port = a.Port h.failCount = 0 h.lastFail = time.Now() h.lastExp = time.Now() @@ -71,10 +72,13 @@ func (h *Info) Key() string { } // Addr returns the address of the discovery service instance. -func (h *Info) Addr() *addr.AppAddr { +func (h *Info) Addr() *net.UDPAddr { h.mu.Lock() defer h.mu.Unlock() - return h.addr.Copy() + ret := &net.UDPAddr{} + ret.IP = append(h.addr.IP[:0:0], h.addr.IP...) + ret.Port = h.addr.Port + return ret } // FailCount returns the fail count. diff --git a/go/lib/discovery/discoveryinfo/info_test.go b/go/lib/discovery/discoveryinfo/info_test.go new file mode 100644 index 0000000000..0a6a0b13d7 --- /dev/null +++ b/go/lib/discovery/discoveryinfo/info_test.go @@ -0,0 +1,96 @@ +package discoveryinfo + +import ( + "net" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNew(t *testing.T) { + cases := map[string]struct { + key string + addr *net.UDPAddr + }{ + "empty address": {key: "x", addr: &net.UDPAddr{}}, + } + + for n, tc := range cases { + t.Run(n, func(t *testing.T) { + got := New(tc.key, tc.addr) + assert.NotNil(t, got) + }) + } +} + +func TestUpdate(t *testing.T) { + cases := map[string]struct { + before, after *Info + input *net.UDPAddr + }{ + "nil addr": { + before: &Info{ + addr: &net.UDPAddr{}, + failCount: 10, + }, + input: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + after: &Info{ + addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + failCount: 0, + }, + }, + "not nil addr": { + before: &Info{ + addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.10"), Port: 1234}, + failCount: 10, + }, + input: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + after: &Info{ + addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + failCount: 0, + }, + }, + "same addr": { + before: &Info{ + addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + failCount: 10, + }, + input: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + after: &Info{ + addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + failCount: 10, + }, + }, + } + + for n, tc := range cases { + t.Run(n, func(t *testing.T) { + tc.before.Update(tc.input) + tc.input.IP[0] = 42 // other part of the code modifies the input reference. + assert.Equal(t, tc.before.addr, tc.after.addr) + assert.Equal(t, tc.before.failCount, tc.after.failCount) + }) + } +} + +func TestAddr(t *testing.T) { + cases := map[string]struct { + before *Info + want *net.UDPAddr + }{ + "addr": { + before: &Info{ + addr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + }, + want: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, + }, + } + + for n, tc := range cases { + t.Run(n, func(t *testing.T) { + got := tc.before.Addr() + tc.before.addr.IP[0] = 42 // other part of the code modifies the IP reference. + assert.Equal(t, got, tc.want) + }) + } +} diff --git a/go/lib/discovery/discoverypool/pool.go b/go/lib/discovery/discoverypool/pool.go index 5d7d99ad00..e231e1292b 100644 --- a/go/lib/discovery/discoverypool/pool.go +++ b/go/lib/discovery/discoverypool/pool.go @@ -16,6 +16,7 @@ package discoverypool import ( "math" + "net" "sync" "github.com/scionproto/scion/go/lib/common" @@ -53,10 +54,15 @@ func (p *Pool) Update(svcInfo topology.IDAddrMap) error { defer p.mu.Unlock() // Add missing DS servers. for k, v := range svcInfo { + x := v.PublicAddr(v.Overlay) + y := &net.UDPAddr{ + IP: x.L3.IP(), + Port: int(x.L4), + } if info, ok := p.m[k]; !ok { - p.m[k] = discoveryinfo.New(k, v.PublicAddr(v.Overlay)) + p.m[k] = discoveryinfo.New(k, y) } else { - info.Update(v.PublicAddr(v.Overlay)) + info.Update(y) } } // Get list of outdated DS servers. diff --git a/go/lib/discovery/discoverypool/pool_test.go b/go/lib/discovery/discoverypool/pool_test.go index 6e134fb165..b9eaaee51c 100644 --- a/go/lib/discovery/discoverypool/pool_test.go +++ b/go/lib/discovery/discoverypool/pool_test.go @@ -28,17 +28,19 @@ import ( type testInfo struct { key string - addr *addr.AppAddr + addr *net.UDPAddr } var ds = []testInfo{ - {"ds1-ff00_0_111-1", &addr.AppAddr{ - L3: addr.HostFromIP(net.IPv4(127, 0, 0, 22)), - L4: 30084}, + {"ds1-ff00_0_111-1", &net.UDPAddr{ + IP: net.IPv4(127, 0, 0, 22), + Port: 30084, + }, + }, + {"ds1-ff00_0_111-2", &net.UDPAddr{ + IP: net.IPv4(127, 0, 0, 80), + Port: 30085, }, - {"ds1-ff00_0_111-2", &addr.AppAddr{ - L3: addr.HostFromIP(net.IPv4(127, 0, 0, 80)), - L4: 30085}, }, } @@ -46,8 +48,8 @@ func contains(pool *Pool, v testInfo) { Convey("The pool contains "+v.key, func() { info, ok := pool.m[v.key] SoMsg("Not found", ok, ShouldBeTrue) - SoMsg("Ip", info.Addr().L3.IP(), ShouldResemble, v.addr.L3.IP()) - SoMsg("Port", info.Addr().L4, ShouldEqual, v.addr.L4) + SoMsg("Ip", info.Addr().IP.Equal(v.addr.IP), ShouldBeTrue) + SoMsg("Port", info.Addr().Port, ShouldEqual, v.addr.Port) }) } @@ -85,9 +87,9 @@ func TestPoolUpdate(t *testing.T) { Convey("The pool should contain the updated info", func() { contains(pool, testInfo{ key: ds[0].key, - addr: &addr.AppAddr{ - L3: addr.HostFromIP(net.IPv4(127, 0, 0, 21)), - L4: svcInfo[ds[0].key].IPv4.PublicAddr().L4, + addr: &net.UDPAddr{ + IP: net.IPv4(127, 0, 0, 21), + Port: int(svcInfo[ds[0].key].IPv4.PublicAddr().L4), }, }) }) @@ -101,9 +103,9 @@ func TestPoolUpdate(t *testing.T) { } contains(pool, testInfo{ key: "ds-new", - addr: &addr.AppAddr{ - L3: addr.HostFromIP(net.IPv4(127, 0, 0, 22)), - L4: 30084}, + addr: &net.UDPAddr{ + IP: net.IPv4(127, 0, 0, 22), + Port: 30084}, }) }) })