Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

topology: replace SCIONAddress to net.UDPAddr os #3507

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/beacon_srv/internal/ifstate/pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestPusherPush(t *testing.T) {
for _, br := range topoProvider.Get().BRNames() {
a := topoProvider.Get().SBRAddress(br)
msgr.EXPECT().SendIfStateInfos(gomock.Any(), gomock.Eq(expectedMsg),
gomock.Eq(a.ToXAddr()), gomock.Any())
gomock.Eq(a), gomock.Any())
}
}
p.Push(context.Background(), 101)
Expand Down
2 changes: 1 addition & 1 deletion go/beacon_srv/internal/ifstate/revoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (p *brPusher) sendIfStateToAllBRs(ctx context.Context, msg *path_mgmt.IFSta

for _, br := range topo.BRNames() {
t := topo.SBRAddress(br)
p.sendIfStateToBr(ctx, msg, br, t.ToXAddr(), wg)
p.sendIfStateToBr(ctx, msg, br, t, wg)
}
}

Expand Down
4 changes: 2 additions & 2 deletions go/beacon_srv/internal/ifstate/revoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ func checkInterfaces(intfs *Interfaces, nonActive map[common.IFIDType]State) {
func brId(t *testing.T, topoProvider topology.Provider, saddr *snet.UDPAddr) string {
topo := topoProvider.Get()
for _, brID := range topo.BRNames() {
leg := topo.SBRAddress(brID)
if leg.Host.L3.String() == saddr.Host.IP.String() && leg.IA == saddr.IA {
a := topo.SBRAddress(brID)
if a.Host.IP.Equal(saddr.Host.IP) && a.IA == saddr.IA {
return brID
}
}
Expand Down
6 changes: 4 additions & 2 deletions go/beacon_srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ func realMain() int {
}
// We do not need to drain the connection, since the src address is spoofed
// to contain the topo address.
ohpAddress := topo.PublicAddress(addr.SvcBS, cfg.General.ID)
ohpAddress.Port = 0
a := topo.PublicAddress(addr.SvcBS, cfg.General.ID)
ohpAddress := &net.UDPAddr{
IP: append(a.IP[:0:0], a.IP...), Port: 0,
}
conn, _, err := pktDisp.RegisterTimeout(topo.IA(), ohpAddress, nil,
addr.SvcNone, time.Second)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go/border/rctrl/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func Control(sRevInfoQ chan rpkt.RawSRevCallbackArgs, dispatcherReconnect bool)
},
)
ctrlAddr := ctx.Conf.BR.CtrlAddrs
pub := &snet.Addr{IA: ia, Host: ctrlAddr.SCIONAddress}
snetConn, err = scionNetwork.ListenSCIONWithBindSVC("udp4", pub, nil, addr.SvcNone, 0)
pub := snet.NewUDPAddr(ia, nil, nil, ctrlAddr.SCIONAddress)
snetConn, err = scionNetwork.ListenSCIONWithBindSVC("udp4", pub.ToAddr(), nil, addr.SvcNone, 0)
if err != nil {
fatal.Fatal(common.NewBasicError("Listening on address", err, "addr", ctrlAddr))
}
Expand Down
1 change: 0 additions & 1 deletion go/lib/discovery/discoverypool/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ go_test(
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/topology:go_default_library",
"//go/lib/xtest:go_default_library",
"@com_github_smartystreets_goconvey//convey:go_default_library",
Expand Down
9 changes: 2 additions & 7 deletions go/lib/discovery/discoverypool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package discoverypool

import (
"math"
"net"
"sync"

"github.com/scionproto/scion/go/lib/common"
Expand Down Expand Up @@ -54,14 +53,10 @@ func (p *Pool) Update(svcInfo topology.IDAddrMap) error {
defer p.mu.Unlock()
// Add missing DS servers.
for k, v := range svcInfo {
y := &net.UDPAddr{
IP: v.SCIONAddress.L3.IP(),
Port: int(v.SCIONAddress.L4),
}
if info, ok := p.m[k]; !ok {
p.m[k] = discoveryinfo.New(k, y)
p.m[k] = discoveryinfo.New(k, v.SCIONAddress)
} else {
info.Update(y)
info.Update(v.SCIONAddress)
}
}
// Get list of outdated DS servers.
Expand Down
6 changes: 2 additions & 4 deletions go/lib/discovery/discoverypool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/topology"
"github.com/scionproto/scion/go/lib/xtest"
)
Expand Down Expand Up @@ -80,15 +79,14 @@ func TestPoolUpdate(t *testing.T) {
pool := mustLoadPool(t)
svcInfo := mustLoadSvcInfo(t)
Convey("And a topology containing an updated discovery service entry", func() {
svcInfo[ds[0].key].SCIONAddress.L3 = addr.HostFromIP(
net.IPv4(127, 0, 0, 21))
svcInfo[ds[0].key].SCIONAddress.IP = net.IPv4(127, 0, 0, 21)
pool.Update(svcInfo)
Convey("The pool should contain the updated info", func() {
contains(pool, testInfo{
key: ds[0].key,
addr: &net.UDPAddr{
IP: net.IPv4(127, 0, 0, 21),
Port: int(svcInfo[ds[0].key].SCIONAddress.L4),
Port: svcInfo[ds[0].key].SCIONAddress.Port,
},
})
})
Expand Down
2 changes: 0 additions & 2 deletions go/lib/healthpool/svcinstance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ go_library(
importpath = "github.com/scionproto/scion/go/lib/healthpool/svcinstance",
visibility = ["//visibility:public"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/healthpool:go_default_library",
"//go/lib/topology:go_default_library",
],
Expand All @@ -21,7 +20,6 @@ go_test(
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/healthpool:go_default_library",
"//go/lib/topology:go_default_library",
"//go/lib/xtest:go_default_library",
Expand Down
18 changes: 11 additions & 7 deletions go/lib/healthpool/svcinstance/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package svcinstance

import (
"net"
"sync"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/healthpool"
)

Expand All @@ -33,7 +33,7 @@ func (i Info) Fail() {
}

// Addr returns the service instance address.
func (i Info) Addr() *addr.AppAddr {
func (i Info) Addr() *net.UDPAddr {
return i.info.addrCopy()
}

Expand All @@ -45,20 +45,24 @@ func (i Info) Name() string {
type info struct {
healthpool.Info
mtx sync.RWMutex
addr *addr.AppAddr
addr *net.UDPAddr
name string
}

func (i *info) addrCopy() *addr.AppAddr {
func (i *info) addrCopy() *net.UDPAddr {
i.mtx.RLock()
defer i.mtx.RUnlock()
return i.addr.Copy()
return &net.UDPAddr{
IP: append(i.addr.IP[:0:0], i.addr.IP...),
Port: i.addr.Port,
}

}

func (i *info) update(a *addr.AppAddr) {
func (i *info) update(a *net.UDPAddr) {
i.mtx.Lock()
defer i.mtx.Unlock()
if !a.Equal(i.addr) {
if !a.IP.Equal(i.addr.IP) || a.Port != i.addr.Port {
i.addr = a
i.ResetCount()
}
Expand Down
31 changes: 15 additions & 16 deletions go/lib/healthpool/svcinstance/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/healthpool"
"github.com/scionproto/scion/go/lib/topology"
"github.com/scionproto/scion/go/lib/xtest"
Expand All @@ -33,22 +32,22 @@ const (
ds3new = "ds1-ff00_0_111-3-new"
)

var dsInfos = map[string]*addr.AppAddr{
var dsInfos = map[string]*net.UDPAddr{
ds1: {
L3: addr.HostFromIP(net.IPv4(127, 0, 0, 22)),
L4: 30084,
IP: net.IPv4(127, 0, 0, 22),
Port: 30084,
},
ds2: {
L3: addr.HostFromIP(net.IPv4(127, 0, 0, 80)),
L4: 30085,
IP: net.IPv4(127, 0, 0, 80),
Port: 30085,
},
ds3new: {
L3: addr.HostFromIP(net.IPv4(127, 0, 0, 22)),
L4: 30084,
IP: net.IPv4(127, 0, 0, 22),
Port: 30084,
},
ds1updated: {
L3: addr.HostFromIP(net.IPv4(127, 0, 0, 21)),
L4: 30084,
IP: net.IPv4(127, 0, 0, 21),
Port: 30084,
},
}

Expand All @@ -73,7 +72,7 @@ func TestPoolUpdate(t *testing.T) {
pool := mustLoadPool(t)
svcInfo := mustLoadSvcInfo(t)
Convey("And an instance map containing an updated discovery service entry", func() {
svcInfo[ds1].SCIONAddress.L3 = dsInfos[ds1updated].L3
svcInfo[ds1].SCIONAddress.IP = dsInfos[ds1updated].IP
pool.infos[ds1].Fail()
err := pool.Update(svcInfo)
SoMsg("err", err, ShouldBeNil)
Expand Down Expand Up @@ -118,13 +117,13 @@ func TestPoolChoose(t *testing.T) {
p.infos[ds1].Fail()
i, err := p.Choose()
SoMsg("err first", err, ShouldBeNil)
SoMsg("Choose first", i.Addr().Equal(p.infos[ds2].addr), ShouldBeTrue)
SoMsg("Choose first", i.Addr().IP.Equal(p.infos[ds2].addr.IP), ShouldBeTrue)
SoMsg("Name first", i.Name(), ShouldEqual, ds2)
i.Fail()
i.Fail()
i, err = p.Choose()
SoMsg("err second", err, ShouldBeNil)
SoMsg("Choose second", i.Addr().Equal(p.infos[ds1].addr), ShouldBeTrue)
SoMsg("Choose second", i.Addr().IP.Equal(p.infos[ds1].addr.IP), ShouldBeTrue)
SoMsg("Name second", i.Name(), ShouldEqual, ds1)
})
}
Expand All @@ -146,12 +145,12 @@ func containsAll(p *Pool, names ...string) {
}
}

func contains(p *Pool, name string, a *addr.AppAddr) {
func contains(p *Pool, name string, a *net.UDPAddr) {
Convey("The pool contains "+name, func() {
info, ok := p.infos[name]
SoMsg("Not found", ok, ShouldBeTrue)
SoMsg("Ip", info.addr.L3.IP(), ShouldResemble, a.L3.IP())
SoMsg("Port", info.addr.L4, ShouldEqual, a.L4)
SoMsg("Ip", info.addr.IP.String(), ShouldResemble, a.IP.String())
SoMsg("Port", info.addr.Port, ShouldEqual, a.Port)
})
}

Expand Down
2 changes: 1 addition & 1 deletion go/lib/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ var DispAddr HostAddr = func(ia addr.IA) snet.Addr {
os.Exit(1)
}
bs := topo.BS["bs"+ia.FileFmt(false)+"-1"]
return snet.Addr{Host: bs.SCIONAddress, IA: ia}
return snet.Addr{Host: addr.AppAddrFromUDP(bs.SCIONAddress), IA: ia}
}

// interface kept similar to go 1.10
Expand Down
35 changes: 6 additions & 29 deletions go/lib/topology/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Topology interface {
Exists(svc addr.HostSVC, name string) bool

// SBRAddress returns the internal public address of the BR with the specified name.
SBRAddress(name string) *snet.Addr
SBRAddress(name string) *snet.UDPAddr

// OverlayAnycast returns the overlay address for an arbitrary server of the requested type.
OverlayAnycast(svc addr.HostSVC) (*net.UDPAddr, error)
Expand Down Expand Up @@ -200,17 +200,8 @@ func (t *topologyS) MakeHostInfos(st proto.ServiceType) []net.UDPAddr {
return hostInfos
}
for _, a := range addresses {
if v4Addr := a.SCIONAddress; v4Addr != nil {
hostInfos = append(hostInfos, net.UDPAddr{
IP: copyIP(v4Addr.L3.IP()),
Port: int(v4Addr.L4),
})
}
if v6Addr := a.SCIONAddress; v6Addr != nil {
hostInfos = append(hostInfos, net.UDPAddr{
IP: copyIP(v6Addr.L3.IP()),
Port: int(v6Addr.L4),
})
if tmp := a.SCIONAddress; tmp != nil {
hostInfos = append(hostInfos, *tmp)
}
}
return hostInfos
Expand All @@ -230,17 +221,7 @@ func (t *topologyS) PublicAddress(svc addr.HostSVC, name string) *net.UDPAddr {
if topoAddr == nil {
return nil
}
if topoAddr.SCIONAddress == nil {
return nil
}
// FIXME(scrye): The interface this type implements offers read-only access. The copy below
// shouldn't be needed, but this can cause tricky to find bugs. We should tackle removing
// the copy in a separate PR.
ip := topoAddr.SCIONAddress.L3.IP()
return &net.UDPAddr{
IP: append(ip[:0:0], ip...),
Port: int(topoAddr.SCIONAddress.L4),
}
return topoAddr.SCIONAddress
}

func (t *topologyS) Exists(svc addr.HostSVC, name string) bool {
Expand Down Expand Up @@ -371,16 +352,12 @@ func (t *topologyS) BRNames() []string {
return t.Topology.BRNames
}

func (t *topologyS) SBRAddress(name string) *snet.Addr {
func (t *topologyS) SBRAddress(name string) *snet.UDPAddr {
br, ok := t.Topology.BR[name]
if !ok {
return nil
}
return &snet.Addr{
IA: t.IA(),
Host: br.CtrlAddrs.SCIONAddress,
NextHop: br.CtrlAddrs.UnderlayAddr(),
}
return snet.NewUDPAddr(t.IA(), nil, br.CtrlAddrs.UnderlayAddr(), br.CtrlAddrs.SCIONAddress)
}

func (t *topologyS) SVCNames(svc addr.HostSVC) ServiceNames {
Expand Down
4 changes: 2 additions & 2 deletions go/lib/topology/mock_topology/topology.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions go/lib/topology/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func rawAddrMapToTopoAddr(ram jsontopo.NATSCIONAddressMap) (*TopoAddr, error) {
}

return &TopoAddr{
SCIONAddress: &addr.AppAddr{
L3: addr.HostFromIP(ip),
L4: uint16(addressInfo.Public.Address.L4Port),
SCIONAddress: &net.UDPAddr{
IP: ip,
Port: addressInfo.Public.Address.L4Port,
},
UnderlayAddress: &net.UDPAddr{
IP: append(ip[:0:0], ip...),
Expand Down
16 changes: 15 additions & 1 deletion go/lib/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type (
// TopoAddr wraps the possible addresses of a SCION service and describes
// the underlay to be used for contacting said service.
TopoAddr struct {
SCIONAddress *addr.AppAddr
SCIONAddress *net.UDPAddr
UnderlayAddress net.Addr
}
)
Expand Down Expand Up @@ -429,6 +429,20 @@ func (a *TopoAddr) String() string {
return fmt.Sprintf("TopoAddr{SCION: %v, Underlay: %v}", a.SCIONAddress, a.UnderlayAddress)
}

func (a *TopoAddr) copy() *TopoAddr {
// TODO(scrye): Investigate how this can be removed.
if a == nil {
return nil
}
return &TopoAddr{
SCIONAddress: &net.UDPAddr{
IP: append(a.SCIONAddress.IP[:0:0], a.SCIONAddress.IP...),
Port: a.SCIONAddress.Port,
},
UnderlayAddress: toUDPAddr(a.UnderlayAddress.(*net.UDPAddr)),
}
}

func toUDPAddr(a net.Addr) *net.UDPAddr {
if a == nil {
return nil
Expand Down
Loading