Skip to content

Commit

Permalink
Remove snet.Addr
Browse files Browse the repository at this point in the history
Remove snet.Addr, and constructors for snet.SVCAddr and snet.UDPAddr, instead use the struct directly.
  • Loading branch information
lukedirtwalker committed Jan 29, 2020
1 parent 299a765 commit 018f483
Show file tree
Hide file tree
Showing 47 changed files with 408 additions and 498 deletions.
2 changes: 1 addition & 1 deletion go/acceptance/sigcmn.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
)

var SigAddr integration.HostAddr = func(ia addr.IA) *snet.UDPAddr {
return snet.NewUDPAddr(ia, nil, nil, &net.UDPAddr{IP: net.IP(IAIPMap[ia])})
return &snet.UDPAddr{IA: ia, Host: &net.UDPAddr{IP: net.IP(IAIPMap[ia])}}
}

func ReadTestingConf() error {
Expand Down
2 changes: 1 addition & 1 deletion go/border/rctrl/ifstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func genIFStateReq() error {

var errors common.MultiError
for _, a := range bsAddrs {
dst := snet.NewSVCAddr(ia, nil, a, addr.SvcBS.Multicast())
dst := &snet.SVCAddr{IA: ia, NextHop: a, SVC: addr.SvcBS.Multicast()}
if _, err := snetConn.WriteTo(pld, dst); err != nil {
cl.Result = metrics.ErrWrite
metrics.Control.SentIFStateReq(cl).Inc()
Expand Down
2 changes: 1 addition & 1 deletion go/border/rctrl/revinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func fwdRevInfo(sRevInfo *path_mgmt.SignedRevInfo, dstHost addr.HostSVC) {
logger.Error("Writing RevInfo signed Ctrl payload", "err", err)
return
}
dst := snet.NewSVCAddr(ia, nil, nil, dstHost)
dst := &snet.SVCAddr{IA: ia, SVC: dstHost}
dst.NextHop, err = ctx.ResolveSVCAny(dstHost)
if err != nil {
cl.Result = metrics.ErrResolveSVC
Expand Down
8 changes: 6 additions & 2 deletions go/cs/beaconing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ func (h *handler) verifySegment(segment *seg.PathSegment) error {
if err != nil {
return common.NewBasicError("path error", err)
}
svcToQuery := snet.NewSVCAddr(snetPeer.IA, peerPath.Path(),
peerPath.OverlayNextHop(), addr.SvcBS)
svcToQuery := &snet.SVCAddr{
IA: snetPeer.IA,
Path: peerPath.Path(),
NextHop: peerPath.OverlayNextHop(),
SVC: addr.SvcBS,
}
return segverifier.VerifySegment(h.request.Context(), h.verifier, svcToQuery, segment)
}
10 changes: 5 additions & 5 deletions go/cs/beaconing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestNewHandler(t *testing.T) {
handler := NewHandler(localIA, intfs, inserter, verifier)
t.Run("Wrong payload type", func(t *testing.T) {
req := infra.NewRequest(context.Background(), &ctrl.Pld{}, nil,
snet.NewUDPAddr(addr.IA{}, testPath(localIF), nil, nil), 0)
&snet.UDPAddr{IA: addr.IA{}, Path: testPath(localIF)}, 0)
res := handler.Handle(req)
assert.Equal(t, res, infra.MetricsErrInternal)
})
Expand All @@ -114,14 +114,14 @@ func TestNewHandler(t *testing.T) {
t.Run("Invalid hop field", func(t *testing.T) {
req := infra.NewRequest(
infra.NewContextWithResponseWriter(context.Background(), rw),
pseg, nil, snet.NewUDPAddr(addr.IA{}, &spath.Path{}, nil, nil), 0)
pseg, nil, &snet.UDPAddr{IA: addr.IA{}, Path: &spath.Path{}}, 0)
res := handler.Handle(req)
assert.Equal(t, res, infra.MetricsErrInvalid)
})
t.Run("Invalid unknown interface", func(t *testing.T) {
req := infra.NewRequest(
infra.NewContextWithResponseWriter(context.Background(), rw),
pseg, nil, snet.NewUDPAddr(addr.IA{}, testPath(12), nil, nil), 0)
pseg, nil, &snet.UDPAddr{IA: addr.IA{}, Path: testPath(12)}, 0)
res := handler.Handle(req)
assert.Equal(t, res, infra.MetricsErrInvalid)
})
Expand All @@ -130,7 +130,7 @@ func TestNewHandler(t *testing.T) {
t.Run("Invalid link type", func(t *testing.T) {
req := infra.NewRequest(
infra.NewContextWithResponseWriter(context.Background(), rw),
pseg, nil, snet.NewUDPAddr(addr.IA{}, testPath(42), nil, nil), 0)
pseg, nil, &snet.UDPAddr{IA: addr.IA{}, Path: testPath(42)}, 0)
res := handler.Handle(req)
assert.Equal(t, res, infra.MetricsErrInvalid)
})
Expand Down Expand Up @@ -202,7 +202,7 @@ func defaultTestReq(rw infra.ResponseWriter, pseg *seg.PathSegment) *infra.Reque
infra.NewContextWithResponseWriter(context.Background(), rw),
pseg,
nil,
snet.NewUDPAddr(addr.IA{}, testPath(localIF), nil, nil),
&snet.UDPAddr{IA: addr.IA{}, Path: testPath(localIF)},
0,
)
}
Expand Down
2 changes: 1 addition & 1 deletion go/cs/beaconing/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (r *segmentRegistrar) onSuccess() {
func (r *segmentRegistrar) chooseServer(pseg *seg.PathSegment) (net.Addr, error) {
if r.segType != proto.PathSegType_down {
topo := r.topoProvider.Get()
return snet.NewSVCAddr(topo.IA(), nil, nil, addr.SvcPS), nil
return &snet.SVCAddr{IA: topo.IA(), SVC: addr.SvcPS}, nil
}
return addrutil.GetPath(addr.SvcPS, pseg, r.topoProvider)
}
8 changes: 6 additions & 2 deletions go/cs/handlers/segreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ func (h *segRegHandler) Handle() *infra.HandlerResult {
sendAck(proto.Ack_ErrCode_reject, messenger.AckRejectFailedToParse)
return infra.MetricsErrInvalid
}
svcToQuery := snet.NewSVCAddr(snetPeer.IA, peerPath.Path(),
peerPath.OverlayNextHop(), addr.SvcBS)
svcToQuery := &snet.SVCAddr{
IA: snetPeer.IA,
Path: peerPath.Path(),
NextHop: peerPath.OverlayNextHop(),
SVC: addr.SvcBS,
}
segs := seghandler.Segments{
Segs: segReg.Recs,
SRevInfos: segReg.SRevInfos,
Expand Down
8 changes: 6 additions & 2 deletions go/cs/handlers/segsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ func (h *syncHandler) Handle() *infra.HandlerResult {
metrics.Sync.Registrations(labels.WithResult(metrics.ErrParse)).Inc()
return infra.MetricsErrInvalid
}
svcToQuery := snet.NewSVCAddr(snetPeer.IA, peerPath.Path(),
peerPath.OverlayNextHop(), addr.SvcPS)
svcToQuery := &snet.SVCAddr{
IA: snetPeer.IA,
Path: peerPath.Path(),
NextHop: peerPath.OverlayNextHop(),
SVC: addr.SvcPS,
}

segs := seghandler.Segments{
Segs: segSync.Recs,
Expand Down
2 changes: 1 addition & 1 deletion go/cs/ifstate/revoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *Revoker) pushRevocationsToPS(ctx context.Context,
topo := r.cfg.TopoProvider.Get()
labels := metrics.SentLabels{Dst: metrics.DstPS}

a := snet.NewSVCAddr(topo.IA(), nil, nil, addr.SvcPS)
a := &snet.SVCAddr{IA: topo.IA(), SVC: addr.SvcPS}
for ifid, srev := range revs {
if err := r.cfg.Msgr.SendRev(ctx, srev, a, messenger.NextId()); err != nil {
log.FromCtx(ctx).Error("[ifstate.Revoker] Failed to send revocation to PS",
Expand Down
12 changes: 6 additions & 6 deletions go/cs/keepalive/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestNewHandler(t *testing.T) {
RevDropper: dropper,
})
req := infra.NewRequest(context.Background(), &ifid.IFID{OrigIfID: originIF}, nil,
snet.NewUDPAddr(originIA, testPath(localIF), nil, nil), 0)
&snet.UDPAddr{IA: originIA, Path: testPath(localIF)}, 0)
res := handler.Handle(req)
waitTimeout(t, wg)
assert.Equal(t, res, infra.MetricsResultOk)
Expand All @@ -91,7 +91,7 @@ func TestNewHandler(t *testing.T) {
intfs.Get(localIF).Activate(42)
handler := NewHandler(localIA, intfs, zeroCallTasks(mctrl))
req := infra.NewRequest(context.Background(), &ifid.IFID{OrigIfID: originIF}, nil,
snet.NewUDPAddr(originIA, testPath(localIF), nil, nil), 0)
&snet.UDPAddr{IA: originIA, Path: testPath(localIF)}, 0)
res := handler.Handle(req)
assert.Equal(t, res, infra.MetricsResultOk)
})
Expand All @@ -107,7 +107,7 @@ func TestNewHandler(t *testing.T) {
{
msg: "Wrong payload type",
req: infra.NewRequest(context.Background(), &ctrl.Pld{}, nil,
snet.NewUDPAddr(originIA, testPath(localIF), nil, nil), 0),
&snet.UDPAddr{IA: originIA, Path: testPath(localIF)}, 0),
exp: infra.MetricsErrInternal,
},
{
Expand All @@ -119,19 +119,19 @@ func TestNewHandler(t *testing.T) {
{
msg: "Invalid path",
req: infra.NewRequest(context.Background(), &ifid.IFID{OrigIfID: originIF}, nil,
snet.NewUDPAddr(originIA, &spath.Path{}, nil, nil), 0),
&snet.UDPAddr{IA: originIA, Path: &spath.Path{}}, 0),
exp: infra.MetricsErrInvalid,
},
{
msg: "Invalid ConsIngress ifid",
req: infra.NewRequest(context.Background(), &ifid.IFID{OrigIfID: originIF}, nil,
snet.NewUDPAddr(originIA, testPath(originIF), nil, nil), 0),
&snet.UDPAddr{IA: originIA, Path: testPath(originIF)}, 0),
exp: infra.MetricsErrInvalid,
},
{
msg: "Invalid IA",
req: infra.NewRequest(context.Background(), &ifid.IFID{OrigIfID: originIF}, nil,
snet.NewUDPAddr(localIA, testPath(localIF), nil, nil), 0),
&snet.UDPAddr{IA: localIA, Path: testPath(localIF)}, 0),
exp: infra.MetricsErrInvalid,
},
}
Expand Down
2 changes: 1 addition & 1 deletion go/cs/onehop/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (s *BeaconSender) attemptQUIC(ctx context.Context, ia addr.IA, path *spath.
return false, nil
}

t := snet.NewSVCAddr(ia, path, nextHop, addr.SvcBS)
t := &snet.SVCAddr{IA: ia, Path: path, NextHop: nextHop, SVC: addr.SvcBS}
newAddr, redirect, err := s.AddressRewriter.RedirectToQUIC(ctx, t)

if err != nil || !redirect {
Expand Down
7 changes: 6 additions & 1 deletion go/examples/pingpong/pingpong.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ func (c *client) run() {
// IP address needs to be supplied explicitly. When supplied a local
// port of 0, Dial will assign a random free local port.

remoteUDP := snet.NewUDPAddr(remote.IA, remote.Path, remote.NextHop, remote.Host)
remoteUDP := &snet.UDPAddr{
IA: remote.IA,
Path: remote.Path,
NextHop: remote.NextHop,
Host: remote.Host,
}
c.qsess, err = squic.Dial(network, local.Host, remoteUDP, addr.SvcNone, nil)
if err != nil {
LogFatal("Unable to dial", "err", err)
Expand Down
4 changes: 2 additions & 2 deletions go/hidden_path_srv/internal/hpcfgreq/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestCfgReq(t *testing.T) {
msg := &path_mgmt.HPCfgReq{
ChangedSince: 0,
}
peer := snet.NewUDPAddr(ia110, nil, nil, nil)
peer := &snet.UDPAddr{IA: ia110}
req := infra.NewRequest(ctx, msg, nil, peer, 0)
reply := &path_mgmt.HPCfgReply{
Cfgs: []*path_mgmt.HPCfg{group1.ToMsg(), group2.ToMsg(), group3.ToMsg()},
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCfgReq(t *testing.T) {
msg := &path_mgmt.HPCfgReq{
ChangedSince: 0,
}
peer := snet.NewUDPAddr(ia111, nil, nil, nil)
peer := &snet.UDPAddr{IA: ia111}
req := infra.NewRequest(ctx, msg, nil, peer, 0)
ack := ack.Ack{
Err: proto.Ack_ErrCode_reject,
Expand Down
2 changes: 1 addition & 1 deletion go/hidden_path_srv/internal/hpsegreq/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (f *DefaultFetcher) fetchRemote(ctx context.Context, ids []hiddenpath.Group
RawDstIA: endsAt.IAInt(),
GroupIds: rawIds,
}
addr := snet.NewSVCAddr(remote, nil, nil, addr.SvcHPS)
addr := &snet.SVCAddr{IA: remote, SVC: addr.SvcHPS}
reply, err := f.msger.GetHPSegs(ctx, req, addr, messenger.NextId())
if err != nil {
var recs = make([]*path_mgmt.HPSegRecs, 0, len(ids))
Expand Down
26 changes: 13 additions & 13 deletions go/hidden_path_srv/internal/hpsegreq/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group1.Id.ToMsg()},
},
peer: snet.NewUDPAddr(ia113, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia113},
res: []*path_mgmt.HPSegRecs{
{
GroupId: group1.Id.ToMsg(),
Expand All @@ -159,7 +159,7 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group2.Id.ToMsg()},
},
peer: snet.NewUDPAddr(ia113, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia113},
res: []*path_mgmt.HPSegRecs{
{
GroupId: group2.Id.ToMsg(),
Expand All @@ -179,7 +179,7 @@ func TestFetcher(t *testing.T) {
},
},
}
addr := snet.NewSVCAddr(ia115, nil, nil, addr.SvcHPS)
addr := &snet.SVCAddr{IA: ia115, SVC: addr.SvcHPS}
mockMsgr.EXPECT().GetHPSegs(gomock.Any(), gomock.Any(),
addr, gomock.Any()).Return(reply, nil)
},
Expand All @@ -189,7 +189,7 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group1.Id.ToMsg(), group2.Id.ToMsg()},
},
peer: snet.NewUDPAddr(ia113, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia113},
res: []*path_mgmt.HPSegRecs{
{
GroupId: group1.Id.ToMsg(),
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestFetcher(t *testing.T) {
},
},
}
addr := snet.NewSVCAddr(ia115, nil, nil, addr.SvcHPS)
addr := &snet.SVCAddr{IA: ia115, SVC: addr.SvcHPS}
mockDB.EXPECT().Get(gomock.Any(), gomock.Any()).Return(res, nil)
mockMsgr.EXPECT().GetHPSegs(gomock.Any(), gomock.Any(), addr,
gomock.Any()).Return(reply, nil)
Expand All @@ -229,7 +229,7 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group2.Id.ToMsg(), group3.Id.ToMsg()},
},
peer: snet.NewUDPAddr(ia113, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia113},
res: []*path_mgmt.HPSegRecs{
{
GroupId: group2.Id.ToMsg(),
Expand Down Expand Up @@ -265,10 +265,10 @@ func TestFetcher(t *testing.T) {
},
},
}
addr2 := snet.NewSVCAddr(ia115, nil, nil, addr.SvcHPS)
addr2 := &snet.SVCAddr{IA: ia115, SVC: addr.SvcHPS}
mockMsgr.EXPECT().GetHPSegs(gomock.Any(), gomock.Any(), addr2,
gomock.Any()).Return(reply2, nil)
addr3 := snet.NewSVCAddr(ia114, nil, nil, addr.SvcHPS)
addr3 := &snet.SVCAddr{IA: ia114, SVC: addr.SvcHPS}
mockMsgr.EXPECT().GetHPSegs(gomock.Any(), gomock.Any(), addr3,
gomock.Any()).Return(reply3, nil)
},
Expand All @@ -278,7 +278,7 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group1.Id.ToMsg()},
},
peer: snet.NewUDPAddr(ia113, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia113},
res: []*path_mgmt.HPSegRecs{
{
GroupId: group1.Id.ToMsg(),
Expand All @@ -294,15 +294,15 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group2.Id.ToMsg()},
},
peer: snet.NewUDPAddr(ia113, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia113},
res: []*path_mgmt.HPSegRecs{
{
GroupId: group2.Id.ToMsg(),
Err: "dummy",
},
},
setup: func(mockDB *mock_pathdb.MockPathDB, mockMsgr *mock_infra.MockMessenger) {
addr := snet.NewSVCAddr(ia115, nil, nil, addr.SvcHPS)
addr := &snet.SVCAddr{IA: ia115, SVC: addr.SvcHPS}
mockMsgr.EXPECT().GetHPSegs(gomock.Any(), gomock.Any(),
addr, gomock.Any()).Return(nil, errors.New("dummy"))
},
Expand All @@ -312,7 +312,7 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{wrongId.ToMsg()},
},
peer: snet.NewUDPAddr(ia114, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia114},
err: hpsegreq.ErrUnknownGroup,
setup: func(mockDB *mock_pathdb.MockPathDB, mockMsgr *mock_infra.MockMessenger) {},
},
Expand All @@ -321,7 +321,7 @@ func TestFetcher(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group1.Id.ToMsg()},
},
peer: snet.NewUDPAddr(ia114, nil, nil, nil),
peer: &snet.UDPAddr{IA: ia114},
err: hpsegreq.ErrNotReader,
setup: func(mockDB *mock_pathdb.MockPathDB, mockMsgr *mock_infra.MockMessenger) {},
},
Expand Down
4 changes: 2 additions & 2 deletions go/hidden_path_srv/internal/hpsegreq/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestSegReq(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group1.Id.ToMsg()},
}
peer := snet.NewUDPAddr(addr.IA{}, nil, nil, nil)
peer := &snet.UDPAddr{IA: addr.IA{}}
req := infra.NewRequest(ctx, msg, nil, peer, 0)
recs := []*path_mgmt.HPSegRecs{
{
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestSegReq(t *testing.T) {
RawDstIA: ia111.IAInt(),
GroupIds: []*path_mgmt.HPGroupId{group1.Id.ToMsg()},
}
peer := snet.NewUDPAddr(addr.IA{}, nil, nil, nil)
peer := &snet.UDPAddr{IA: addr.IA{}}
req := infra.NewRequest(ctx, msg, nil, peer, 0)
m.fetcher.EXPECT().Fetch(gomock.Any(), gomock.Any(),
gomock.Any()).Return(nil, errors.New("dummy"))
Expand Down
4 changes: 2 additions & 2 deletions go/hidden_path_srv/internal/registration/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestSegReg(t *testing.T) {
Recs: []*seg.Meta{seg110_133},
},
}
peer := snet.NewUDPAddr(addr.IA{}, nil, nil, nil)
peer := &snet.UDPAddr{IA: addr.IA{}}
req := infra.NewRequest(ctx, msg, nil, peer, 0)
ack := ack.Ack{
Err: proto.Ack_ErrCode_ok,
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestSegReg(t *testing.T) {
Recs: []*seg.Meta{seg110_133},
},
}
peer := snet.NewUDPAddr(addr.IA{}, &spath.Path{}, nil, nil)
peer := &snet.UDPAddr{IA: addr.IA{}, Path: &spath.Path{}}
req := infra.NewRequest(ctx, msg, nil, peer, 0)
ack := ack.Ack{
Err: proto.Ack_ErrCode_reject,
Expand Down
2 changes: 1 addition & 1 deletion go/integration/cert_req/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func getRemote() error {
if svcHost, err = getSVCAddress(); err != nil {
return err
}
svc = snet.NewUDPAddr(integration.Local.IA, nil, nil, svcHost)
svc = &snet.UDPAddr{IA: integration.Local.IA, Host: svcHost}
return nil
}

Expand Down
Loading

0 comments on commit 018f483

Please sign in to comment.