diff --git a/.golangcilint.yml b/.golangcilint.yml index ba3e6dff79..d585f3d638 100644 --- a/.golangcilint.yml +++ b/.golangcilint.yml @@ -3,6 +3,7 @@ linters: disable-all: true enable: # Default linters. + - forbidigo - errcheck - gosimple - govet @@ -19,6 +20,15 @@ linters: - misspell - goheader linters-settings: + # ... + forbidigo: + forbid: + - p: "([iI][fF][iI]d)|([iI]F[iI][dD])|([iI][fF]i[dD])" + msg: "spell interface ID as ifID / IfID" + - p: "(?i)interfaceID" # case insensitive + msg: "spell interface ID as ifID / IfID" + - p: "Trc" + msg: "spell trust root certificate as trc / TRC" lll: line-length: 100 tab-width: 4 diff --git a/control/beacon/beacon.go b/control/beacon/beacon.go index f38d54d90a..6378247870 100644 --- a/control/beacon/beacon.go +++ b/control/beacon/beacon.go @@ -25,8 +25,8 @@ import ( type Beacon struct { // Segment is the path segment. Segment *seg.PathSegment - // InIfId is the interface the beacon is received on. - InIfId uint16 + // InIfID is the interface the beacon is received on. + InIfID uint16 } // Diversity returns the link diversity between this and the other beacon. The @@ -39,11 +39,11 @@ func (b Beacon) Diversity(other Beacon) int { } var diff int for _, asEntry := range b.Segment.ASEntries { - ia, ifid := link(asEntry) + ia, ifID := link(asEntry) var found bool for _, otherEntry := range other.Segment.ASEntries { - oia, oifid := link(otherEntry) - if ia.Equal(oia) && ifid == oifid { + oia, oifID := link(otherEntry) + if ia.Equal(oia) && ifID == oifID { found = true break } @@ -56,7 +56,7 @@ func (b Beacon) Diversity(other Beacon) int { } func (b Beacon) String() string { - return fmt.Sprintf("Ingress: %d Segment: [ %s ]", b.InIfId, b.Segment) + return fmt.Sprintf("Ingress: %d Segment: [ %s ]", b.InIfID, b.Segment) } func link(entry seg.ASEntry) (addr.IA, uint16) { diff --git a/control/beacon/beacondbtest/beacondbtest.go b/control/beacon/beacondbtest/beacondbtest.go index 8c68d4f7bf..4b3af82017 100644 --- a/control/beacon/beacondbtest/beacondbtest.go +++ b/control/beacon/beacondbtest/beacondbtest.go @@ -318,13 +318,13 @@ func CheckResults(t *testing.T, results []beacon.Beacon, expectedBeacons []beaco } assert.Equal(t, expected, actual) } - assert.Equal(t, expected.InIfId, res.InIfId, "InIfId %d should match", i) + assert.Equal(t, expected.InIfID, res.InIfID, "InIfID %d should match", i) } } func InsertBeacon(t *testing.T, db beacon.DB, ases []IfInfo, - inIfId uint16, infoTS uint32, allowed beacon.Usage) beacon.Beacon { - b, _ := AllocBeacon(t, ases, inIfId, infoTS) + inIfID uint16, infoTS uint32, allowed beacon.Usage) beacon.Beacon { + b, _ := AllocBeacon(t, ases, inIfID, infoTS) ctx, cancelF := context.WithTimeout(context.Background(), timeout) defer cancelF() _, err := db.InsertBeacon(ctx, b, allowed) @@ -334,21 +334,21 @@ func InsertBeacon(t *testing.T, db beacon.DB, ases []IfInfo, type PeerEntry struct { IA addr.IA - Ingress common.IFIDType + Ingress common.IfIDType } type IfInfo struct { IA addr.IA Next addr.IA - Ingress common.IFIDType - Egress common.IFIDType + Ingress common.IfIDType + Egress common.IfIDType Peers []PeerEntry } func AllocBeacon( t *testing.T, ases []IfInfo, - inIfId uint16, + inIfID uint16, infoTS uint32, ) (beacon.Beacon, []byte) { @@ -401,5 +401,5 @@ func AllocBeacon( err := pseg.AddASEntry(context.Background(), entry, signer) require.NoError(t, err) } - return beacon.Beacon{Segment: pseg, InIfId: inIfId}, pseg.ID() + return beacon.Beacon{Segment: pseg, InIfID: inIfID}, pseg.ID() } diff --git a/control/beacon/store_test.go b/control/beacon/store_test.go index 0d26853116..3dc5d53ee3 100644 --- a/control/beacon/store_test.go +++ b/control/beacon/store_test.go @@ -269,13 +269,13 @@ func testBeacon(g *graph.Graph, desc ...uint16) beacon.Beacon { pseg := testSegment(g, desc) asEntry := pseg.ASEntries[pseg.MaxIdx()] return beacon.Beacon{ - InIfId: asEntry.HopEntry.HopField.ConsIngress, + InIfID: asEntry.HopEntry.HopField.ConsIngress, Segment: pseg, } } -func testSegment(g *graph.Graph, ifids []uint16) *seg.PathSegment { - pseg := g.Beacon(ifids) +func testSegment(g *graph.Graph, ifIDs []uint16) *seg.PathSegment { + pseg := g.Beacon(ifIDs) pseg.ASEntries = pseg.ASEntries[:len(pseg.ASEntries)-1] return pseg } diff --git a/control/beaconing/export_test.go b/control/beaconing/export_test.go index 57533ff782..76db29854c 100644 --- a/control/beaconing/export_test.go +++ b/control/beaconing/export_test.go @@ -20,7 +20,7 @@ import ( "github.com/scionproto/scion/private/topology" ) -func (cfg StaticInfoCfg) TestGenerate(ifType map[common.IFIDType]topology.LinkType, - ingress, egress common.IFIDType) *staticinfo.Extension { +func (cfg StaticInfoCfg) TestGenerate(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) *staticinfo.Extension { return cfg.generate(ifType, ingress, egress) } diff --git a/control/beaconing/extender.go b/control/beaconing/extender.go index 4ea5e99704..34374f2d10 100644 --- a/control/beaconing/extender.go +++ b/control/beaconing/extender.go @@ -298,13 +298,13 @@ func (s *DefaultExtender) remoteMTU(ifID uint16) (uint16, error) { return topoInfo.MTU, nil } -func (s *DefaultExtender) remoteInfo(ifid uint16) ( +func (s *DefaultExtender) remoteInfo(ifID uint16) ( addr.IA, uint16, uint16, error) { - if ifid == 0 { + if ifID == 0 { return 0, 0, 0, nil } - intf := s.Intfs.Get(ifid) + intf := s.Intfs.Get(ifID) if intf == nil { return 0, 0, 0, serrors.New("interface not found") } diff --git a/control/beaconing/grpc/beacon_sender.go b/control/beaconing/grpc/beacon_sender.go index df7fd85b5e..2f8cb96ed8 100644 --- a/control/beaconing/grpc/beacon_sender.go +++ b/control/beaconing/grpc/beacon_sender.go @@ -39,12 +39,12 @@ type BeaconSenderFactory struct { func (f *BeaconSenderFactory) NewSender( ctx context.Context, dstIA addr.IA, - egIfId uint16, + egIfID uint16, nextHop *net.UDPAddr, ) (beaconing.Sender, error) { addr := &onehop.Addr{ IA: dstIA, - Egress: egIfId, + Egress: egIfID, SVC: addr.SvcCS, NextHop: nextHop, } diff --git a/control/beaconing/grpc/creation_server.go b/control/beaconing/grpc/creation_server.go index 2dc3df7e28..26c3440caa 100644 --- a/control/beaconing/grpc/creation_server.go +++ b/control/beaconing/grpc/creation_server.go @@ -68,7 +68,7 @@ func (s SegmentCreationServer) Beacon(ctx context.Context, } b := beacon.Beacon{ Segment: ps, - InIfId: ingress, + InIfID: ingress, } if err := s.Handler.HandleBeacon(ctx, b, peer); err != nil { logger.Debug("Failed to handle beacon", "peer", peer, "err", err) diff --git a/control/beaconing/handler.go b/control/beaconing/handler.go index 31d7974301..886ffee737 100644 --- a/control/beaconing/handler.go +++ b/control/beaconing/handler.go @@ -54,19 +54,19 @@ type Handler struct { // HandleBeacon handles a baeacon received from peer. func (h Handler) HandleBeacon(ctx context.Context, b beacon.Beacon, peer *snet.UDPAddr) error { span := opentracing.SpanFromContext(ctx) - labels := handlerLabels{Ingress: b.InIfId} + labels := handlerLabels{Ingress: b.InIfID} - intf := h.Interfaces.Get(b.InIfId) + intf := h.Interfaces.Get(b.InIfID) if intf == nil { err := serrors.New("received beacon on non-existent interface", - "ingress_interface", b.InIfId) + "ingress_interface", b.InIfID) h.updateMetric(span, labels.WithResult(prom.ErrNotClassified), err) return err } upstream := intf.TopoInfo().IA if span != nil { - span.SetTag("ingress_interface", b.InIfId) + span.SetTag("ingress_interface", b.InIfID) span.SetTag("upstream", upstream) } labels.Neighbor = upstream @@ -106,7 +106,7 @@ func (h Handler) validateASEntry(b beacon.Beacon, intf *ifstate.Interface) error topoInfo := intf.TopoInfo() if topoInfo.LinkType != topology.Parent && topoInfo.LinkType != topology.Core { return serrors.New("beacon received on invalid link", - "ingress_interface", b.InIfId, "link_type", topoInfo.LinkType) + "ingress_interface", b.InIfID, "link_type", topoInfo.LinkType) } asEntry := b.Segment.ASEntries[b.Segment.MaxIdx()] if !asEntry.Local.Equal(topoInfo.IA) { diff --git a/control/beaconing/handler_test.go b/control/beaconing/handler_test.go index 487f28f388..4e7a9af575 100644 --- a/control/beaconing/handler_test.go +++ b/control/beaconing/handler_test.go @@ -51,7 +51,7 @@ func TestHandlerHandleBeacon(t *testing.T) { g := graph.NewDefaultGraph(mctrl) return beacon.Beacon{ Segment: testSegment(g, []uint16{graph.If_220_X_120_B, graph.If_120_A_110_X}), - InIfId: localIF, + InIfID: localIF, } }() @@ -104,7 +104,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: 12, + InIfID: 12, } }, Peer: func() *snet.UDPAddr { @@ -130,7 +130,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: 42, + InIfID: 42, } }, Peer: func() *snet.UDPAddr { @@ -156,7 +156,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: localIF, + InIfID: localIF, } b.Segment.ASEntries[b.Segment.MaxIdx()].Local = addr.MustParseIA("1-ff00:0:111") return b @@ -185,7 +185,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: localIF, + InIfID: localIF, } b.Segment.ASEntries[b.Segment.MaxIdx()].Next = addr.MustParseIA("1-ff00:0:111") return b @@ -276,8 +276,8 @@ func TestHandlerHandleBeacon(t *testing.T) { } } -func testSegment(g *graph.Graph, ifids []uint16) *seg.PathSegment { - pseg := g.Beacon(ifids) +func testSegment(g *graph.Graph, ifIDs []uint16) *seg.PathSegment { + pseg := g.Beacon(ifIDs) pseg.ASEntries = pseg.ASEntries[:len(pseg.ASEntries)-1] return pseg } diff --git a/control/beaconing/originator.go b/control/beaconing/originator.go index 52997e72d0..7219c6c1ba 100644 --- a/control/beaconing/originator.go +++ b/control/beaconing/originator.go @@ -140,11 +140,11 @@ func (o *Originator) needBeacon(active []*ifstate.Interface) []*ifstate.Interfac func (o *Originator) logSummary(logger log.Logger, s *summary) { if o.Tick.Passed() { - logger.Debug("Originated beacons", "egress_interfaces", s.IfIds()) + logger.Debug("Originated beacons", "egress_interfaces", s.IfIDs()) return } if s.count > 0 { - logger.Debug("Originated beacons on stale interfaces", "egress_interfaces", s.IfIds()) + logger.Debug("Originated beacons on stale interfaces", "egress_interfaces", s.IfIDs()) } } @@ -156,7 +156,7 @@ type beaconOriginator struct { summary *summary } -// originateBeacon originates a beacon on the given ifid. +// originateBeacon originates a beacon on the given ifID. func (o *beaconOriginator) originateBeacon(ctx context.Context) error { labels := originatorLabels{intf: o.intf} topoInfo := o.intf.TopoInfo() @@ -213,7 +213,7 @@ func (o *beaconOriginator) createBeacon(ctx context.Context) (*seg.PathSegment, func (o *beaconOriginator) onSuccess(intf *ifstate.Interface) { intf.Originate(o.Tick.Now()) - o.summary.AddIfid(o.intf.TopoInfo().ID) + o.summary.AddIfID(o.intf.TopoInfo().ID) o.summary.Inc() } diff --git a/control/beaconing/originator_test.go b/control/beaconing/originator_test.go index 6c2041eaf0..e7d64673a5 100644 --- a/control/beaconing/originator_test.go +++ b/control/beaconing/originator_test.go @@ -61,7 +61,7 @@ func TestOriginatorRun(t *testing.T) { } return false } - t.Run("run originates ifid packets on all active interfaces", func(t *testing.T) { + t.Run("run originates ifID packets on all active interfaces", func(t *testing.T) { mctrl := gomock.NewController(t) defer mctrl.Finish() intfs := ifstate.NewInterfaces(interfaceInfos(topo), ifstate.Config{}) @@ -90,7 +90,7 @@ func TestOriginatorRun(t *testing.T) { senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(4).DoAndReturn( - func(_ context.Context, dstIA addr.IA, egIfId uint16, + func(_ context.Context, dstIA addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) @@ -103,9 +103,9 @@ func TestOriginatorRun(t *testing.T) { // Extract the hop field from the current AS entry to compare. hopF := b.ASEntries[b.MaxIdx()].HopEntry.HopField // Check the interface matches. - assert.Equal(t, hopF.ConsEgress, egIfId) + assert.Equal(t, hopF.ConsEgress, egIfID) // Check that the beacon is sent to the correct border router. - br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr) + br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfID].InternalAddr) assert.Equal(t, br, nextHop) return nil }, diff --git a/control/beaconing/propagator.go b/control/beaconing/propagator.go index f2d0e27190..588ea9acaf 100644 --- a/control/beaconing/propagator.go +++ b/control/beaconing/propagator.go @@ -169,7 +169,7 @@ func (p *Propagator) beaconsPerInterface( } var beacons []beacon.Beacon for _, b := range allBeacons { - if p.AllInterfaces.Get(b.InIfId) == nil { + if p.AllInterfaces.Get(b.InIfID) == nil { continue } beacons = append(beacons, b) @@ -185,7 +185,7 @@ func (p *Propagator) beaconsPerInterface( if err != nil { return nil, err } - toPropagate = append(toPropagate, beacon.Beacon{Segment: ps, InIfId: b.InIfId}) + toPropagate = append(toPropagate, beacon.Beacon{Segment: ps, InIfID: b.InIfID}) } r[intf] = toPropagate } @@ -223,7 +223,7 @@ func (p *Propagator) logCandidateBeacons( for _, b := range beacons { infos = append(infos, Beacon{ ID: b.Segment.GetLoggingID(), - Ingress: b.InIfId, + Ingress: b.InIfID, Segment: hopsDescription(b.Segment.ASEntries), }) } @@ -271,7 +271,7 @@ func (p *propagator) Propagate(ctx context.Context) error { ) if err != nil { for _, b := range p.beacons { - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, prom.ErrNetwork) + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, prom.ErrNetwork) } return serrors.WrapStr("getting beacon sender", err, "waited_for", time.Since(senderStart).String(), @@ -295,14 +295,14 @@ func (p *propagator) Propagate(ctx context.Context) error { id = b.Segment.GetLoggingID() } - if err := p.extender.Extend(ctx, b.Segment, b.InIfId, egress, p.peers); err != nil { + if err := p.extender.Extend(ctx, b.Segment, b.InIfID, egress, p.peers); err != nil { logger.Error("Unable to extend beacon", "egress_interface", egress, - "beacon.ingress_interface", b.InIfId, + "beacon.ingress_interface", b.InIfID, "beacon.segment", hopsDescription(b.Segment.ASEntries), "err", err, ) - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, "err_create") + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, "err_create") return } @@ -310,24 +310,24 @@ func (p *propagator) Propagate(ctx context.Context) error { if err := sender.Send(ctx, b.Segment); err != nil { logger.Info("Unable to send beacon", "egress_interface", egress, - "beacon.ingress_interface", b.InIfId, + "beacon.ingress_interface", b.InIfID, "beacon.segment", hopsDescription(b.Segment.ASEntries), "waited_for", time.Since(sendStart).String(), "err", err, ) - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, prom.ErrNetwork) + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, prom.ErrNetwork) return } setSuccess() - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, prom.Success) + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, prom.Success) p.intf.Propagate(p.now) if debugEnabled { logger.Debug("Propagated beacon", "egress_interface", egress, "candidate_id", id, - "beacon.ingress_interface", b.InIfId, + "beacon.ingress_interface", b.InIfID, "beacon.segment", hopsDescription(b.Segment.ASEntries), "waited_for", time.Since(sendStart).String(), "err", err, diff --git a/control/beaconing/propagator_test.go b/control/beaconing/propagator_test.go index 5634e20eea..83ddfc73f6 100644 --- a/control/beaconing/propagator_test.go +++ b/control/beaconing/propagator_test.go @@ -95,13 +95,13 @@ func TestPropagatorRunNonCore(t *testing.T) { senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).DoAndReturn( - func(_ context.Context, _ addr.IA, egIfId uint16, + func(_ context.Context, _ addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(3).DoAndReturn( func(_ context.Context, b *seg.PathSegment) error { - validateSend(t, b, egIfId, nextHop, pub, topo) + validateSend(t, b, egIfID, nextHop, pub, topo) return nil }, ) @@ -168,13 +168,13 @@ func TestPropagatorRunCore(t *testing.T) { senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), uint16(1121), gomock.Any()).DoAndReturn( - func(_ context.Context, _ addr.IA, egIfId uint16, + func(_ context.Context, _ addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(2).DoAndReturn( func(_ context.Context, b *seg.PathSegment) error { - validateSend(t, b, egIfId, nextHop, pub, topo) + validateSend(t, b, egIfID, nextHop, pub, topo) return nil }, ) @@ -184,13 +184,13 @@ func TestPropagatorRunCore(t *testing.T) { ) senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), uint16(1113), gomock.Any()).DoAndReturn( - func(_ context.Context, _ addr.IA, egIfId uint16, + func(_ context.Context, _ addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(1).DoAndReturn( func(_ context.Context, b *seg.PathSegment) error { - validateSend(t, b, egIfId, nextHop, pub, topo) + validateSend(t, b, egIfID, nextHop, pub, topo) return nil }, ) @@ -280,7 +280,7 @@ func TestPropagatorFastRecovery(t *testing.T) { func validateSend( t *testing.T, b *seg.PathSegment, - egIfId uint16, + egIfID uint16, nextHop *net.UDPAddr, pub crypto.PublicKey, topo topology.Topology, @@ -292,8 +292,8 @@ func validateSend( // Extract the hop field from the current AS entry to compare. hopF := b.ASEntries[b.MaxIdx()].HopEntry.HopField // Check the interface matches. - assert.Equal(t, hopF.ConsEgress, egIfId) + assert.Equal(t, hopF.ConsEgress, egIfID) // Check that the beacon is sent to the correct border router. - br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr) + br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfID].InternalAddr) assert.Equal(t, br, nextHop) } diff --git a/control/beaconing/staticinfo_config.go b/control/beaconing/staticinfo_config.go index 3cedd4a72a..aa8c4f8a3d 100644 --- a/control/beaconing/staticinfo_config.go +++ b/control/beaconing/staticinfo_config.go @@ -30,12 +30,12 @@ import ( type InterfaceLatencies struct { Inter util.DurWrap `json:"Inter"` - Intra map[common.IFIDType]util.DurWrap `json:"Intra"` + Intra map[common.IfIDType]util.DurWrap `json:"Intra"` } type InterfaceBandwidths struct { Inter uint64 `json:"Inter"` - Intra map[common.IFIDType]uint64 `json:"Intra"` + Intra map[common.IfIDType]uint64 `json:"Intra"` } type InterfaceGeodata struct { @@ -45,7 +45,7 @@ type InterfaceGeodata struct { } type InterfaceHops struct { - Intra map[common.IFIDType]uint32 `json:"Intra"` + Intra map[common.IfIDType]uint32 `json:"Intra"` } type LinkType staticinfo.LinkType @@ -79,11 +79,11 @@ func (l *LinkType) UnmarshalText(text []byte) error { // StaticInfoCfg is used to parse data from config.json. type StaticInfoCfg struct { - Latency map[common.IFIDType]InterfaceLatencies `json:"Latency"` - Bandwidth map[common.IFIDType]InterfaceBandwidths `json:"Bandwidth"` - LinkType map[common.IFIDType]LinkType `json:"LinkType"` - Geo map[common.IFIDType]InterfaceGeodata `json:"Geo"` - Hops map[common.IFIDType]InterfaceHops `json:"Hops"` + Latency map[common.IfIDType]InterfaceLatencies `json:"Latency"` + Bandwidth map[common.IfIDType]InterfaceBandwidths `json:"Bandwidth"` + LinkType map[common.IfIDType]LinkType `json:"LinkType"` + Geo map[common.IfIDType]InterfaceGeodata `json:"Geo"` + Hops map[common.IfIDType]InterfaceHops `json:"Hops"` Note string `json:"Note"` } @@ -133,7 +133,7 @@ func (cfg *StaticInfoCfg) clean() { } // symmetrizeLatency makes the Intra latency values symmetric -func symmetrizeLatency(latency map[common.IFIDType]InterfaceLatencies) { +func symmetrizeLatency(latency map[common.IfIDType]InterfaceLatencies) { for i, sub := range latency { delete(sub.Intra, i) // Remove loopy entry for j, v := range sub.Intra { @@ -143,7 +143,7 @@ func symmetrizeLatency(latency map[common.IFIDType]InterfaceLatencies) { if latency[j].Intra == nil { latency[j] = InterfaceLatencies{ Inter: latency[j].Inter, - Intra: make(map[common.IFIDType]util.DurWrap), + Intra: make(map[common.IfIDType]util.DurWrap), } } vTransposed, ok := latency[j].Intra[i] @@ -156,7 +156,7 @@ func symmetrizeLatency(latency map[common.IFIDType]InterfaceLatencies) { } // symmetrizeBandwidth makes the Intra bandwidth values symmetric -func symmetrizeBandwidth(bandwidth map[common.IFIDType]InterfaceBandwidths) { +func symmetrizeBandwidth(bandwidth map[common.IfIDType]InterfaceBandwidths) { for i, sub := range bandwidth { delete(sub.Intra, i) // Remove loopy entry for j, v := range sub.Intra { @@ -166,7 +166,7 @@ func symmetrizeBandwidth(bandwidth map[common.IFIDType]InterfaceBandwidths) { if bandwidth[j].Intra == nil { bandwidth[j] = InterfaceBandwidths{ Inter: bandwidth[j].Inter, - Intra: make(map[common.IFIDType]uint64), + Intra: make(map[common.IfIDType]uint64), } } vTransposed, ok := bandwidth[j].Intra[i] @@ -179,13 +179,13 @@ func symmetrizeBandwidth(bandwidth map[common.IFIDType]InterfaceBandwidths) { } // symmetrizeHops makes the Intra hops values symmetric -func symmetrizeHops(hops map[common.IFIDType]InterfaceHops) { +func symmetrizeHops(hops map[common.IfIDType]InterfaceHops) { for i, sub := range hops { delete(sub.Intra, i) // Remove loopy entry for j, v := range sub.Intra { if _, ok := hops[j]; !ok { hops[j] = InterfaceHops{ - Intra: make(map[common.IFIDType]uint32), + Intra: make(map[common.IfIDType]uint32), } } vTransposed, ok := hops[j].Intra[i] @@ -203,11 +203,11 @@ func (cfg StaticInfoCfg) Generate(intfs *ifstate.Interfaces, ingress, egress uint16) *staticinfo.Extension { ifType := interfaceTypeTable(intfs) - return cfg.generate(ifType, common.IFIDType(ingress), common.IFIDType(egress)) + return cfg.generate(ifType, common.IfIDType(ingress), common.IfIDType(egress)) } -func (cfg StaticInfoCfg) generate(ifType map[common.IFIDType]topology.LinkType, - ingress, egress common.IFIDType) *staticinfo.Extension { +func (cfg StaticInfoCfg) generate(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) *staticinfo.Extension { return &staticinfo.Extension{ Latency: cfg.generateLatency(ifType, ingress, egress), @@ -221,22 +221,22 @@ func (cfg StaticInfoCfg) generate(ifType map[common.IFIDType]topology.LinkType, // generateLatency creates the LatencyInfo by extracting the relevant values from // the config. -func (cfg StaticInfoCfg) generateLatency(ifType map[common.IFIDType]topology.LinkType, - ingress, egress common.IFIDType) staticinfo.LatencyInfo { +func (cfg StaticInfoCfg) generateLatency(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.LatencyInfo { l := staticinfo.LatencyInfo{ - Intra: make(map[common.IFIDType]time.Duration), - Inter: make(map[common.IFIDType]time.Duration), + Intra: make(map[common.IfIDType]time.Duration), + Inter: make(map[common.IfIDType]time.Duration), } - for ifid, v := range cfg.Latency[egress].Intra { - if includeIntraInfo(ifType, ifid, ingress, egress) { - l.Intra[ifid] = v.Duration + for ifID, v := range cfg.Latency[egress].Intra { + if includeIntraInfo(ifType, ifID, ingress, egress) { + l.Intra[ifID] = v.Duration } } - for ifid, v := range cfg.Latency { - t := ifType[ifid] - if ifid == egress || t == topology.Peer { - l.Inter[ifid] = v.Inter.Duration + for ifID, v := range cfg.Latency { + t := ifType[ifID] + if ifID == egress || t == topology.Peer { + l.Inter[ifID] = v.Inter.Duration } } return l @@ -244,22 +244,22 @@ func (cfg StaticInfoCfg) generateLatency(ifType map[common.IFIDType]topology.Lin // generateBandwidth creates the BandwidthInfo by extracting the relevant values // from the config. -func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IFIDType]topology.LinkType, - ingress, egress common.IFIDType) staticinfo.BandwidthInfo { +func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.BandwidthInfo { bw := staticinfo.BandwidthInfo{ - Intra: make(map[common.IFIDType]uint64), - Inter: make(map[common.IFIDType]uint64), + Intra: make(map[common.IfIDType]uint64), + Inter: make(map[common.IfIDType]uint64), } - for ifid, v := range cfg.Bandwidth[egress].Intra { - if includeIntraInfo(ifType, ifid, ingress, egress) { - bw.Intra[ifid] = v + for ifID, v := range cfg.Bandwidth[egress].Intra { + if includeIntraInfo(ifType, ifID, ingress, egress) { + bw.Intra[ifID] = v } } - for ifid, v := range cfg.Bandwidth { - t := ifType[ifid] - if ifid == egress || t == topology.Peer { - bw.Inter[ifid] = v.Inter + for ifID, v := range cfg.Bandwidth { + t := ifType[ifID] + if ifID == egress || t == topology.Peer { + bw.Inter[ifID] = v.Inter } } return bw @@ -267,14 +267,14 @@ func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IFIDType]topology.L // generateLinkType creates the LinkTypeInfo by extracting the relevant values from // the config. -func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IFIDType]topology.LinkType, - egress common.IFIDType) staticinfo.LinkTypeInfo { +func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IfIDType]topology.LinkType, + egress common.IfIDType) staticinfo.LinkTypeInfo { lt := make(staticinfo.LinkTypeInfo) - for ifid, intfLT := range cfg.LinkType { - t := ifType[ifid] - if ifid == egress || t == topology.Peer { - lt[ifid] = staticinfo.LinkType(intfLT) + for ifID, intfLT := range cfg.LinkType { + t := ifType[ifID] + if ifID == egress || t == topology.Peer { + lt[ifID] = staticinfo.LinkType(intfLT) } } return lt @@ -282,13 +282,13 @@ func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IFIDType]topology.Li // generateInternalHops creates the InternalHopsInfo by extracting the relevant // values from the config. -func (cfg StaticInfoCfg) generateInternalHops(ifType map[common.IFIDType]topology.LinkType, - ingress, egress common.IFIDType) staticinfo.InternalHopsInfo { +func (cfg StaticInfoCfg) generateInternalHops(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.InternalHopsInfo { ihi := make(staticinfo.InternalHopsInfo) - for ifid, v := range cfg.Hops[egress].Intra { - if includeIntraInfo(ifType, ifid, ingress, egress) { - ihi[ifid] = v + for ifID, v := range cfg.Hops[egress].Intra { + if includeIntraInfo(ifType, ifID, ingress, egress) { + ihi[ifID] = v } } return ihi @@ -296,14 +296,14 @@ func (cfg StaticInfoCfg) generateInternalHops(ifType map[common.IFIDType]topolog // generateGeo creates the GeoInfo by extracting the relevant values from // the config. -func (cfg StaticInfoCfg) generateGeo(ifType map[common.IFIDType]topology.LinkType, - ingress, egress common.IFIDType) staticinfo.GeoInfo { +func (cfg StaticInfoCfg) generateGeo(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.GeoInfo { gi := staticinfo.GeoInfo{} - for ifid, loc := range cfg.Geo { - t := ifType[ifid] - if ifid == egress || ifid == ingress || t == topology.Peer { - gi[ifid] = staticinfo.GeoCoordinates{ + for ifID, loc := range cfg.Geo { + t := ifType[ifID] + if ifID == egress || ifID == ingress || t == topology.Peer { + gi[ifID] = staticinfo.GeoCoordinates{ Longitude: loc.Longitude, Latitude: loc.Latitude, Address: loc.Address, @@ -314,7 +314,7 @@ func (cfg StaticInfoCfg) generateGeo(ifType map[common.IFIDType]topology.LinkTyp } // includeIntraInfo determines if the intra-AS metadata info for the interface -// pair (ifid, egress) should be included in this beacon: +// pair (ifID, egress) should be included in this beacon: // Include information between the egress interface and // - ingress interface // - sibling child interfaces, @@ -322,34 +322,34 @@ func (cfg StaticInfoCfg) generateGeo(ifType map[common.IFIDType]topology.LinkTyp // - peer interfaces // For core/sibling child interfaces, we can skip some entries to avoid // redundancy: by consistently only including latency to interfaces with -// ifid > egress, we ensure that for each cross-over, the latency from +// ifID > egress, we ensure that for each cross-over, the latency from // this AS Entry's egress interface to the other AS Entry's egress // interface will be available in exactly one of the two AS Entries. // Note that the choice of < or > is arbitrary. At least each separate // AS needs to pick one consistently (or decide to just include the full // information all the time), otherwise information for cross-overs may // be missing. -func includeIntraInfo(ifType map[common.IFIDType]topology.LinkType, - ifid, ingress, egress common.IFIDType) bool { +func includeIntraInfo(ifType map[common.IfIDType]topology.LinkType, + ifID, ingress, egress common.IfIDType) bool { isCoreIngress := (ifType[ingress] == topology.Core || ingress == 0) isCoreEgress := (ifType[egress] == topology.Core || egress == 0) isCoreSeg := isCoreIngress && isCoreEgress if isCoreSeg { - return ifid == ingress + return ifID == ingress } - t := ifType[ifid] - return ifid == ingress || - t == topology.Child && ifid > egress || + t := ifType[ifID] + return ifID == ingress || + t == topology.Child && ifID > egress || t == topology.Core || t == topology.Peer } -func interfaceTypeTable(intfs *ifstate.Interfaces) map[common.IFIDType]topology.LinkType { +func interfaceTypeTable(intfs *ifstate.Interfaces) map[common.IfIDType]topology.LinkType { ifMap := intfs.All() - ifTypes := make(map[common.IFIDType]topology.LinkType, len(ifMap)) + ifTypes := make(map[common.IfIDType]topology.LinkType, len(ifMap)) for ifID, ifInfo := range ifMap { - ifTypes[common.IFIDType(ifID)] = ifInfo.TopoInfo().LinkType + ifTypes[common.IfIDType(ifID)] = ifInfo.TopoInfo().LinkType } return ifTypes } diff --git a/control/beaconing/staticinfo_config_test.go b/control/beaconing/staticinfo_config_test.go index e68a07734c..50dc57f9a1 100644 --- a/control/beaconing/staticinfo_config_test.go +++ b/control/beaconing/staticinfo_config_test.go @@ -95,10 +95,10 @@ func getTestConfigData() *beaconing.StaticInfoCfg { } return &beaconing.StaticInfoCfg{ - Latency: map[common.IFIDType]beaconing.InterfaceLatencies{ + Latency: map[common.IfIDType]beaconing.InterfaceLatencies{ 1: { Inter: w(latency_inter_1), - Intra: map[common.IFIDType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 2: w(latency_intra_1_2), 3: w(latency_intra_1_3), 5: w(latency_intra_1_5), @@ -106,7 +106,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 2: { Inter: w(latency_inter_2), - Intra: map[common.IFIDType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 1: w(latency_intra_1_2), 3: w(latency_intra_2_3), 5: w(latency_intra_2_5), @@ -114,7 +114,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 3: { Inter: w(latency_inter_3), - Intra: map[common.IFIDType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 1: w(latency_intra_1_3), 2: w(latency_intra_2_3), 5: w(latency_intra_3_5), @@ -122,17 +122,17 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 5: { Inter: w(latency_inter_5), - Intra: map[common.IFIDType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 1: w(latency_intra_1_5), 2: w(latency_intra_2_5), 3: w(latency_intra_3_5), }, }, }, - Bandwidth: map[common.IFIDType]beaconing.InterfaceBandwidths{ + Bandwidth: map[common.IfIDType]beaconing.InterfaceBandwidths{ 1: { Inter: bandwidth_inter_1, - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 2: bandwidth_intra_1_2, 3: bandwidth_intra_1_3, 5: bandwidth_intra_1_5, @@ -140,7 +140,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 2: { Inter: bandwidth_inter_2, - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_2, 3: bandwidth_intra_2_3, 5: bandwidth_intra_2_5, @@ -148,7 +148,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 3: { Inter: bandwidth_inter_3, - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_3, 2: bandwidth_intra_2_3, 5: bandwidth_intra_3_5, @@ -156,49 +156,49 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 5: { Inter: bandwidth_inter_5, - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_5, 2: bandwidth_intra_2_5, 3: bandwidth_intra_3_5, }, }, }, - LinkType: map[common.IFIDType]beaconing.LinkType{ + LinkType: map[common.IfIDType]beaconing.LinkType{ 1: beaconing.LinkType(link_type_1), 2: beaconing.LinkType(link_type_2), 3: beaconing.LinkType(link_type_3), 5: beaconing.LinkType(link_type_5), }, - Geo: map[common.IFIDType]beaconing.InterfaceGeodata{ + Geo: map[common.IfIDType]beaconing.InterfaceGeodata{ 1: {geo_1.Longitude, geo_1.Latitude, geo_1.Address}, 2: {geo_2.Longitude, geo_2.Latitude, geo_2.Address}, 3: {geo_3.Longitude, geo_3.Latitude, geo_3.Address}, 5: {geo_5.Longitude, geo_5.Latitude, geo_5.Address}, }, - Hops: map[common.IFIDType]beaconing.InterfaceHops{ + Hops: map[common.IfIDType]beaconing.InterfaceHops{ 1: { - Intra: map[common.IFIDType]uint32{ + Intra: map[common.IfIDType]uint32{ 2: hops_intra_1_2, 3: hops_intra_1_3, 5: hops_intra_1_5, }, }, 2: { - Intra: map[common.IFIDType]uint32{ + Intra: map[common.IfIDType]uint32{ 1: hops_intra_1_2, 3: hops_intra_2_3, 5: hops_intra_2_5, }, }, 3: { - Intra: map[common.IFIDType]uint32{ + Intra: map[common.IfIDType]uint32{ 1: hops_intra_1_3, 2: hops_intra_2_3, 5: hops_intra_3_5, }, }, 5: { - Intra: map[common.IFIDType]uint32{ + Intra: map[common.IfIDType]uint32{ 1: hops_intra_1_5, 2: hops_intra_2_5, 3: hops_intra_3_5, @@ -221,14 +221,14 @@ func TestGenerateStaticInfo(t *testing.T) { cfg := getTestConfigData() // "topology" information for a non-core AS: - ifTypeNoncore := map[common.IFIDType]topology.LinkType{ + ifTypeNoncore := map[common.IfIDType]topology.LinkType{ 1: topology.Child, 2: topology.Child, 3: topology.Parent, 5: topology.Peer, } // "topology" information for a core AS: - ifTypeCore := map[common.IFIDType]topology.LinkType{ + ifTypeCore := map[common.IfIDType]topology.LinkType{ 1: topology.Core, 2: topology.Child, 3: topology.Core, @@ -237,9 +237,9 @@ func TestGenerateStaticInfo(t *testing.T) { testCases := []struct { name string - ingress common.IFIDType - egress common.IFIDType - ifType map[common.IFIDType]topology.LinkType + ingress common.IfIDType + egress common.IfIDType + ifType map[common.IfIDType]topology.LinkType expected staticinfo.Extension }{ { @@ -249,23 +249,23 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 2: latency_intra_1_2, 3: latency_intra_1_3, 5: latency_intra_1_5, }, - Inter: map[common.IFIDType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 2: bandwidth_intra_1_2, 3: bandwidth_intra_1_3, 5: bandwidth_intra_1_5, }, - Inter: map[common.IFIDType]uint64{ + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, 5: bandwidth_inter_5, }, @@ -279,7 +279,7 @@ func TestGenerateStaticInfo(t *testing.T) { 1: link_type_1, 5: link_type_5, }, - InternalHops: map[common.IFIDType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 2: hops_intra_1_2, 3: hops_intra_1_3, 5: hops_intra_1_5, @@ -294,21 +294,21 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 3: latency_intra_2_3, 5: latency_intra_2_5, }, - Inter: map[common.IFIDType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 2: latency_inter_2, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 3: bandwidth_intra_2_3, 5: bandwidth_intra_2_5, }, - Inter: map[common.IFIDType]uint64{ + Inter: map[common.IfIDType]uint64{ 2: bandwidth_inter_2, 5: bandwidth_inter_5, }, @@ -322,7 +322,7 @@ func TestGenerateStaticInfo(t *testing.T) { 2: link_type_2, 5: link_type_5, }, - InternalHops: map[common.IFIDType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 3: hops_intra_2_3, 5: hops_intra_2_5, }, @@ -336,14 +336,14 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{}, - Inter: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{}, + Inter: map[common.IfIDType]time.Duration{ 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{}, - Inter: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{}, + Inter: map[common.IfIDType]uint64{ 5: bandwidth_inter_5, }, }, @@ -354,7 +354,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 5: link_type_5, }, - InternalHops: map[common.IFIDType]uint32{}, + InternalHops: map[common.IfIDType]uint32{}, Note: note, }, }, @@ -365,21 +365,21 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 2: latency_intra_1_2, 5: latency_intra_1_5, }, - Inter: map[common.IFIDType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 2: bandwidth_intra_1_2, 5: bandwidth_intra_1_5, }, - Inter: map[common.IFIDType]uint64{ + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, 5: bandwidth_inter_5, }, @@ -392,7 +392,7 @@ func TestGenerateStaticInfo(t *testing.T) { 1: link_type_1, 5: link_type_5, }, - InternalHops: map[common.IFIDType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 2: hops_intra_1_2, 5: hops_intra_1_5, }, @@ -406,19 +406,19 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 5: latency_intra_2_5, }, - Inter: map[common.IFIDType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 2: latency_inter_2, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 5: bandwidth_intra_2_5, }, - Inter: map[common.IFIDType]uint64{ + Inter: map[common.IfIDType]uint64{ 2: bandwidth_inter_2, 5: bandwidth_inter_5, }, @@ -431,7 +431,7 @@ func TestGenerateStaticInfo(t *testing.T) { 2: link_type_2, 5: link_type_5, }, - InternalHops: map[common.IFIDType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 5: hops_intra_2_5, }, Note: note, @@ -444,22 +444,22 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 1: latency_intra_1_2, 3: latency_intra_2_3, 5: latency_intra_2_5, }, - Inter: map[common.IFIDType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 2: latency_inter_2, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_2, 3: bandwidth_intra_2_3, 5: bandwidth_intra_2_5, }, - Inter: map[common.IFIDType]uint64{ + Inter: map[common.IfIDType]uint64{ 2: bandwidth_inter_2, }, }, @@ -469,7 +469,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 2: link_type_2, }, - InternalHops: map[common.IFIDType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 1: hops_intra_1_2, 3: hops_intra_2_3, 5: hops_intra_2_5, @@ -484,14 +484,14 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{}, - Inter: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{}, + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{}, - Inter: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{}, + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, }, }, @@ -501,7 +501,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 1: link_type_1, }, - InternalHops: map[common.IFIDType]uint32{}, + InternalHops: map[common.IfIDType]uint32{}, Note: note, }, }, @@ -512,18 +512,18 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 3: latency_intra_1_3, }, - Inter: map[common.IFIDType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 3: bandwidth_intra_1_3, }, - Inter: map[common.IFIDType]uint64{ + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, }, }, @@ -534,7 +534,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 1: link_type_1, }, - InternalHops: map[common.IFIDType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 3: hops_intra_1_3, }, Note: note, @@ -547,18 +547,18 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{}, - Inter: map[common.IFIDType]time.Duration{}, + Intra: map[common.IfIDType]time.Duration{}, + Inter: map[common.IfIDType]time.Duration{}, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{}, - Inter: map[common.IFIDType]uint64{}, + Intra: map[common.IfIDType]uint64{}, + Inter: map[common.IfIDType]uint64{}, }, Geo: staticinfo.GeoInfo{ 3: geo_3, }, LinkType: staticinfo.LinkTypeInfo{}, - InternalHops: map[common.IFIDType]uint32{}, + InternalHops: map[common.IfIDType]uint32{}, Note: note, }, }, diff --git a/control/beaconing/util.go b/control/beaconing/util.go index 0bf0eda7f9..8bcb02f10d 100644 --- a/control/beaconing/util.go +++ b/control/beaconing/util.go @@ -32,12 +32,12 @@ import ( // ID. func sortedIntfs(intfs *ifstate.Interfaces, linkType topology.LinkType) []uint16 { var result []uint16 - for ifid, intf := range intfs.All() { + for ifID, intf := range intfs.All() { topoInfo := intf.TopoInfo() if topoInfo.LinkType != linkType { continue } - result = append(result, ifid) + result = append(result, ifID) } sort.Slice(result, func(i, j int) bool { return result[i] < result[j] }) return result @@ -46,14 +46,14 @@ func sortedIntfs(intfs *ifstate.Interfaces, linkType topology.LinkType) []uint16 type summary struct { mu sync.Mutex srcs map[addr.IA]struct{} - ifIds map[uint16]struct{} + ifIDs map[uint16]struct{} count int } func newSummary() *summary { return &summary{ srcs: make(map[addr.IA]struct{}), - ifIds: make(map[uint16]struct{}), + ifIDs: make(map[uint16]struct{}), } } @@ -63,10 +63,10 @@ func (s *summary) AddSrc(ia addr.IA) { s.srcs[ia] = struct{}{} } -func (s *summary) AddIfid(ifid uint16) { +func (s *summary) AddIfID(ifID uint16) { s.mu.Lock() defer s.mu.Unlock() - s.ifIds[ifid] = struct{}{} + s.ifIDs[ifID] = struct{}{} } func (s *summary) Inc() { @@ -75,12 +75,12 @@ func (s *summary) Inc() { s.count++ } -func (s *summary) IfIds() []uint16 { +func (s *summary) IfIDs() []uint16 { s.mu.Lock() defer s.mu.Unlock() - list := make([]uint16, 0, len(s.ifIds)) - for ifId := range s.ifIds { - list = append(list, ifId) + list := make([]uint16, 0, len(s.ifIDs)) + for ifID := range s.ifIDs { + list = append(list, ifID) } sort.Slice(list, func(i, j int) bool { return list[i] < list[j] }) return list diff --git a/control/beaconing/writer.go b/control/beaconing/writer.go index 70dcde0eae..52dd7a2b3c 100644 --- a/control/beaconing/writer.go +++ b/control/beaconing/writer.go @@ -165,10 +165,10 @@ func (r *RemoteWriter) Write( var expected int var wg sync.WaitGroup for _, b := range segments { - if r.Intfs.Get(b.InIfId) == nil { + if r.Intfs.Get(b.InIfID) == nil { continue } - err := r.Extender.Extend(ctx, b.Segment, b.InIfId, 0, peers) + err := r.Extender.Extend(ctx, b.Segment, b.InIfID, 0, peers) if err != nil { logger.Error("Unable to terminate beacon", "beacon", b, "err", err) metrics.CounterInc(r.InternalErrors) @@ -223,10 +223,10 @@ func (r *LocalWriter) Write( beacons := make(map[string]beacon.Beacon) var toRegister []*seg.Meta for _, b := range segments { - if r.Intfs.Get(b.InIfId) == nil { + if r.Intfs.Get(b.InIfID) == nil { continue } - err := r.Extender.Extend(ctx, b.Segment, b.InIfId, 0, peers) + err := r.Extender.Extend(ctx, b.Segment, b.InIfID, 0, peers) if err != nil { logger.Error("Unable to terminate beacon", "beacon", b, "err", err) metrics.CounterInc(r.InternalErrors) @@ -266,7 +266,7 @@ func (r *LocalWriter) updateMetricsFromStat(s seghandler.SegStats, b map[string] for _, id := range s.InsertedSegs { metrics.CounterInc(metrics.CounterWith(r.Registered, writerLabels{ StartIA: b[id].Segment.FirstIA(), - Ingress: b[id].InIfId, + Ingress: b[id].InIfID, SegType: r.Type.String(), Result: "ok_new", }.Expand()...)) @@ -274,7 +274,7 @@ func (r *LocalWriter) updateMetricsFromStat(s seghandler.SegStats, b map[string] for _, id := range s.UpdatedSegs { metrics.CounterInc(metrics.CounterWith(r.Registered, writerLabels{ StartIA: b[id].Segment.FirstIA(), - Ingress: b[id].InIfId, + Ingress: b[id].InIfID, SegType: r.Type.String(), Result: "ok_updated", }.Expand()...)) @@ -315,7 +315,7 @@ func (r *remoteWriter) startSendSegReg(ctx context.Context, bseg beacon.Beacon, labels := writerLabels{ StartIA: bseg.Segment.FirstIA(), - Ingress: bseg.InIfId, + Ingress: bseg.InIfID, SegType: r.writer.Type.String(), } diff --git a/control/beaconing/writer_test.go b/control/beaconing/writer_test.go index 788a9544c0..508b00849c 100644 --- a/control/beaconing/writer_test.go +++ b/control/beaconing/writer_test.go @@ -316,7 +316,7 @@ func TestRegistrarRun(t *testing.T) { func(_, _ interface{}) (<-chan beacon.Beacon, error) { res := make(chan beacon.Beacon, 1) b := testBeacon(g, []uint16{graph.If_120_X_111_B}) - b.InIfId = 10 + b.InIfID = 10 res <- b close(res) return res, nil @@ -331,7 +331,7 @@ func testBeacon(g *graph.Graph, desc []uint16) beacon.Beacon { bseg.ASEntries = bseg.ASEntries[:len(bseg.ASEntries)-1] return beacon.Beacon{ - InIfId: asEntry.HopEntry.HopField.ConsIngress, + InIfID: asEntry.HopEntry.HopField.ConsIngress, Segment: bseg, } } @@ -377,7 +377,7 @@ type topoWrap struct { } func (w topoWrap) UnderlayNextHop(id uint16) *net.UDPAddr { - a, _ := w.Topo.UnderlayNextHop(common.IFIDType(id)) + a, _ := w.Topo.UnderlayNextHop(common.IfIDType(id)) return a } @@ -390,7 +390,7 @@ func interfaceInfos(topo topology.Topology) map[uint16]ifstate.InterfaceInfo { IA: info.IA, LinkType: info.LinkType, InternalAddr: netip.MustParseAddrPort(info.InternalAddr.String()), - RemoteID: uint16(info.RemoteIFID), + RemoteID: uint16(info.RemoteIfID), MTU: uint16(info.MTU), } } diff --git a/control/cmd/control/main.go b/control/cmd/control/main.go index 7b36a7e28d..c591180d79 100644 --- a/control/cmd/control/main.go +++ b/control/cmd/control/main.go @@ -844,7 +844,7 @@ func createBeaconStore( return store, *policies.Prop.Filter.AllowIsdLoop, err } -func adaptInterfaceMap(in map[common.IFIDType]topology.IFInfo) map[uint16]ifstate.InterfaceInfo { +func adaptInterfaceMap(in map[common.IfIDType]topology.IFInfo) map[uint16]ifstate.InterfaceInfo { converted := make(map[uint16]ifstate.InterfaceInfo, len(in)) for id, info := range in { converted[uint16(id)] = ifstate.InterfaceInfo{ @@ -852,7 +852,7 @@ func adaptInterfaceMap(in map[common.IFIDType]topology.IFInfo) map[uint16]ifstat IA: info.IA, LinkType: info.LinkType, InternalAddr: info.InternalAddr, - RemoteID: uint16(info.RemoteIFID), + RemoteID: uint16(info.RemoteIfID), MTU: uint16(info.MTU), } } diff --git a/control/ifstate/ifstate.go b/control/ifstate/ifstate.go index 5fa04e4fa8..53aa464d2a 100644 --- a/control/ifstate/ifstate.go +++ b/control/ifstate/ifstate.go @@ -86,12 +86,12 @@ func (intfs *Interfaces) Update(ifInfomap map[uint16]InterfaceInfo) { intfs.mu.Lock() defer intfs.mu.Unlock() m := make(map[uint16]*Interface, len(intfs.intfs)) - for ifid, info := range ifInfomap { - if intf, ok := intfs.intfs[ifid]; ok { + for ifID, info := range ifInfomap { + if intf, ok := intfs.intfs[ifID]; ok { intf.updateTopoInfo(info) - m[ifid] = intf + m[ifID] = intf } else { - m[ifid] = &Interface{ + m[ifID] = &Interface{ topoInfo: info, cfg: intfs.cfg, } @@ -128,17 +128,17 @@ func (intfs *Interfaces) All() map[uint16]*Interface { intfs.mu.RLock() defer intfs.mu.RUnlock() res := make(map[uint16]*Interface, len(intfs.intfs)) - for ifid, intf := range intfs.intfs { - res[ifid] = intf + for ifID, intf := range intfs.intfs { + res[ifID] = intf } return res } // Get returns the interface for the specified id, or nil if not present. -func (intfs *Interfaces) Get(ifid uint16) *Interface { +func (intfs *Interfaces) Get(ifID uint16) *Interface { intfs.mu.RLock() defer intfs.mu.RUnlock() - return intfs.intfs[ifid] + return intfs.intfs[ifID] } // Interface keeps track of the interface state. diff --git a/control/ifstate/ifstate_test.go b/control/ifstate/ifstate_test.go index da44d392d4..7b144f15be 100644 --- a/control/ifstate/ifstate_test.go +++ b/control/ifstate/ifstate_test.go @@ -33,7 +33,7 @@ func TestInterfacesUpdate(t *testing.T) { // The topo info should come from the updated map. assert.Equal(t, uint16(1401), intfs.Get(1).TopoInfo().MTU) assert.Equal(t, uint16(1402), intfs.Get(2).TopoInfo().MTU) - // The remote ifid should be kept + // The remote ifID should be kept assert.EqualValues(t, 11, intfs.Get(1).TopoInfo().RemoteID) assert.EqualValues(t, 22, intfs.Get(2).TopoInfo().RemoteID) }) diff --git a/control/mgmtapi/api.go b/control/mgmtapi/api.go index 539edf9f6d..666df8bfe3 100644 --- a/control/mgmtapi/api.go +++ b/control/mgmtapi/api.go @@ -213,7 +213,7 @@ func (s *Server) GetBeacons(w http.ResponseWriter, r *http.Request, params GetBe } rep = append(rep, &Beacon{ Usages: usage, - IngressInterface: int(result.Beacon.InIfId), + IngressInterface: int(result.Beacon.InIfID), Id: segapi.SegID(s), LastUpdated: result.LastUpdated, Timestamp: s.Info.Timestamp.UTC(), @@ -362,7 +362,7 @@ func (s *Server) GetBeacon(w http.ResponseWriter, r *http.Request, segmentId Seg res := map[string]Beacon{ "beacon": { Usages: usage, - IngressInterface: int(results[0].Beacon.InIfId), + IngressInterface: int(results[0].Beacon.InIfID), Id: segapi.SegID(seg), LastUpdated: results[0].LastUpdated, Timestamp: seg.Info.Timestamp.UTC(), @@ -586,22 +586,26 @@ func (s *Server) GetCa(w http.ResponseWriter, r *http.Request) { } // GetTrcs gets the trcs specified by it's params. -func (s *Server) GetTrcs(w http.ResponseWriter, r *http.Request, params GetTrcsParams) { - cppkiParams := cppkiapi.GetTrcsParams{ +func (s *Server) GetTrcs( + w http.ResponseWriter, + r *http.Request, + params GetTrcsParams, // nolint - name from published API +) { + cppkiParams := cppkiapi.GetTrcsParams{ // nolint - name from published API Isd: params.Isd, All: params.All, } - s.CPPKIServer.GetTrcs(w, r, cppkiParams) + s.CPPKIServer.GetTrcs(w, r, cppkiParams) // nolint - name from published API } // GetTrc gets the trc specified by it's isd base and serial. func (s *Server) GetTrc(w http.ResponseWriter, r *http.Request, isd int, base int, serial int) { - s.CPPKIServer.GetTrc(w, r, isd, base, serial) + s.CPPKIServer.GetTrc(w, r, isd, base, serial) // nolint - name from published API } // GetTrcBlob gets the trc encoded pem blob. func (s *Server) GetTrcBlob(w http.ResponseWriter, r *http.Request, isd int, base int, serial int) { - s.CPPKIServer.GetTrcBlob(w, r, isd, base, serial) + s.CPPKIServer.GetTrcBlob(w, r, isd, base, serial) // nolint - name from published API } // GetConfig is an indirection to the http handler. @@ -663,12 +667,12 @@ func (s *Server) GetSigner(w http.ResponseWriter, r *http.Request) { }, }, Expiration: p.Expiration, - TrcId: TRCID{ + TrcId: TRCID{ // nolint - name from published API BaseNumber: int(p.TRCID.Base), Isd: int(p.TRCID.ISD), SerialNumber: int(p.TRCID.Serial), }, - TrcInGracePeriod: p.InGrace, + TrcInGracePeriod: p.InGrace, // nolint - name from published API } enc := json.NewEncoder(w) enc.SetIndent("", " ") diff --git a/control/mgmtapi/api_test.go b/control/mgmtapi/api_test.go index c31cc20d17..d4e3e650b6 100644 --- a/control/mgmtapi/api_test.go +++ b/control/mgmtapi/api_test.go @@ -945,7 +945,7 @@ func createBeacons(t *testing.T) []beacon.Beacon { }, }, }, - InIfId: 2, + InIfID: 2, }, Usage: beaconlib.UsageUpReg | beaconlib.UsageDownReg, LastUpdated: time.Date(2021, 1, 2, 8, 0, 0, 0, time.UTC), @@ -979,7 +979,7 @@ func createBeacons(t *testing.T) []beacon.Beacon { }, }, }, - InIfId: 1, + InIfID: 1, }, Usage: beaconlib.UsageCoreReg, LastUpdated: time.Date(2021, 2, 2, 8, 0, 0, 0, time.UTC), diff --git a/control/trust/grpc/proto.go b/control/trust/grpc/proto.go index af20257fe2..5c1644e9a5 100644 --- a/control/trust/grpc/proto.go +++ b/control/trust/grpc/proto.go @@ -86,6 +86,6 @@ func chainsToResponse(chains [][]*x509.Certificate) *cppb.ChainsResponse { func trcToResponse(trc cppki.SignedTRC) *cppb.TRCResponse { return &cppb.TRCResponse{ - Trc: trc.Raw, + Trc: trc.Raw, // nolint - name from protobuf } } diff --git a/control/trust/grpc/proto_test.go b/control/trust/grpc/proto_test.go index 2370ed3e68..d5e01bcde5 100644 --- a/control/trust/grpc/proto_test.go +++ b/control/trust/grpc/proto_test.go @@ -150,5 +150,5 @@ func TestChainsToRep(t *testing.T) { func TestTRCToRep(t *testing.T) { trc := cppki.SignedTRC{Raw: []byte("you can trust me, for sure!")} rep := trustgrpc.TRCToResponse(trc) - assert.Equal(t, trc.Raw, rep.Trc) + assert.Equal(t, trc.Raw, rep.Trc) // nolint - name from published protobuf } diff --git a/daemon/internal/servers/grpc.go b/daemon/internal/servers/grpc.go index c8c8258bcb..16b64b9d15 100644 --- a/daemon/internal/servers/grpc.go +++ b/daemon/internal/servers/grpc.go @@ -47,7 +47,7 @@ import ( ) type Topology interface { - InterfaceIDs() []uint16 + IfIDs() []uint16 UnderlayNextHop(uint16) *net.UDPAddr ControlServiceAddresses() []*net.UDPAddr PortRange() (uint16, uint16) @@ -277,7 +277,7 @@ func (s *DaemonServer) interfaces(ctx context.Context, Interfaces: make(map[uint64]*sdpb.Interface), } topo := s.Topology - for _, ifID := range topo.InterfaceIDs() { + for _, ifID := range topo.IfIDs() { nextHop := topo.UnderlayNextHop(ifID) if nextHop == nil { continue @@ -337,7 +337,7 @@ func (s *DaemonServer) notifyInterfaceDown(ctx context.Context, revInfo := &path_mgmt.RevInfo{ RawIsdas: addr.IA(req.IsdAs), - IfID: common.IFIDType(req.Id), + IfID: common.IfIDType(req.Id), LinkType: proto.LinkType_core, RawTTL: 10, RawTimestamp: util.TimeToSecs(time.Now()), diff --git a/daemon/mgmtapi/api.go b/daemon/mgmtapi/api.go index 60e7ff7753..15815a2ced 100644 --- a/daemon/mgmtapi/api.go +++ b/daemon/mgmtapi/api.go @@ -102,20 +102,24 @@ func (s *Server) GetCertificateBlob(w http.ResponseWriter, r *http.Request, chai } // GetTrcs gets the trcs specified by it's params. -func (s *Server) GetTrcs(w http.ResponseWriter, r *http.Request, params GetTrcsParams) { - cppkiParams := cppkiapi.GetTrcsParams{ +func (s *Server) GetTrcs( + w http.ResponseWriter, + r *http.Request, + params GetTrcsParams, // nolint - name from published API +) { + cppkiParams := cppkiapi.GetTrcsParams{ // nolint - name from published API Isd: params.Isd, All: params.All, } - s.CPPKIServer.GetTrcs(w, r, cppkiParams) + s.CPPKIServer.GetTrcs(w, r, cppkiParams) // nolint - name from published API } // GetTrc gets the trc specified by it's isd base and serial. func (s *Server) GetTrc(w http.ResponseWriter, r *http.Request, isd int, base int, serial int) { - s.CPPKIServer.GetTrc(w, r, isd, base, serial) + s.CPPKIServer.GetTrc(w, r, isd, base, serial) // nolint - name from published API } // GetTrcBlob gets the trc encoded pem blob. func (s *Server) GetTrcBlob(w http.ResponseWriter, r *http.Request, isd int, base int, serial int) { - s.CPPKIServer.GetTrcBlob(w, r, isd, base, serial) + s.CPPKIServer.GetTrcBlob(w, r, isd, base, serial) // nolint - name from published API } diff --git a/doc/dev/style/go.rst b/doc/dev/style/go.rst index e3be4d6659..f96a349f30 100644 --- a/doc/dev/style/go.rst +++ b/doc/dev/style/go.rst @@ -13,12 +13,14 @@ Naming ------ We use mixedCaps notation as recommended by `Effective Go -`__. The following rules apply (note -that a significant part of the code base uses other notations; these should be -refactored, however): +`__. Perhaps unintuitively, Go +treats ``ID`` as an initialism, and we treat ``If`` as a word. The following +rules apply (note that a significant part of the code base uses other +notations; these should be refactored, however): - Use ``sd`` or ``SD`` to refer to the SCION Daemon, not ``Sciond`` or ``SCIOND``. -- Use ``IfID`` or ``ifID`` for SCION Interface Identifiers, not ``IFID`` or ``InterfaceID``. +- Use ``IfID`` or ``ifID`` for SCION Interface Identifiers, not ``IFID`` nor ``InterfaceID`` nor ``intfID``. +- Use ``IfIDSomething`` or ``ifIDSomething`` when concatenating ``ifID`` with ``something``. - Use ``Svc`` or ``svc`` for SCION Service Addresses, not ``SVC`` or ``Service``. - Use ``TRC`` or ``trc`` for Trust Root Configurations, not ``Trc``. diff --git a/gateway/pathhealth/revocations_test.go b/gateway/pathhealth/revocations_test.go index 4c2368f775..8698fe891f 100644 --- a/gateway/pathhealth/revocations_test.go +++ b/gateway/pathhealth/revocations_test.go @@ -69,18 +69,18 @@ func TestExpiredRevocation(t *testing.T) { s.Cleanup(context.Background()) } -func createMockPath(ctrl *gomock.Controller, ia addr.IA, ifid common.IFIDType) snet.Path { +func createMockPath(ctrl *gomock.Controller, ia addr.IA, ifID common.IfIDType) snet.Path { path := mock_snet.NewMockPath(ctrl) path.EXPECT().Metadata().Return(&snet.PathMetadata{ - Interfaces: []snet.PathInterface{{IA: ia, ID: ifid}}, + Interfaces: []snet.PathInterface{{IA: ia, ID: ifID}}, }) return path } -func createRevInfo(ia addr.IA, ifid common.IFIDType, expired bool) *path_mgmt.RevInfo { +func createRevInfo(ia addr.IA, ifID common.IfIDType, expired bool) *path_mgmt.RevInfo { ri := &path_mgmt.RevInfo{ RawIsdas: ia, - IfID: ifid, + IfID: ifID, // Revocation was issued a minute ago. RawTimestamp: util.TimeToSecs(time.Now().Add(-time.Minute)), } diff --git a/pkg/daemon/grpc.go b/pkg/daemon/grpc.go index 4cbec6036c..0b5ff34736 100644 --- a/pkg/daemon/grpc.go +++ b/pkg/daemon/grpc.go @@ -260,7 +260,7 @@ func convertPath(p *sdpb.Path, dst addr.IA) (path.Path, error) { interfaces := make([]snet.PathInterface, len(p.Interfaces)) for i, pi := range p.Interfaces { interfaces[i] = snet.PathInterface{ - ID: common.IFIDType(pi.Id), + ID: common.IfIDType(pi.Id), IA: addr.IA(pi.IsdAs), } } diff --git a/pkg/experimental/hiddenpath/beaconwriter.go b/pkg/experimental/hiddenpath/beaconwriter.go index 917ac03c80..3fd2b802db 100644 --- a/pkg/experimental/hiddenpath/beaconwriter.go +++ b/pkg/experimental/hiddenpath/beaconwriter.go @@ -80,17 +80,17 @@ func (w *BeaconWriter) Write(ctx context.Context, segments []beacon.Beacon, var wg sync.WaitGroup for _, b := range segments { - if w.Intfs.Get(b.InIfId) == nil { - logger.Error("Received beacon for non-existing interface", "interface", b.InIfId) + if w.Intfs.Get(b.InIfID) == nil { + logger.Error("Received beacon for non-existing interface", "interface", b.InIfID) metrics.CounterInc(w.InternalErrors) continue } - regPolicy, ok := w.RegistrationPolicy[uint64(b.InIfId)] + regPolicy, ok := w.RegistrationPolicy[uint64(b.InIfID)] if !ok { - logger.Info("no HP nor public registration policy for beacon", "interface", b.InIfId) + logger.Info("no HP nor public registration policy for beacon", "interface", b.InIfID) continue } - err := w.Extender.Extend(ctx, b.Segment, b.InIfId, 0, peers) + err := w.Extender.Extend(ctx, b.Segment, b.InIfID, 0, peers) if err != nil { logger.Error("Unable to terminate beacon", "beacon", b, "err", err) metrics.CounterInc(w.InternalErrors) @@ -161,7 +161,7 @@ func (w *remoteWriter) run(ctx context.Context, bseg beacon.Beacon) { labels := writerLabels{ StartIA: bseg.Segment.FirstIA(), - Ingress: bseg.InIfId, + Ingress: bseg.InIfID, SegType: w.segTypeString(), } diff --git a/pkg/experimental/hiddenpath/beaconwriter_test.go b/pkg/experimental/hiddenpath/beaconwriter_test.go index 5844b4c30e..d68c0b19c0 100644 --- a/pkg/experimental/hiddenpath/beaconwriter_test.go +++ b/pkg/experimental/hiddenpath/beaconwriter_test.go @@ -231,7 +231,7 @@ func testBeacon(g *graph.Graph, desc []uint16) beacon.Beacon { bseg.ASEntries = bseg.ASEntries[:len(bseg.ASEntries)-1] return beacon.Beacon{ - InIfId: asEntry.HopEntry.HopField.ConsIngress, + InIfID: asEntry.HopEntry.HopField.ConsIngress, Segment: bseg, } } @@ -274,12 +274,12 @@ func (v segVerifier) Verify(_ context.Context, signedMsg *cryptopb.SignedMessage // ID. func sortedIntfs(intfs *ifstate.Interfaces, linkType topology.LinkType) []uint16 { var result []uint16 - for ifid, intf := range intfs.All() { + for ifID, intf := range intfs.All() { topoInfo := intf.TopoInfo() if topoInfo.LinkType != linkType { continue } - result = append(result, ifid) + result = append(result, ifID) } sort.Slice(result, func(i, j int) bool { return result[i] < result[j] }) return result @@ -348,7 +348,7 @@ type topoWrap struct { } func (w topoWrap) UnderlayNextHop(id uint16) *net.UDPAddr { - a, _ := w.Topo.UnderlayNextHop(common.IFIDType(id)) + a, _ := w.Topo.UnderlayNextHop(common.IfIDType(id)) return a } @@ -369,7 +369,7 @@ func interfaceInfos(topo topology.Topology) map[uint16]ifstate.InterfaceInfo { IA: info.IA, LinkType: info.LinkType, InternalAddr: netip.MustParseAddrPort(info.InternalAddr.String()), - RemoteID: uint16(info.RemoteIFID), + RemoteID: uint16(info.RemoteIfID), MTU: uint16(info.MTU), } } diff --git a/pkg/private/common/defs.go b/pkg/private/common/defs.go index 62d0f068bb..ae00ad94c7 100644 --- a/pkg/private/common/defs.go +++ b/pkg/private/common/defs.go @@ -32,28 +32,28 @@ const ( TimeFmtSecs = "2006-01-02 15:04:05-0700" ) -// IFIDType is the type for interface IDs. +// IfIDType is the type for interface IDs. // // Deprecated: with version 2 of the SCION header, there is no interface ID type anymore. // Use the appropriate type depending on the path type. -type IFIDType uint64 +type IfIDType uint64 -func (ifid IFIDType) String() string { - return strconv.FormatUint(uint64(ifid), 10) +func (ifID IfIDType) String() string { + return strconv.FormatUint(uint64(ifID), 10) } // UnmarshalJSON unmarshals the JSON data into the IfID. -func (ifid *IFIDType) UnmarshalJSON(data []byte) error { - return ifid.UnmarshalText(data) +func (ifID *IfIDType) UnmarshalJSON(data []byte) error { + return ifID.UnmarshalText(data) } // UnmarshalText unmarshals the text into the IfID. -func (ifid *IFIDType) UnmarshalText(text []byte) error { +func (ifID *IfIDType) UnmarshalText(text []byte) error { i, err := strconv.ParseUint(strings.ReplaceAll(string(text), "\"", ""), 10, 64) if err != nil { return err } - *ifid = IFIDType(i) + *ifID = IfIDType(i) return nil } diff --git a/pkg/private/common/defs_test.go b/pkg/private/common/defs_test.go index d911c2e53c..218181b201 100644 --- a/pkg/private/common/defs_test.go +++ b/pkg/private/common/defs_test.go @@ -41,10 +41,10 @@ func TestTypeOf(t *testing.T) { } } -func TestIFIDTypeUnmarshalJSON(t *testing.T) { +func TestIfIDTypeUnmarshalJSON(t *testing.T) { t.Run("Simple Value", func(t *testing.T) { type exampleStruct struct { - IfID common.IFIDType `json:"if_id"` + IfID common.IfIDType `json:"if_id"` } j := `{"if_id": 5}` var f exampleStruct @@ -53,17 +53,17 @@ func TestIFIDTypeUnmarshalJSON(t *testing.T) { }) t.Run("Map keys", func(t *testing.T) { type exampleStruct struct { - IfMap map[common.IFIDType]string `json:"if_map"` + IfMap map[common.IfIDType]string `json:"if_map"` } j := `{"if_map": {"5": "foo"}}` var f exampleStruct require.NoError(t, json.Unmarshal([]byte(j), &f)) - assert.Equal(t, exampleStruct{IfMap: map[common.IFIDType]string{5: "foo"}}, f) + assert.Equal(t, exampleStruct{IfMap: map[common.IfIDType]string{5: "foo"}}, f) }) } -func TestIFIDTypeUnmarshalText(t *testing.T) { - var id common.IFIDType +func TestIfIDTypeUnmarshalText(t *testing.T) { + var id common.IfIDType assert.NoError(t, id.UnmarshalText([]byte("1"))) - assert.Equal(t, common.IFIDType(1), id) + assert.Equal(t, common.IfIDType(1), id) } diff --git a/pkg/private/ctrl/path_mgmt/rev_info.go b/pkg/private/ctrl/path_mgmt/rev_info.go index 4a9d6d1396..45b75ff82f 100644 --- a/pkg/private/ctrl/path_mgmt/rev_info.go +++ b/pkg/private/ctrl/path_mgmt/rev_info.go @@ -47,7 +47,7 @@ func (ee RevTimeError) Error() string { } type RevInfo struct { - IfID common.IFIDType + IfID common.IfIDType RawIsdas addr.IA // LinkType of revocation LinkType proto.LinkType diff --git a/pkg/private/xtest/graph/graph.go b/pkg/private/xtest/graph/graph.go index f608624e5f..ee3020f4fd 100644 --- a/pkg/private/xtest/graph/graph.go +++ b/pkg/private/xtest/graph/graph.go @@ -48,20 +48,20 @@ import ( "github.com/scionproto/scion/pkg/slayers/path" ) -// Graph implements a graph of ASes and IFIDs for testing purposes. IFIDs +// Graph implements a graph of ASes and IfIDs for testing purposes. IfIDs // must be globally unique. // // Nodes are represented by ASes. // -// Edges are represented by pairs of IFIDs. +// Edges are represented by pairs of IfIDs. type Graph struct { - // maps IFIDs to the other IFID of the edge + // maps IfIDs to the other IfID of the edge links map[uint16]uint16 - // specifies whether an IFID is on a peering link + // specifies whether an IfID is on a peering link isPeer map[uint16]bool - // maps IFIDs to the AS they belong to + // maps IfIDs to the AS they belong to parents map[uint16]addr.IA - // maps ASes to a structure containing a slice of their IFIDs + // maps ASes to a structure containing a slice of their IfIDs ases map[addr.IA]*AS signers map[addr.IA]*Signer @@ -89,7 +89,7 @@ func NewFromDescription(ctrl *gomock.Controller, desc *Description) *Graph { graph.Add(node) } for _, edge := range desc.Edges { - graph.AddLink(edge.Xia, edge.Xifid, edge.Yia, edge.Yifid, edge.Peer) + graph.AddLink(edge.Xia, edge.XifID, edge.Yia, edge.YifID, edge.Peer) } return graph } @@ -101,7 +101,7 @@ func (g *Graph) Add(ia string) { defer g.lock.Unlock() isdas := MustParseIA(ia) g.ases[isdas] = &AS{ - IFIDs: make(map[uint16]struct{}), + IfIDs: make(map[uint16]struct{}), } g.signers[isdas] = NewSigner( WithIA(isdas), @@ -121,10 +121,10 @@ func (g *Graph) GetSigner(ia string) *Signer { } // AddLink adds a new edge between the ASes described by xIA and yIA, with -// xIFID in xIA and yIFID in yIA. If xIA or yIA are not valid string +// xIfID in xIA and yIfID in yIA. If xIA or yIA are not valid string // representations of an ISD-AS, AddLink panics. -func (g *Graph) AddLink(xIA string, xIFID uint16, - yIA string, yIFID uint16, peer bool) { +func (g *Graph) AddLink(xIA string, xIfID uint16, + yIA string, yIfID uint16, peer bool) { g.lock.Lock() defer g.lock.Unlock() @@ -136,45 +136,45 @@ func (g *Graph) AddLink(xIA string, xIFID uint16, if _, ok := g.ases[y]; !ok { panic(fmt.Sprintf("AS %s not in graph", yIA)) } - if _, ok := g.links[xIFID]; ok { - panic(fmt.Sprintf("IFID %d is not unique", xIFID)) + if _, ok := g.links[xIfID]; ok { + panic(fmt.Sprintf("IfID %d is not unique", xIfID)) } - if _, ok := g.links[yIFID]; ok { - panic(fmt.Sprintf("IFID %d is not unique", yIFID)) + if _, ok := g.links[yIfID]; ok { + panic(fmt.Sprintf("IfID %d is not unique", yIfID)) } - g.links[xIFID] = yIFID - g.links[yIFID] = xIFID - g.isPeer[xIFID] = peer - g.isPeer[yIFID] = peer - g.parents[xIFID] = x - g.parents[yIFID] = y - g.ases[x].IFIDs[xIFID] = struct{}{} - g.ases[y].IFIDs[yIFID] = struct{}{} + g.links[xIfID] = yIfID + g.links[yIfID] = xIfID + g.isPeer[xIfID] = peer + g.isPeer[yIfID] = peer + g.parents[xIfID] = x + g.parents[yIfID] = y + g.ases[x].IfIDs[xIfID] = struct{}{} + g.ases[y].IfIDs[yIfID] = struct{}{} } -// RemoveLink deletes the edge containing ifid from the graph. -func (g *Graph) RemoveLink(ifid uint16) { +// RemoveLink deletes the edge containing ifID from the graph. +func (g *Graph) RemoveLink(ifID uint16) { g.lock.Lock() defer g.lock.Unlock() - ia := g.parents[ifid] - neighborIFID := g.links[ifid] - neighborIA := g.parents[neighborIFID] - - delete(g.links, ifid) - delete(g.links, neighborIFID) - delete(g.isPeer, ifid) - delete(g.isPeer, neighborIFID) - delete(g.parents, ifid) - delete(g.parents, neighborIFID) - g.ases[ia].Delete(ifid) - g.ases[neighborIA].Delete(neighborIFID) -} - -// GetParent returns the parent AS of ifid. -func (g *Graph) GetParent(ifid uint16) addr.IA { + ia := g.parents[ifID] + neighborIfID := g.links[ifID] + neighborIA := g.parents[neighborIfID] + + delete(g.links, ifID) + delete(g.links, neighborIfID) + delete(g.isPeer, ifID) + delete(g.isPeer, neighborIfID) + delete(g.parents, ifID) + delete(g.parents, neighborIfID) + g.ases[ia].Delete(ifID) + g.ases[neighborIA].Delete(neighborIfID) +} + +// GetParent returns the parent AS of ifID. +func (g *Graph) GetParent(ifID uint16) addr.IA { g.lock.Lock() defer g.lock.Unlock() - return g.parents[ifid] + return g.parents[ifID] } // GetPaths returns all the minimum-length paths. If xIA = yIA, a 1-length @@ -215,15 +215,15 @@ func (g *Graph) GetPaths(xIA string, yIA string) [][]uint16 { } // Explore neighboring ASes, if not visited yet. - for ifid := range g.ases[curSolution.CurrentIA].IFIDs { - nextIFID := g.links[ifid] - nextIA := g.parents[nextIFID] + for ifID := range g.ases[curSolution.CurrentIA].IfIDs { + nextIfID := g.links[ifID] + nextIA := g.parents[nextIfID] if curSolution.Visited(nextIA) { continue } // Copy to avoid mutating the trails of other explorations. nextTrail := curSolution.Copy() - nextTrail.Add(ifid, nextIFID, nextIA) + nextTrail.Add(ifID, nextIfID, nextIA) nextTrail.CurrentIA = nextIA queue = append(queue, nextTrail) } @@ -231,35 +231,35 @@ func (g *Graph) GetPaths(xIA string, yIA string) [][]uint16 { return solution } -// Beacon constructs path segments across a series of egress ifids. The parent -// AS of the first IFID is the origin of the beacon, and the beacon propagates -// down to the parent AS of the remote counterpart of the last IFID. The +// Beacon constructs path segments across a series of egress ifIDs. The parent +// AS of the first IfID is the origin of the beacon, and the beacon propagates +// down to the parent AS of the remote counterpart of the last IfID. The // constructed segment includes peering links. The hop fields in the returned // segment do not contain valid MACs. -func (g *Graph) Beacon(ifids []uint16) *seg.PathSegment { - return g.beacon(ifids, false) +func (g *Graph) Beacon(ifIDs []uint16) *seg.PathSegment { + return g.beacon(ifIDs, false) } -func (g *Graph) BeaconWithStaticInfo(ifids []uint16) *seg.PathSegment { - return g.beacon(ifids, true) +func (g *Graph) BeaconWithStaticInfo(ifIDs []uint16) *seg.PathSegment { + return g.beacon(ifIDs, true) } -// beacon constructs path segments across a series of egress ifids. The parent -// AS of the first IFID is the origin of the beacon, and the beacon propagates -// down to the parent AS of the remote counterpart of the last IFID. The +// beacon constructs path segments across a series of egress ifIDs. The parent +// AS of the first IfID is the origin of the beacon, and the beacon propagates +// down to the parent AS of the remote counterpart of the last IfID. The // constructed segment includes peering links. The hop fields in the returned // segment do not contain valid MACs. -func (g *Graph) beacon(ifids []uint16, addStaticInfo bool) *seg.PathSegment { +func (g *Graph) beacon(ifIDs []uint16, addStaticInfo bool) *seg.PathSegment { var inIF, outIF, remoteOutIF uint16 var currIA, outIA addr.IA var segment *seg.PathSegment - if len(ifids) == 0 { + if len(ifIDs) == 0 { return segment } - if _, ok := g.parents[ifids[0]]; !ok { - panic(fmt.Sprintf("%d unknown ifid", ifids[0])) + if _, ok := g.parents[ifIDs[0]]; !ok { + panic(fmt.Sprintf("%d unknown ifID", ifIDs[0])) } segment, err := seg.CreateSegment(time.Now(), uint16(rand.Int())) @@ -267,17 +267,17 @@ func (g *Graph) beacon(ifids []uint16, addStaticInfo bool) *seg.PathSegment { panic(err) } - currIA = g.parents[ifids[0]] - for i := 0; i <= len(ifids); i++ { + currIA = g.parents[ifIDs[0]] + for i := 0; i <= len(ifIDs); i++ { switch { - case i < len(ifids): + case i < len(ifIDs): var ok bool - outIF = ifids[i] + outIF = ifIDs[i] if remoteOutIF, ok = g.links[outIF]; !ok { - panic(fmt.Sprintf("%d unknown ifid", outIF)) + panic(fmt.Sprintf("%d unknown ifID", outIF)) } outIA = g.parents[remoteOutIF] - case i == len(ifids): + case i == len(ifIDs): outIF = 0 remoteOutIF = 0 outIA = 0 @@ -302,14 +302,14 @@ func (g *Graph) beacon(ifids []uint16, addStaticInfo bool) *seg.PathSegment { as := g.ases[currIA] // use int to avoid implementing sort.Interface - var ifids []int - for peeringLocalIF := range as.IFIDs { - ifids = append(ifids, int(peeringLocalIF)) + var ifIDs []int + for peeringLocalIF := range as.IfIDs { + ifIDs = append(ifIDs, int(peeringLocalIF)) } - sort.Ints(ifids) + sort.Ints(ifIDs) - for _, intIFID := range ifids { - peeringLocalIF := uint16(intIFID) + for _, intIfID := range ifIDs { + peeringLocalIF := uint16(intIfID) if g.isPeer[peeringLocalIF] { peeringRemoteIF := g.links[peeringLocalIF] asEntry.PeerEntries = append(asEntry.PeerEntries, seg.PeerEntry{ @@ -337,10 +337,10 @@ func (g *Graph) beacon(ifids []uint16, addStaticInfo bool) *seg.PathSegment { return segment } -// DeleteInterface removes ifid from the graph without deleting its remote -// counterpart. This is useful for testing IFID misconfigurations. -func (g *Graph) DeleteInterface(ifid uint16) { - delete(g.links, ifid) +// DeleteInterface removes ifID from the graph without deleting its remote +// counterpart. This is useful for testing IfID misconfigurations. +func (g *Graph) DeleteInterface(ifID uint16) { + delete(g.links, ifID) } // Latency returns an arbitrary test latency value between two interfaces. The @@ -373,15 +373,15 @@ func (g *Graph) Bandwidth(a, b uint16) uint64 { } // GeoCoordinates returns an arbitrary test GeoCoordinate for the interface -func (g *Graph) GeoCoordinates(ifid uint16) staticinfo.GeoCoordinates { - ia, ok := g.parents[ifid] +func (g *Graph) GeoCoordinates(ifID uint16) staticinfo.GeoCoordinates { + ia, ok := g.parents[ifID] if !ok { panic("unknown interface") } return staticinfo.GeoCoordinates{ - Latitude: float32(ifid), - Longitude: float32(ifid), - Address: fmt.Sprintf("Location %s#%d", ia, ifid), + Latitude: float32(ifID), + Longitude: float32(ifID), + Address: fmt.Sprintf("Location %s#%d", ia, ifID), } } @@ -478,8 +478,8 @@ func (s Signer) Sign(ctx context.Context, msg []byte, id := &cppb.VerificationKeyID{ IsdAs: uint64(s.IA), - TrcBase: uint64(s.TRCID.Base), - TrcSerial: uint64(s.TRCID.Serial), + TrcBase: uint64(s.TRCID.Base), // nolint - name from published protobuf + TrcSerial: uint64(s.TRCID.Serial), // nolint - name from published protobuf SubjectKeyId: skid, } rawID, err := proto.Marshal(id) @@ -497,17 +497,17 @@ func (s Signer) Sign(ctx context.Context, msg []byte, return signed.Sign(hdr, msg, s.PrivateKey, associatedData...) } -// AS contains a list of all the IFIDs in an AS. +// AS contains a list of all the IfIDs in an AS. type AS struct { - IFIDs map[uint16]struct{} + IfIDs map[uint16]struct{} } -// Delete removes ifid from as. -func (as *AS) Delete(ifid uint16) { - if _, ok := as.IFIDs[ifid]; !ok { - panic("ifid not found") +// Delete removes ifID from as. +func (as *AS) Delete(ifID uint16) { + if _, ok := as.IfIDs[ifID]; !ok { + panic("ifID not found") } - delete(as.IFIDs, ifid) + delete(as.IfIDs, ifID) } // solution tracks the state of a candidate solution for the graph @@ -517,7 +517,7 @@ type solution struct { CurrentIA addr.IA // whether the AS has already been visited by this path, to avoid loops visited map[addr.IA]struct{} - // the trail of IFIDs + // the trail of IfIDs trail []uint16 } @@ -547,10 +547,10 @@ func (s *solution) Visited(ia addr.IA) bool { return ok } -// Add appends localIFID and nextIFID to the trail, and advances to nextIA. -func (s *solution) Add(localIFID, nextIFID uint16, nextIA addr.IA) { +// Add appends localIfID and nextIfID to the trail, and advances to nextIA. +func (s *solution) Add(localIfID, nextIfID uint16, nextIA addr.IA) { s.visited[nextIA] = struct{}{} - s.trail = append(s.trail, localIFID, nextIFID) + s.trail = append(s.trail, localIfID, nextIfID) } func (s *solution) Len() int { @@ -575,9 +575,9 @@ type Description struct { // EdgeDesc is used in Descriptions to describe the links between ASes. type EdgeDesc struct { Xia string - Xifid uint16 + XifID uint16 Yia string - Yifid uint16 + YifID uint16 Peer bool } @@ -603,55 +603,55 @@ func generateStaticInfo(g *Graph, ia addr.IA, inIF, outIF uint16) *staticinfo.Ex latency := staticinfo.LatencyInfo{} if outIF != 0 { - latency.Intra = make(map[common.IFIDType]time.Duration) - latency.Inter = make(map[common.IFIDType]time.Duration) - for ifid := range as.IFIDs { - if ifid != outIF { + latency.Intra = make(map[common.IfIDType]time.Duration) + latency.Inter = make(map[common.IfIDType]time.Duration) + for ifID := range as.IfIDs { + if ifID != outIF { // Note: the test graph does not distinguish between parent/child or // core interfaces. // Otherwise, we could skip the parent interfaces and half of the // sibling interfaces here. - latency.Intra[common.IFIDType(ifid)] = g.Latency(ifid, outIF) + latency.Intra[common.IfIDType(ifID)] = g.Latency(ifID, outIF) } - if ifid == outIF || g.isPeer[ifid] { - latency.Inter[common.IFIDType(ifid)] = g.Latency(ifid, g.links[ifid]) + if ifID == outIF || g.isPeer[ifID] { + latency.Inter[common.IfIDType(ifID)] = g.Latency(ifID, g.links[ifID]) } } } bandwidth := staticinfo.BandwidthInfo{} if outIF != 0 { - bandwidth.Intra = make(map[common.IFIDType]uint64) - bandwidth.Inter = make(map[common.IFIDType]uint64) - for ifid := range as.IFIDs { - if ifid != outIF { - bandwidth.Intra[common.IFIDType(ifid)] = g.Bandwidth(ifid, outIF) + bandwidth.Intra = make(map[common.IfIDType]uint64) + bandwidth.Inter = make(map[common.IfIDType]uint64) + for ifID := range as.IfIDs { + if ifID != outIF { + bandwidth.Intra[common.IfIDType(ifID)] = g.Bandwidth(ifID, outIF) } - if ifid == outIF || g.isPeer[ifid] { - bandwidth.Inter[common.IFIDType(ifid)] = g.Bandwidth(ifid, g.links[ifid]) + if ifID == outIF || g.isPeer[ifID] { + bandwidth.Inter[common.IfIDType(ifID)] = g.Bandwidth(ifID, g.links[ifID]) } } } geo := make(staticinfo.GeoInfo) - for ifid := range as.IFIDs { - geo[common.IFIDType(ifid)] = g.GeoCoordinates(ifid) + for ifID := range as.IfIDs { + geo[common.IfIDType(ifID)] = g.GeoCoordinates(ifID) } linkType := make(staticinfo.LinkTypeInfo) - for ifid := range as.IFIDs { - linkType[common.IFIDType(ifid)] = g.LinkType(ifid, g.links[ifid]) + for ifID := range as.IfIDs { + linkType[common.IfIDType(ifID)] = g.LinkType(ifID, g.links[ifID]) } var internalHops staticinfo.InternalHopsInfo if outIF != 0 { - internalHops = make(map[common.IFIDType]uint32) + internalHops = make(map[common.IfIDType]uint32) if inIF != 0 { - internalHops[common.IFIDType(inIF)] = g.InternalHops(inIF, outIF) + internalHops[common.IfIDType(inIF)] = g.InternalHops(inIF, outIF) } - for ifid := range as.IFIDs { - if ifid != outIF && ifid != inIF { - internalHops[common.IFIDType(ifid)] = g.InternalHops(ifid, outIF) + for ifID := range as.IfIDs { + if ifID != outIF && ifID != inIF { + internalHops[common.IfIDType(ifID)] = g.InternalHops(ifID, outIF) } } } diff --git a/pkg/segment/extensions/staticinfo/staticinfo.go b/pkg/segment/extensions/staticinfo/staticinfo.go index 12d6089d9b..83c7073151 100644 --- a/pkg/segment/extensions/staticinfo/staticinfo.go +++ b/pkg/segment/extensions/staticinfo/staticinfo.go @@ -39,20 +39,20 @@ type Extension struct { // LatencyInfo is the internal repesentation of `latency` in the // StaticInfoExtension. type LatencyInfo struct { - Intra map[common.IFIDType]time.Duration - Inter map[common.IFIDType]time.Duration + Intra map[common.IfIDType]time.Duration + Inter map[common.IfIDType]time.Duration } // BandwidthInfo is the internal repesentation of `bandwidth` in the // StaticInfoExtension. type BandwidthInfo struct { - Intra map[common.IFIDType]uint64 - Inter map[common.IFIDType]uint64 + Intra map[common.IfIDType]uint64 + Inter map[common.IfIDType]uint64 } // GeoInfo is the internal repesentation of `geo` in the // StaticInfoExtension. -type GeoInfo map[common.IFIDType]GeoCoordinates +type GeoInfo map[common.IfIDType]GeoCoordinates // GeoCoordinates is the internal repesentation of the GeoCoordinates in the // StaticInfoExtension. @@ -76,11 +76,11 @@ const ( // LinkTypeInfo is the internal representation of `link_type` in the // StaticInfoExtension. -type LinkTypeInfo map[common.IFIDType]LinkType +type LinkTypeInfo map[common.IfIDType]LinkType // InternalHopsInfo is the internal representation of `internal_hops` in the // StaticInfoExtension. -type InternalHopsInfo map[common.IFIDType]uint32 +type InternalHopsInfo map[common.IfIDType]uint32 // FromPB creates the staticinfo Extension from the protobuf representation. func FromPB(pb *cppb.StaticInfoExtension) *Extension { @@ -101,13 +101,13 @@ func latencyInfoFromPB(pb *cppb.LatencyInfo) LatencyInfo { if pb == nil || len(pb.Intra) == 0 && len(pb.Inter) == 0 { return LatencyInfo{} } - intra := make(map[common.IFIDType]time.Duration, len(pb.Intra)) - for ifid, v := range pb.Intra { - intra[common.IFIDType(ifid)] = time.Duration(v) * time.Microsecond + intra := make(map[common.IfIDType]time.Duration, len(pb.Intra)) + for ifID, v := range pb.Intra { + intra[common.IfIDType(ifID)] = time.Duration(v) * time.Microsecond } - inter := make(map[common.IFIDType]time.Duration, len(pb.Inter)) - for ifid, v := range pb.Inter { - inter[common.IFIDType(ifid)] = time.Duration(v) * time.Microsecond + inter := make(map[common.IfIDType]time.Duration, len(pb.Inter)) + for ifID, v := range pb.Inter { + inter[common.IfIDType(ifID)] = time.Duration(v) * time.Microsecond } return LatencyInfo{ Intra: intra, @@ -119,13 +119,13 @@ func bandwidthInfoFromPB(pb *cppb.BandwidthInfo) BandwidthInfo { if pb == nil || len(pb.Intra) == 0 && len(pb.Inter) == 0 { return BandwidthInfo{} } - intra := make(map[common.IFIDType]uint64, len(pb.Intra)) - for ifid, v := range pb.Intra { - intra[common.IFIDType(ifid)] = v + intra := make(map[common.IfIDType]uint64, len(pb.Intra)) + for ifID, v := range pb.Intra { + intra[common.IfIDType(ifID)] = v } - inter := make(map[common.IFIDType]uint64, len(pb.Inter)) - for ifid, v := range pb.Inter { - inter[common.IFIDType(ifid)] = v + inter := make(map[common.IfIDType]uint64, len(pb.Inter)) + for ifID, v := range pb.Inter { + inter[common.IfIDType(ifID)] = v } return BandwidthInfo{ Intra: intra, @@ -138,8 +138,8 @@ func geoInfoFromPB(pb map[uint64]*cppb.GeoCoordinates) GeoInfo { return nil } gi := make(GeoInfo, len(pb)) - for ifid, v := range pb { - gi[common.IFIDType(ifid)] = GeoCoordinates{ + for ifID, v := range pb { + gi[common.IfIDType(ifID)] = GeoCoordinates{ Latitude: v.Latitude, Longitude: v.Longitude, Address: v.Address, @@ -153,7 +153,7 @@ func linkTypeInfoFromPB(pb map[uint64]cppb.LinkType) LinkTypeInfo { return nil } lti := make(LinkTypeInfo, len(pb)) - for ifid, vpb := range pb { + for ifID, vpb := range pb { var v LinkType switch vpb { case cppb.LinkType_LINK_TYPE_UNSPECIFIED: @@ -167,7 +167,7 @@ func linkTypeInfoFromPB(pb map[uint64]cppb.LinkType) LinkTypeInfo { default: continue } - lti[common.IFIDType(ifid)] = v + lti[common.IfIDType(ifID)] = v } return lti } @@ -177,8 +177,8 @@ func internalHopsInfoFromPB(pb map[uint64]uint32) InternalHopsInfo { return nil } ihi := make(InternalHopsInfo, len(pb)) - for ifid, v := range pb { - ihi[common.IFIDType(ifid)] = v + for ifID, v := range pb { + ihi[common.IfIDType(ifID)] = v } return ihi } @@ -204,12 +204,12 @@ func latencyInfoToPB(li LatencyInfo) *cppb.LatencyInfo { return nil } intra := make(map[uint64]uint32, len(li.Intra)) - for ifid, v := range li.Intra { - intra[uint64(ifid)] = uint32(v.Microseconds()) + for ifID, v := range li.Intra { + intra[uint64(ifID)] = uint32(v.Microseconds()) } inter := make(map[uint64]uint32, len(li.Inter)) - for ifid, v := range li.Inter { - inter[uint64(ifid)] = uint32(v.Microseconds()) + for ifID, v := range li.Inter { + inter[uint64(ifID)] = uint32(v.Microseconds()) } return &cppb.LatencyInfo{ Intra: intra, @@ -222,12 +222,12 @@ func bandwidthInfoToPB(bwi BandwidthInfo) *cppb.BandwidthInfo { return nil } intra := make(map[uint64]uint64, len(bwi.Intra)) - for ifid, v := range bwi.Intra { - intra[uint64(ifid)] = v + for ifID, v := range bwi.Intra { + intra[uint64(ifID)] = v } inter := make(map[uint64]uint64, len(bwi.Inter)) - for ifid, v := range bwi.Inter { - inter[uint64(ifid)] = v + for ifID, v := range bwi.Inter { + inter[uint64(ifID)] = v } return &cppb.BandwidthInfo{ Intra: intra, @@ -240,8 +240,8 @@ func geoInfoToPB(gi GeoInfo) map[uint64]*cppb.GeoCoordinates { return nil } pb := make(map[uint64]*cppb.GeoCoordinates, len(gi)) - for ifid, v := range gi { - pb[uint64(ifid)] = &cppb.GeoCoordinates{ + for ifID, v := range gi { + pb[uint64(ifID)] = &cppb.GeoCoordinates{ Latitude: v.Latitude, Longitude: v.Longitude, Address: v.Address, @@ -255,7 +255,7 @@ func linkTypeInfoToPB(lti LinkTypeInfo) map[uint64]cppb.LinkType { return nil } pb := make(map[uint64]cppb.LinkType, len(lti)) - for ifid, v := range lti { + for ifID, v := range lti { var vpb cppb.LinkType switch v { case LinkTypeDirect: @@ -267,7 +267,7 @@ func linkTypeInfoToPB(lti LinkTypeInfo) map[uint64]cppb.LinkType { default: continue } - pb[uint64(ifid)] = vpb + pb[uint64(ifID)] = vpb } return pb } @@ -277,8 +277,8 @@ func internalHopsInfoToPB(ihi InternalHopsInfo) map[uint64]uint32 { return nil } pb := make(map[uint64]uint32, len(ihi)) - for ifid, v := range ihi { - pb[uint64(ifid)] = v + for ifID, v := range ihi { + pb[uint64(ifID)] = v } return pb } diff --git a/pkg/segment/extensions/staticinfo/staticinfo_test.go b/pkg/segment/extensions/staticinfo/staticinfo_test.go index ba5df30c34..42c9bff6bf 100644 --- a/pkg/segment/extensions/staticinfo/staticinfo_test.go +++ b/pkg/segment/extensions/staticinfo/staticinfo_test.go @@ -34,22 +34,22 @@ func TestRoundtripStaticInfoExtension(t *testing.T) { }, "latency": { Latency: staticinfo.LatencyInfo{ - Intra: map[common.IFIDType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 10: 10 * time.Millisecond, 11: 11 * time.Millisecond, }, - Inter: map[common.IFIDType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 11: 111 * time.Millisecond, }, }, }, "bandwidth": { Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IFIDType]uint64{ + Intra: map[common.IfIDType]uint64{ 10: 1, // 1Kbit/s 11: 10_000_000_000, // 10Tbit/s }, - Inter: map[common.IFIDType]uint64{ + Inter: map[common.IfIDType]uint64{ 11: 2_000_000, }, }, @@ -71,7 +71,7 @@ func TestRoundtripStaticInfoExtension(t *testing.T) { }, }, "internal_hops": { - InternalHops: map[common.IFIDType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 10: 2, 11: 3, }, diff --git a/pkg/snet/packet_conn.go b/pkg/snet/packet_conn.go index 8e545f73ce..ef2a159f03 100644 --- a/pkg/snet/packet_conn.go +++ b/pkg/snet/packet_conn.go @@ -282,11 +282,11 @@ func (c *SCIONPacketConn) lastHop(p *Packet) (*net.UDPAddr, error) { if err := path.DecodeFromBytes(rpath.Raw); err != nil { return nil, err } - ifid := path.SecondHop.ConsIngress + ifID := path.SecondHop.ConsIngress if !path.Info.ConsDir { - ifid = path.SecondHop.ConsEgress + ifID = path.SecondHop.ConsEgress } - return c.interfaceMap.get(ifid) + return c.interfaceMap.get(ifID) case epic.PathType: var path epic.Path if err := path.DecodeFromBytes(rpath.Raw); err != nil { @@ -300,11 +300,11 @@ func (c *SCIONPacketConn) lastHop(p *Packet) (*net.UDPAddr, error) { if err != nil { return nil, err } - ifid := hf.ConsIngress + ifID := hf.ConsIngress if !infoField.ConsDir { - ifid = hf.ConsEgress + ifID = hf.ConsEgress } - return c.interfaceMap.get(ifid) + return c.interfaceMap.get(ifID) case scion.PathType: var path scion.Raw if err := path.DecodeFromBytes(rpath.Raw); err != nil { @@ -318,11 +318,11 @@ func (c *SCIONPacketConn) lastHop(p *Packet) (*net.UDPAddr, error) { if err != nil { return nil, err } - ifid := hf.ConsIngress + ifID := hf.ConsIngress if !infoField.ConsDir { - ifid = hf.ConsEgress + ifID = hf.ConsEgress } - return c.interfaceMap.get(ifid) + return c.interfaceMap.get(ifID) default: return nil, serrors.New("unknown path type", "type", rpath.PathType.String()) } diff --git a/pkg/snet/path.go b/pkg/snet/path.go index 1a19ad5760..b6c48df30f 100644 --- a/pkg/snet/path.go +++ b/pkg/snet/path.go @@ -70,7 +70,7 @@ type Path interface { // PathInterface is an interface of the path. type PathInterface struct { // ID is the ID of the interface. - ID common.IFIDType + ID common.IfIDType // IA is the ISD AS identifier of the interface. IA addr.IA } diff --git a/pkg/snet/scmp.go b/pkg/snet/scmp.go index ddbbf38268..e759d057c0 100644 --- a/pkg/snet/scmp.go +++ b/pkg/snet/scmp.go @@ -73,7 +73,7 @@ func (h DefaultSCMPHandler) Handle(pkt *Packet) error { case slayers.SCMPTypeExternalInterfaceDown: msg := pkt.Payload.(SCMPExternalInterfaceDown) return h.handleSCMPRev(typeCode, &path_mgmt.RevInfo{ - IfID: common.IFIDType(msg.Interface), + IfID: common.IfIDType(msg.Interface), RawIsdas: msg.IA, RawTimestamp: util.TimeToSecs(time.Now()), RawTTL: 10, @@ -81,7 +81,7 @@ func (h DefaultSCMPHandler) Handle(pkt *Packet) error { case slayers.SCMPTypeInternalConnectivityDown: msg := pkt.Payload.(SCMPInternalConnectivityDown) return h.handleSCMPRev(typeCode, &path_mgmt.RevInfo{ - IfID: common.IFIDType(msg.Egress), + IfID: common.IfIDType(msg.Egress), RawIsdas: msg.IA, RawTimestamp: util.TimeToSecs(time.Now()), RawTTL: 10, diff --git a/pkg/snet/squic/net_test.go b/pkg/snet/squic/net_test.go index 700a6f6189..687c53cded 100644 --- a/pkg/snet/squic/net_test.go +++ b/pkg/snet/squic/net_test.go @@ -46,9 +46,12 @@ func TestAcceptLoopParallelism(t *testing.T) { defer mctrl.Finish() handler := mock_cp.NewMockTrustMaterialServiceServer(mctrl) - handler.EXPECT().TRC(gomock.Any(), gomock.Any()).Return( + handler.EXPECT().TRC( // nolint - name from published protobuf + gomock.Any(), + gomock.Any(), + ).Return( &cppb.TRCResponse{ - Trc: make([]byte, 500), + Trc: make([]byte, 500), // nolint - name from published protobuf }, nil, ).AnyTimes() @@ -113,7 +116,7 @@ func TestGRPCQUIC(t *testing.T) { handler := mock_cp.NewMockTrustMaterialServiceServer(mctrl) handler.EXPECT().TRC(gomock.Any(), gomock.Any()).Return( &cppb.TRCResponse{ - Trc: []byte("hello"), + Trc: []byte("hello"), // nolint - name from published protobuf }, nil, ) @@ -139,7 +142,7 @@ func TestGRPCQUIC(t *testing.T) { client := cppb.NewTrustMaterialServiceClient(conn) rep, err := client.TRC(context.Background(), &cppb.TRCRequest{}) require.NoError(t, err) - assert.Equal(t, "hello", string(rep.Trc)) + assert.Equal(t, "hello", string(rep.Trc)) // nolint - name from published protobuf } func TestEstablishConnection(t *testing.T) { diff --git a/private/mgmtapi/cppki/api/api.go b/private/mgmtapi/cppki/api/api.go index cb5ecb38be..3e0c13a8e8 100644 --- a/private/mgmtapi/cppki/api/api.go +++ b/private/mgmtapi/cppki/api/api.go @@ -227,7 +227,12 @@ func (s *Server) GetCertificateBlob(w http.ResponseWriter, r *http.Request, chai _, _ = w.Write(buf.Bytes()) } -func (s *Server) GetTrcs(w http.ResponseWriter, r *http.Request, params GetTrcsParams) { +func (s *Server) GetTrcs( + w http.ResponseWriter, + r *http.Request, + params GetTrcsParams, // nolint - name from published API +) { + db := s.TrustDB q := truststorage.TRCsQuery{Latest: !(params.All != nil && *params.All)} if params.Isd != nil { @@ -279,7 +284,7 @@ func (s *Server) GetTrcs(w http.ResponseWriter, r *http.Request, params GetTrcsP } -// GetTrc gets the trc specified by it's isd bas and serial. +// GetTrc gets the trc specified by it's isd base and serial. func (s *Server) GetTrc(w http.ResponseWriter, r *http.Request, isd int, base int, serial int) { db := s.TrustDB trc, err := db.SignedTRC(r.Context(), cppki.TRCID{ diff --git a/private/path/combinator/combinator_test.go b/private/path/combinator/combinator_test.go index c1a6495b50..15bb1b6d4e 100644 --- a/private/path/combinator/combinator_test.go +++ b/private/path/combinator/combinator_test.go @@ -547,20 +547,20 @@ func TestFilterDuplicates(t *testing.T) { // These look somewhat valid, but that doesn't matter at all -- we only look // at the fingerprint anyway. path0 := []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IFIDType(10)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IFIDType(10)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(10)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(10)}, } path1 := []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IFIDType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IFIDType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IFIDType(12)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IFIDType(12)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(12)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(12)}, } path2 := []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IFIDType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IFIDType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IFIDType(22)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IFIDType(22)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(22)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(22)}, } // Define two expiry times for the paths: paths with latest expiry will be kept diff --git a/private/path/combinator/graph.go b/private/path/combinator/graph.go index cfb1e71603..447c2a97bc 100644 --- a/private/path/combinator/graph.go +++ b/private/path/combinator/graph.go @@ -50,7 +50,7 @@ type vertexInfo map[vertex]edgeMap // dmg is a Directed Multigraph. // // Vertices are either ASes (identified by their ISD-AS number) or peering -// links (identified by the the ISD-AS numbers of the peers, and the IFIDs on +// links (identified by the the ISD-AS numbers of the peers, and the IfIDs on // the peering link). type dmg struct { Adjacencies map[vertex]vertexInfo @@ -146,8 +146,8 @@ func (g *dmg) traverseSegment(segment *inputSegment) { } for peerEntryIdx, peer := range asEntries[asEntryIndex].PeerEntries { - ingress := common.IFIDType(peer.HopField.ConsIngress) - remote := common.IFIDType(peer.PeerInterface) + ingress := common.IfIDType(peer.HopField.ConsIngress) + remote := common.IfIDType(peer.PeerInterface) tuples = append(tuples, Tuple{ Src: vertexFromIA(pinnedIA), Dst: vertexFromPeering(currentIA, ingress, peer.Peer, remote), @@ -259,25 +259,25 @@ func (s *inputSegment) IsDownSeg() bool { type vertex struct { IA addr.IA UpIA addr.IA - UpIFID common.IFIDType + UpIfID common.IfIDType DownIA addr.IA - DownIFID common.IFIDType + DownIfID common.IfIDType } func vertexFromIA(ia addr.IA) vertex { return vertex{IA: ia} } -func vertexFromPeering(upIA addr.IA, upIFID common.IFIDType, - downIA addr.IA, downIFID common.IFIDType) vertex { +func vertexFromPeering(upIA addr.IA, upIfID common.IfIDType, + downIA addr.IA, downIfID common.IfIDType) vertex { - return vertex{UpIA: upIA, UpIFID: upIFID, DownIA: downIA, DownIFID: downIFID} + return vertex{UpIA: upIA, UpIfID: upIfID, DownIA: downIA, DownIfID: downIfID} } // Reverse returns a new vertex that contains the peering information in // reverse. AS vertices remain unchanged. func (v vertex) Reverse() vertex { - return vertex{IA: v.IA, UpIA: v.DownIA, UpIFID: v.DownIFID, DownIA: v.UpIA, DownIFID: v.UpIFID} + return vertex{IA: v.IA, UpIA: v.DownIA, UpIfID: v.DownIfID, DownIA: v.UpIA, DownIfID: v.UpIfID} } // edgeMap is used to keep the set of edges going from one vertex to another. @@ -365,14 +365,14 @@ func (solution *pathSolution) Path() Path { if hopField.ConsEgress != 0 { intfs = append(intfs, snet.PathInterface{ IA: asEntry.Local, - ID: common.IFIDType(hopField.ConsEgress), + ID: common.IfIDType(hopField.ConsEgress), }) } // In a non-peer shortcut the AS is not traversed completely. if hopField.ConsIngress != 0 && (!isShortcut || isPeer) { intfs = append(intfs, snet.PathInterface{ IA: asEntry.Local, - ID: common.IFIDType(hopField.ConsIngress), + ID: common.IfIDType(hopField.ConsIngress), }) } hops = append(hops, hopField) diff --git a/private/path/combinator/staticinfo_accumulator.go b/private/path/combinator/staticinfo_accumulator.go index f2f7501f39..383bead4e0 100644 --- a/private/path/combinator/staticinfo_accumulator.go +++ b/private/path/combinator/staticinfo_accumulator.go @@ -85,17 +85,17 @@ func collectLatency(p pathInfo) []time.Duration { } egIF := snet.PathInterface{ IA: asEntry.Local, - ID: common.IFIDType(asEntry.HopEntry.HopField.ConsEgress), + ID: common.IfIDType(asEntry.HopEntry.HopField.ConsEgress), } latency := staticInfo.Latency // Egress to sibling child, core or peer interfaces - for ifid, v := range latency.Intra { - otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifid} + for ifID, v := range latency.Intra { + otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopLatency(hopLatencies, egIF, otherIF, v) } // Local peer to remote peer interface - for ifid, v := range latency.Inter { - localIF := snet.PathInterface{IA: asEntry.Local, ID: ifid} + for ifID, v := range latency.Inter { + localIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopLatency(hopLatencies, localIF, p.RemoteIF[localIF], v) } } @@ -140,17 +140,17 @@ func collectBandwidth(p pathInfo) []uint64 { } egIF := snet.PathInterface{ IA: asEntry.Local, - ID: common.IFIDType(asEntry.HopEntry.HopField.ConsEgress), + ID: common.IfIDType(asEntry.HopEntry.HopField.ConsEgress), } bandwidth := staticInfo.Bandwidth // Egress to other local interfaces - for ifid, v := range bandwidth.Intra { - otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifid} + for ifID, v := range bandwidth.Intra { + otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopBandwidth(hopBandwidths, egIF, otherIF, v) } // Local peer to remote peer interface - for ifid, v := range bandwidth.Inter { - localIF := snet.PathInterface{IA: asEntry.Local, ID: ifid} + for ifID, v := range bandwidth.Inter { + localIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopBandwidth(hopBandwidths, localIF, p.RemoteIF[localIF], v) } } @@ -187,8 +187,8 @@ func collectGeo(p pathInfo) []snet.GeoCoordinates { if staticInfo == nil { continue } - for ifid, v := range staticInfo.Geo { - iface := snet.PathInterface{IA: asEntry.Local, ID: ifid} + for ifID, v := range staticInfo.Geo { + iface := snet.PathInterface{IA: asEntry.Local, ID: ifID} ifaceGeos[iface] = snet.GeoCoordinates{ Longitude: v.Longitude, Latitude: v.Latitude, @@ -213,9 +213,9 @@ func collectLinkType(p pathInfo) []snet.LinkType { if staticInfo == nil { continue } - for ifid, rawLinkType := range staticInfo.LinkType { + for ifID, rawLinkType := range staticInfo.LinkType { linkType := convertLinkType(rawLinkType) - localIF := snet.PathInterface{IA: asEntry.Local, ID: ifid} + localIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} hop := makeHopKey(localIF, p.RemoteIF[localIF]) if prevLinkType, duplicate := hopLinkTypes[hop]; duplicate { // Handle conflicts by using LinkTypeUnset @@ -265,11 +265,11 @@ func collectInternalHops(p pathInfo) []uint32 { } egIF := snet.PathInterface{ IA: asEntry.Local, - ID: common.IFIDType(asEntry.HopEntry.HopField.ConsEgress), + ID: common.IfIDType(asEntry.HopEntry.HopField.ConsEgress), } internalHops := staticInfo.InternalHops - for ifid, v := range internalHops { - otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifid} + for ifID, v := range internalHops { + otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopInternalHops(hopInternalHops, egIF, otherIF, v) } } diff --git a/private/path/combinator/staticinfo_accumulator_test.go b/private/path/combinator/staticinfo_accumulator_test.go index 491ff6e0c3..1bfe056356 100644 --- a/private/path/combinator/staticinfo_accumulator_test.go +++ b/private/path/combinator/staticinfo_accumulator_test.go @@ -42,12 +42,12 @@ func TestStaticinfo(t *testing.T) { { Name: "#0 simple up-core-down", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IFIDType(graph.If_131_X_130_A)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IFIDType(graph.If_130_A_131_X)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IFIDType(graph.If_130_B_120_A)}, - {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IFIDType(graph.If_120_A_130_B)}, - {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IFIDType(graph.If_120_X_111_B)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IFIDType(graph.If_111_B_120_X)}, + {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIDType(graph.If_131_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_131_X)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_B_120_A)}, + {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IfIDType(graph.If_120_A_130_B)}, + {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IfIDType(graph.If_120_X_111_B)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(graph.If_111_B_120_X)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_130_A_131_X}, @@ -58,10 +58,10 @@ func TestStaticinfo(t *testing.T) { { Name: "#1 simple up-core", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IFIDType(graph.If_131_X_130_A)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IFIDType(graph.If_130_A_131_X)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IFIDType(graph.If_130_A_110_X)}, - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IFIDType(graph.If_110_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIDType(graph.If_131_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_131_X)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_110_X)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(graph.If_110_X_130_A)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_130_A_131_X}, @@ -72,8 +72,8 @@ func TestStaticinfo(t *testing.T) { { Name: "#2 simple up only", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IFIDType(graph.If_131_X_130_A)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IFIDType(graph.If_130_A_131_X)}, + {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIDType(graph.If_131_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_131_X)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_130_A_131_X}, @@ -84,10 +84,10 @@ func TestStaticinfo(t *testing.T) { { Name: "#14 shortcut, common upstream", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IFIDType(graph.If_212_X_211_A1)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IFIDType(graph.If_211_A1_212_X)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IFIDType(graph.If_211_A_222_X)}, - {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IFIDType(graph.If_222_X_211_A)}, + {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IfIDType(graph.If_212_X_211_A1)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A1_212_X)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A_222_X)}, + {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IfIDType(graph.If_222_X_211_A)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_210_X1_211_A, graph.If_211_A1_212_X}, @@ -98,12 +98,12 @@ func TestStaticinfo(t *testing.T) { { Name: "#15 go through peer", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IFIDType(graph.If_212_X_211_A1)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IFIDType(graph.If_211_A1_212_X)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IFIDType(graph.If_211_A_221_X)}, - {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IFIDType(graph.If_221_X_211_A)}, - {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IFIDType(graph.If_221_X_222_X)}, - {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IFIDType(graph.If_222_X_221_X)}, + {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IfIDType(graph.If_212_X_211_A1)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A1_212_X)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A_221_X)}, + {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IfIDType(graph.If_221_X_211_A)}, + {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IfIDType(graph.If_221_X_222_X)}, + {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IfIDType(graph.If_222_X_221_X)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_210_X1_211_A, graph.If_211_A1_212_X}, @@ -231,8 +231,8 @@ func concatBeaconASEntries(g *graph.Graph, upIfIDs, coreIfIDs, downIfIDs []uint16) []seg.ASEntry { r := []seg.ASEntry{} - for _, ifids := range [][]uint16{upIfIDs, coreIfIDs, downIfIDs} { - seg := g.BeaconWithStaticInfo(ifids) + for _, ifIDs := range [][]uint16{upIfIDs, coreIfIDs, downIfIDs} { + seg := g.BeaconWithStaticInfo(ifIDs) if seg != nil { r = append(r, seg.ASEntries...) } diff --git a/private/path/pathpol/acl_test.go b/private/path/pathpol/acl_test.go index 1fe86cfb2b..1bdb412832 100644 --- a/private/path/pathpol/acl_test.go +++ b/private/path/pathpol/acl_test.go @@ -113,7 +113,7 @@ func TestACLEntryLoadFromString(t *testing.T) { String: "+ 0", ACLEntry: ACLEntry{ Action: Allow, - Rule: &HopPredicate{IfIDs: []common.IFIDType{0}}, + Rule: &HopPredicate{IfIDs: []common.IfIDType{0}}, }, ErrorAssertion: assert.NoError, }, @@ -121,7 +121,7 @@ func TestACLEntryLoadFromString(t *testing.T) { String: "+ 1-2#3", ACLEntry: ACLEntry{ Action: Allow, - Rule: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IFIDType{3}}, + Rule: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{3}}, }, ErrorAssertion: assert.NoError, }, @@ -134,7 +134,7 @@ func TestACLEntryLoadFromString(t *testing.T) { String: "- 0", ACLEntry: ACLEntry{ Action: Deny, - Rule: &HopPredicate{IfIDs: []common.IFIDType{0}}, + Rule: &HopPredicate{IfIDs: []common.IfIDType{0}}, }, ErrorAssertion: assert.NoError, }, @@ -161,7 +161,7 @@ func TestACLEntryLoadFromString(t *testing.T) { func TestACLEntryString(t *testing.T) { aclEntryString := "+ 0-0#0" - aclEntry := &ACLEntry{Action: true, Rule: &HopPredicate{IfIDs: []common.IFIDType{0}}} + aclEntry := &ACLEntry{Action: true, Rule: &HopPredicate{IfIDs: []common.IfIDType{0}}} assert.Equal(t, aclEntryString, aclEntry.String()) } diff --git a/private/path/pathpol/hop_pred.go b/private/path/pathpol/hop_pred.go index 41881390c1..d1159b071c 100644 --- a/private/path/pathpol/hop_pred.go +++ b/private/path/pathpol/hop_pred.go @@ -32,11 +32,11 @@ import ( type HopPredicate struct { ISD addr.ISD AS addr.AS - IfIDs []common.IFIDType + IfIDs []common.IfIDType } func NewHopPredicate() *HopPredicate { - return &HopPredicate{IfIDs: make([]common.IFIDType, 1)} + return &HopPredicate{IfIDs: make([]common.IfIDType, 1)} } func HopPredicateFromString(str string) (*HopPredicate, error) { @@ -44,7 +44,7 @@ func HopPredicateFromString(str string) (*HopPredicate, error) { if err = validateHopPredStr(str); err != nil { return &HopPredicate{}, err } - var ifIDs = make([]common.IFIDType, 1) + var ifIDs = make([]common.IfIDType, 1) // Parse ISD dashParts := strings.Split(str, "-") isd, err := addr.ParseISD(dashParts[0]) @@ -66,12 +66,12 @@ func HopPredicateFromString(str string) (*HopPredicate, error) { // Parse IfIDs if present commaParts := strings.Split(hashParts[1], ",") if ifIDs[0], err = parseIfID(commaParts[0]); err != nil { - return &HopPredicate{}, serrors.WrapStr("Failed to parse ifids", err, "value", str) + return &HopPredicate{}, serrors.WrapStr("Failed to parse ifIDs", err, "value", str) } if len(commaParts) == 2 { ifID, err := parseIfID(commaParts[1]) if err != nil { - return &HopPredicate{}, serrors.WrapStr("Failed to parse ifids", err, "value", str) + return &HopPredicate{}, serrors.WrapStr("Failed to parse ifIDs", err, "value", str) } ifIDs = append(ifIDs, ifID) } @@ -115,8 +115,8 @@ func (hp *HopPredicate) matchesAll() bool { func (hp HopPredicate) String() string { var s []string - for _, ifid := range hp.IfIDs { - s = append(s, ifid.String()) + for _, ifID := range hp.IfIDs { + s = append(s, ifID.String()) } return fmt.Sprintf("%d-%s#%s", hp.ISD, hp.AS, strings.Join(s, ",")) } @@ -136,12 +136,12 @@ func (hp *HopPredicate) UnmarshalJSON(b []byte) error { return err } -func parseIfID(str string) (common.IFIDType, error) { - ifid, err := strconv.ParseUint(str, 10, 64) +func parseIfID(str string) (common.IfIDType, error) { + ifID, err := strconv.ParseUint(str, 10, 64) if err != nil { return 0, err } - return common.IFIDType(ifid), nil + return common.IfIDType(ifID), nil } // validateHopPredStr checks if str has the correct amount of delimiters diff --git a/private/path/pathpol/hop_pred_test.go b/private/path/pathpol/hop_pred_test.go index 15897182b7..fa2cd76e70 100644 --- a/private/path/pathpol/hop_pred_test.go +++ b/private/path/pathpol/hop_pred_test.go @@ -32,22 +32,22 @@ func TestNewHopPredicate(t *testing.T) { }{ "ISD wildcard": { In: "0", - HP: &HopPredicate{ISD: 0, AS: 0, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 0, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "AS, IF wildcard omitted": { In: "1", - HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "IF wildcard omitted": { In: "1-0", - HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "basic wildcard": { In: "1-0#0", - HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "AS wildcard, interface set": { @@ -56,27 +56,27 @@ func TestNewHopPredicate(t *testing.T) { }, "ISD wildcard, AS set": { In: "0-1#0", - HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IfIDType{0}}, Valid: true, }, "ISD wildcard, AS set, interface set": { In: "0-1#2", - HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IFIDType{2}}, + HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IfIDType{2}}, Valid: true, }, "ISD wildcard, AS set and interface omitted": { In: "0-1", - HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IfIDType{0}}, Valid: true, }, "IF wildcard omitted, AS set": { In: "1-2", - HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{0}}, Valid: true, }, "two IfIDs": { In: "1-2#3,4", - HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IFIDType{3, 4}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{3, 4}}, Valid: true, }, "three IfIDs": { @@ -140,13 +140,13 @@ func TestJsonConversion(t *testing.T) { HP *HopPredicate }{ "Normal predicate": { - HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IFIDType{1, 2}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{1, 2}}, }, "wildcard predicate": { - HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IFIDType{0}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{0}}, }, - "only ifids": { - HP: &HopPredicate{IfIDs: []common.IFIDType{0}}, + "only ifIDs": { + HP: &HopPredicate{IfIDs: []common.IfIDType{0}}, }, } for name, test := range tests { diff --git a/private/path/pathpol/policy_test.go b/private/path/pathpol/policy_test.go index 61f7392aad..5e07e38508 100644 --- a/private/path/pathpol/policy_test.go +++ b/private/path/pathpol/policy_test.go @@ -642,13 +642,13 @@ func NewPathProvider(ctrl *gomock.Controller) PathProvider { func (p PathProvider) GetPaths(src, dst addr.IA) []snet.Path { result := []snet.Path{} paths := p.g.GetPaths(src.String(), dst.String()) - for _, ifids := range paths { - pathIntfs := make([]snet.PathInterface, 0, len(ifids)) - for _, ifid := range ifids { - ia := p.g.GetParent(ifid) + for _, ifIDs := range paths { + pathIntfs := make([]snet.PathInterface, 0, len(ifIDs)) + for _, ifID := range ifIDs { + ia := p.g.GetParent(ifID) pathIntfs = append(pathIntfs, snet.PathInterface{ IA: ia, - ID: common.IFIDType(ifid), + ID: common.IfIDType(ifID), }) } var srcIA, dstIA addr.IA diff --git a/private/path/pathpol/sequence.go b/private/path/pathpol/sequence.go index bf9ae6bcfe..011bb2e088 100644 --- a/private/path/pathpol/sequence.go +++ b/private/path/pathpol/sequence.go @@ -293,7 +293,7 @@ func (l *sequenceListener) ExitIFace(c *sequence.IFaceContext) { l.push(re) } -func hop(ia addr.IA, ingress, egress common.IFIDType) string { +func hop(ia addr.IA, ingress, egress common.IfIDType) string { return fmt.Sprintf("%s#%d,%d", ia, ingress, egress) } diff --git a/private/pathdb/query/query.go b/private/pathdb/query/query.go index 5abe6ec09f..d8013fb606 100644 --- a/private/pathdb/query/query.go +++ b/private/pathdb/query/query.go @@ -26,7 +26,7 @@ import ( type IntfSpec struct { IA addr.IA - IfID common.IFIDType + IfID common.IfIDType } type Params struct { diff --git a/private/revcache/revcache.go b/private/revcache/revcache.go index c369a6111a..0e8f061080 100644 --- a/private/revcache/revcache.go +++ b/private/revcache/revcache.go @@ -28,27 +28,27 @@ import ( // Key denotes the key for the revocation cache. type Key struct { IA addr.IA - IfId common.IFIDType + IfID common.IfIDType } // NewKey creates a new key for the revocation cache. -func NewKey(ia addr.IA, ifId common.IFIDType) Key { +func NewKey(ia addr.IA, ifID common.IfIDType) Key { return Key{ IA: ia, - IfId: ifId, + IfID: ifID, } } func (k Key) String() string { - return fmt.Sprintf("%s#%s", k.IA, k.IfId) + return fmt.Sprintf("%s#%s", k.IA, k.IfID) } // KeySet is a set of keys. type KeySet map[Key]struct{} // SingleKey is a convenience function to return a KeySet with a single key. -func SingleKey(ia addr.IA, ifId common.IFIDType) KeySet { - return KeySet{Key{IA: ia, IfId: ifId}: {}} +func SingleKey(ia addr.IA, ifID common.IfIDType) KeySet { + return KeySet{Key{IA: ia, IfID: ifID}: {}} } // RevOrErr is either a revocation or an error. diff --git a/private/revcache/revcachetest/revcachetest.go b/private/revcache/revcachetest/revcachetest.go index 12e9f21f46..76e02c2044 100644 --- a/private/revcache/revcachetest/revcachetest.go +++ b/private/revcache/revcachetest/revcachetest.go @@ -34,8 +34,8 @@ import ( var ( ia110 = addr.MustParseIA("1-ff00:0:110") ia120 = addr.MustParseIA("1-ff00:0:120") - ifId15 = common.IFIDType(15) - ifId19 = common.IFIDType(19) + ifID15 = common.IfIDType(15) + ifID19 = common.IfIDType(19) TimeOut = 5 * time.Second ) @@ -78,13 +78,13 @@ func TestRevCache(t *testing.T, revCache TestableRevCache) { } func testInsertGet(t *testing.T, revCache TestableRevCache) { - rev := defaultRevInfo(ia110, ifId15) + rev := defaultRevInfo(ia110, ifID15) ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() inserted, err := revCache.Insert(ctx, rev) assert.True(t, inserted, "Insert should return true for a new entry") assert.NoError(t, err, "Insert a new entry should not err") - key1 := revcache.NewKey(ia110, ifId15) + key1 := revcache.NewKey(ia110, ifID15) revs, err := revCache.Get(ctx, revcache.KeySet{key1: {}}) assert.NoError(t, err, "Get should not err for existing entry") assert.NotEmpty(t, revs, "Get should return existing entry") @@ -92,16 +92,16 @@ func testInsertGet(t *testing.T, revCache TestableRevCache) { inserted, err = revCache.Insert(ctx, rev) assert.False(t, inserted, "Insert should return false for already existing entry") assert.NoError(t, err, "Insert should not err") - revs, err = revCache.Get(ctx, revcache.SingleKey(ia110, ifId19)) + revs, err = revCache.Get(ctx, revcache.SingleKey(ia110, ifID19)) assert.NoError(t, err, "Get should not err") assert.Empty(t, revs, "Get should return empty result for not present value") } func testGetMultikey(t *testing.T, revCache TestableRevCache) { - rev1 := defaultRevInfo(ia110, ifId15) - rev2 := defaultRevInfo(ia110, ifId19) - rev3 := defaultRevInfo(ia120, ifId15) - rev4 := defaultRevInfo(ia120, common.IFIDType(10)) + rev1 := defaultRevInfo(ia110, ifID15) + rev2 := defaultRevInfo(ia110, ifID19) + rev3 := defaultRevInfo(ia120, ifID15) + rev4 := defaultRevInfo(ia120, common.IfIDType(10)) ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() @@ -119,16 +119,16 @@ func testGetMultikey(t *testing.T, revCache TestableRevCache) { _, err = revCache.Insert(ctx, rev4) require.NoError(t, err) - key1 := revcache.NewKey(ia110, ifId15) + key1 := revcache.NewKey(ia110, ifID15) revs, err = revCache.Get(ctx, revcache.KeySet{key1: {}}) assert.NoError(t, err, "Get should not err") assert.Equal(t, len(revs), 1, "Should contain one rev") assert.Equal(t, revcache.Revocations{key1: rev1}, revs, "Get should return revs for the given keys") - key2 := revcache.NewKey(ia110, ifId19) - key3 := revcache.NewKey(ia120, ifId15) - key4 := revcache.NewKey(ia120, ifId19) // not the key of sr4 + key2 := revcache.NewKey(ia110, ifID19) + key3 := revcache.NewKey(ia120, ifID15) + key4 := revcache.NewKey(ia120, ifID19) // not the key of sr4 searchKeys := revcache.KeySet{key1: {}, key2: {}, key3: {}, key4: {}} revs, err = revCache.Get(ctx, searchKeys) assert.NoError(t, err, "Get should not err") @@ -149,10 +149,10 @@ func testGetAll(t *testing.T, revCache TestableRevCache) { assert.False(t, more, "No more entries expected") // Insert some stuff and query again - rev1 := defaultRevInfo(ia110, ifId15) - rev2 := defaultRevInfo(ia110, ifId19) - rev3 := defaultRevInfo(ia120, ifId15) - rev4 := defaultRevInfo(ia120, common.IFIDType(20)) + rev1 := defaultRevInfo(ia110, ifID15) + rev2 := defaultRevInfo(ia110, ifID19) + rev3 := defaultRevInfo(ia120, ifID15) + rev4 := defaultRevInfo(ia120, common.IfIDType(20)) _, err = revCache.Insert(ctx, rev1) require.NoError(t, err) _, err = revCache.Insert(ctx, rev2) @@ -187,7 +187,7 @@ func testGetAllExpired(t *testing.T, revCache TestableRevCache) { defer cancelF() // insert expired rev revNew := &path_mgmt.RevInfo{ - IfID: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), @@ -204,7 +204,7 @@ func testGetAllExpired(t *testing.T, revCache TestableRevCache) { func testInsertExpired(t *testing.T, revCache TestableRevCache) { r := &path_mgmt.RevInfo{ - IfID: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-15 * time.Second)), @@ -218,13 +218,13 @@ func testInsertExpired(t *testing.T, revCache TestableRevCache) { } func testInsertNewer(t *testing.T, revCache TestableRevCache) { - rev := defaultRevInfo(ia110, ifId15) + rev := defaultRevInfo(ia110, ifID15) ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() _, err := revCache.Insert(ctx, rev) require.NoError(t, err) revNew := &path_mgmt.RevInfo{ - IfID: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(10 * time.Second)), @@ -234,7 +234,7 @@ func testInsertNewer(t *testing.T, revCache TestableRevCache) { inserted, err := revCache.Insert(ctx, revNew) assert.True(t, inserted, "Insert should return true for a new entry") assert.NoError(t, err, "Insert a new entry should not err") - key1 := revcache.NewKey(ia110, ifId15) + key1 := revcache.NewKey(ia110, ifID15) revs, err := revCache.Get(ctx, revcache.KeySet{key1: {}}) assert.NoError(t, err, "Get should not err for existing entry") assert.NotEmpty(t, revs, "Get should return non empty map for inserted value") @@ -245,14 +245,14 @@ func testGetExpired(t *testing.T, revCache TestableRevCache) { ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() revNew := &path_mgmt.RevInfo{ - IfID: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), RawTTL: 1, } revCache.InsertExpired(t, ctx, revNew) - revs, err := revCache.Get(ctx, revcache.SingleKey(ia110, ifId15)) + revs, err := revCache.Get(ctx, revcache.SingleKey(ia110, ifID15)) assert.Empty(t, revs, "Expired entry should not be returned") assert.NoError(t, err, "Should not error for expired entry") } @@ -261,19 +261,19 @@ func testGetMuliKeysExpired(t *testing.T, revCache TestableRevCache) { ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() revNew := &path_mgmt.RevInfo{ - IfID: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), RawTTL: 1, } revCache.InsertExpired(t, ctx, revNew) - rev110_19 := defaultRevInfo(ia110, ifId19) + rev110_19 := defaultRevInfo(ia110, ifID19) _, err := revCache.Insert(ctx, rev110_19) assert.NoError(t, err) - validKey := revcache.NewKey(ia110, ifId19) + validKey := revcache.NewKey(ia110, ifID19) srCache, err := revCache.Get(ctx, revcache.KeySet{ - revcache.NewKey(ia110, ifId15): {}, + revcache.NewKey(ia110, ifID15): {}, validKey: {}, }) assert.NoError(t, err, "Should not error for expired entry") @@ -287,14 +287,14 @@ func testDeleteExpired(t *testing.T, revCache TestableRevCache) { del, err := revCache.DeleteExpired(ctx) assert.NoError(t, err, "DeleteExpired on empty should not error") assert.EqualValues(t, 0, del, "DeleteExpired on empty should delete 0") - rev110_19 := defaultRevInfo(ia110, ifId19) + rev110_19 := defaultRevInfo(ia110, ifID19) _, err = revCache.Insert(ctx, rev110_19) assert.NoError(t, err) del, err = revCache.DeleteExpired(ctx) assert.NoError(t, err, "DeleteExpired should not error") assert.EqualValues(t, 0, del, "DeleteExpired should delete 0 if entry is not expired") revNew := &path_mgmt.RevInfo{ - IfID: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), @@ -309,9 +309,9 @@ func testDeleteExpired(t *testing.T, revCache TestableRevCache) { assert.EqualValues(t, 0, del, "DeleteExpired should delete 0 if entry is not expired") } -func defaultRevInfo(ia addr.IA, ifId common.IFIDType) *path_mgmt.RevInfo { +func defaultRevInfo(ia addr.IA, ifID common.IfIDType) *path_mgmt.RevInfo { return &path_mgmt.RevInfo{ - IfID: ifId, + IfID: ifID, RawIsdas: ia, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now()), diff --git a/private/revcache/util.go b/private/revcache/util.go index bbd13fd1f9..db0e1894e1 100644 --- a/private/revcache/util.go +++ b/private/revcache/util.go @@ -46,10 +46,10 @@ func NoRevokedHopIntf(ctx context.Context, revCache RevCache, func addRevKeys(segs []*seg.PathSegment, keys KeySet, hopOnly bool) { addIntfs := func(ia addr.IA, ingress, egress uint16) { if ingress != 0 { - keys[Key{IA: ia, IfId: common.IFIDType(ingress)}] = struct{}{} + keys[Key{IA: ia, IfID: common.IfIDType(ingress)}] = struct{}{} } if egress != 0 { - keys[Key{IA: ia, IfId: common.IFIDType(egress)}] = struct{}{} + keys[Key{IA: ia, IfID: common.IfIDType(egress)}] = struct{}{} } } for _, s := range segs { diff --git a/private/revcache/util_test.go b/private/revcache/util_test.go index ddde37b569..94e92f1651 100644 --- a/private/revcache/util_test.go +++ b/private/revcache/util_test.go @@ -35,14 +35,12 @@ import ( ) var ( - ia211 = addr.MustParseIA("2-ff00:0:211") - + ia211 = addr.MustParseIA("2-ff00:0:211") timeout = time.Second ) func TestNoRevokedHopIntf(t *testing.T) { now := time.Now() - ctrl := gomock.NewController(t) defer ctrl.Finish() ctx, cancelF := context.WithTimeout(context.Background(), timeout) @@ -62,7 +60,7 @@ func TestNoRevokedHopIntf(t *testing.T) { revCache.EXPECT().Get(gomock.Eq(ctx), gomock.Any()).Return( revcache.Revocations{ revcache.Key{IA: addr.MustParseIA("2-ff00:0:211"), - IfId: common.IFIDType(graph.If_210_X_211_A)}: sRev, + IfID: common.IfIDType(graph.If_210_X_211_A)}: sRev, }, nil, ) noR, err := revcache.NoRevokedHopIntf(ctx, revCache, seg210_222_1) @@ -79,9 +77,9 @@ func TestNoRevokedHopIntf(t *testing.T) { }) } -func defaultRevInfo(ia addr.IA, ifId uint16, ts time.Time) *path_mgmt.RevInfo { +func defaultRevInfo(ia addr.IA, ifID uint16, ts time.Time) *path_mgmt.RevInfo { return &path_mgmt.RevInfo{ - IfID: common.IFIDType(ifId), + IfID: common.IfIDType(ifID), RawIsdas: ia, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(ts), diff --git a/private/segment/segfetcher/pather.go b/private/segment/segfetcher/pather.go index f168cc6ac0..4f045ac81a 100644 --- a/private/segment/segfetcher/pather.go +++ b/private/segment/segfetcher/pather.go @@ -196,7 +196,7 @@ func (p *Pather) translatePath(comb combinator.Path) (snet.Path, error) { nextHop := p.NextHopper.UnderlayNextHop(uint16(comb.Metadata.Interfaces[0].ID)) if nextHop == nil { return nil, serrors.New("Unable to find first-hop BR for path", - "ifid", comb.Metadata.Interfaces[0].ID) + "ifID", comb.Metadata.Interfaces[0].ID) } return path.Path{ Src: comb.Metadata.Interfaces[0].IA, diff --git a/private/segment/segfetcher/resolver_test.go b/private/segment/segfetcher/resolver_test.go index 1f1d7021e6..d452476fd9 100644 --- a/private/segment/segfetcher/resolver_test.go +++ b/private/segment/segfetcher/resolver_test.go @@ -411,11 +411,11 @@ func TestResolverWithRevocations(t *testing.T) { ExpectRevcache: func(t *testing.T, revCache *mock_revcache.MockRevCache) { key111_120 := revcache.Key{ IA: non_core_111, - IfId: common.IFIDType(graph.If_111_B_120_X), + IfID: common.IfIDType(graph.If_111_B_120_X), } key111_130 := revcache.Key{ IA: non_core_111, - IfId: common.IFIDType(graph.If_111_A_130_B), + IfID: common.IfIDType(graph.If_111_A_130_B), } revoke(t, revCache, key111_120) revoke(t, revCache, key111_130) @@ -446,7 +446,7 @@ func TestResolverWithRevocations(t *testing.T) { db.EXPECT().Get(gomock.Any(), gomock.Any()).Times(2) }, ExpectRevcache: func(t *testing.T, revCache *mock_revcache.MockRevCache) { - key110 := revcache.Key{IA: core_110, IfId: common.IFIDType(graph.If_110_X_130_A)} + key110 := revcache.Key{IA: core_110, IfID: common.IfIDType(graph.If_110_X_130_A)} ksMatcher := keySetContains{keys: []revcache.Key{key110}} rev := &path_mgmt.RevInfo{} revCache.EXPECT().Get(gomock.Any(), ksMatcher).Return(revcache.Revocations{ diff --git a/private/storage/beacon/sqlite/db.go b/private/storage/beacon/sqlite/db.go index d42658614c..1ede0786d4 100644 --- a/private/storage/beacon/sqlite/db.go +++ b/private/storage/beacon/sqlite/db.go @@ -140,15 +140,15 @@ func (e *executor) CandidateBeacons( beacons := make([]beacon.Beacon, 0, setSize) for rows.Next() { var rawBeacon sql.RawBytes - var inIntfID common.IFIDType - if err = rows.Scan(&rawBeacon, &inIntfID); err != nil { + var inIfID common.IfIDType + if err = rows.Scan(&rawBeacon, &inIfID); err != nil { return nil, db.NewReadError(beacon.ErrReadingRows, err) } s, err := beacon.UnpackBeacon(rawBeacon) if err != nil { return nil, db.NewDataError(beacon.ErrParse, err) } - beacons = append(beacons, beacon.Beacon{Segment: s, InIfId: uint16(inIntfID)}) + beacons = append(beacons, beacon.Beacon{Segment: s, InIfID: uint16(inIfID)}) } if err := rows.Err(); err != nil { return nil, err @@ -217,8 +217,8 @@ func (e *executor) GetBeacons( var lastUpdated int64 var usage int var rawBeacon sql.RawBytes - var InIntfID uint16 - err = rows.Scan(&RowID, &lastUpdated, &usage, &rawBeacon, &InIntfID) + var InIfID uint16 + err = rows.Scan(&RowID, &lastUpdated, &usage, &rawBeacon, &InIfID) if err != nil { return nil, serrors.WrapStr("reading row", err) } @@ -229,7 +229,7 @@ func (e *executor) GetBeacons( res = append(res, storagebeacon.Beacon{ Beacon: beacon.Beacon{ Segment: seg, - InIfId: InIntfID, + InIfID: InIfID, }, Usage: beacon.Usage(usage), LastUpdated: time.Unix(0, lastUpdated), @@ -360,7 +360,7 @@ func (e *executor) updateExistingBeacon( inst := `UPDATE Beacons SET FullID=?, InIntfID=?, HopsLength=?, InfoTime=?, ExpirationTime=?, LastUpdated=?, Usage=?, Beacon=? WHERE RowID=?` - _, err = e.db.ExecContext(ctx, inst, fullID, b.InIfId, len(b.Segment.ASEntries), infoTime, + _, err = e.db.ExecContext(ctx, inst, fullID, b.InIfID, len(b.Segment.ASEntries), infoTime, expTime, lastUpdated, usage, packedSeg, rowID) if err != nil { return db.NewWriteError("update segment", err) @@ -393,7 +393,7 @@ func insertNewBeacon( ExpirationTime, LastUpdated, Usage, Beacon) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` - _, err = tx.ExecContext(ctx, inst, segID, fullID, start.ISD(), start.AS(), b.InIfId, + _, err = tx.ExecContext(ctx, inst, segID, fullID, start.ISD(), start.AS(), b.InIfID, len(b.Segment.ASEntries), infoTime, expTime, lastUpdated, usage, packed) if err != nil { return db.NewWriteError("insert beacon", err) diff --git a/private/storage/path/dbtest/dbtest.go b/private/storage/path/dbtest/dbtest.go index 631f94d754..d8e474eca6 100644 --- a/private/storage/path/dbtest/dbtest.go +++ b/private/storage/path/dbtest/dbtest.go @@ -596,21 +596,21 @@ func checkInterfacesPresent(t *testing.T, ctx context.Context, } } -func checkInterface(t *testing.T, ctx context.Context, ia addr.IA, ifId uint16, +func checkInterface(t *testing.T, ctx context.Context, ia addr.IA, ifID uint16, pathDB pathdb.ReadWrite, present bool) { r, err := pathDB.Get(ctx, &query.Params{ Intfs: []*query.IntfSpec{ { IA: ia, - IfID: common.IFIDType(ifId), + IfID: common.IfIDType(ifID), }, }, }) require.NoError(t, err) if present { - assert.Equal(t, 1, len(r), fmt.Sprintf("Interface should be present: %v#%d", ia, ifId)) + assert.Equal(t, 1, len(r), fmt.Sprintf("Interface should be present: %v#%d", ia, ifID)) } else { - assert.Zero(t, len(r), (fmt.Sprintf("Interface should not be present: %v#%d", ia, ifId))) + assert.Zero(t, len(r), (fmt.Sprintf("Interface should not be present: %v#%d", ia, ifID))) } } diff --git a/private/storage/trust/fspersister/db_test.go b/private/storage/trust/fspersister/db_test.go index 94f54363ee..fe313b01df 100644 --- a/private/storage/trust/fspersister/db_test.go +++ b/private/storage/trust/fspersister/db_test.go @@ -32,7 +32,7 @@ import ( ) const ( - testTrcsDir = "testdata/overthenetwork/" + testTRCsDir = "testdata/overthenetwork/" ) type DB struct { @@ -96,55 +96,55 @@ func TestInsertTRCWithFSPersistence(t *testing.T) { testDB.Prepare(t, ctx) t.Run("insert TRC not present in neither DB nor FS", func(t *testing.T) { - SignedTRC, persistedTrcPath := getTRC(t, "ISD1-B1-S1.trc", testDB.Dir) + SignedTRC, persistedTRCPath := getTRC(t, "ISD1-B1-S1.trc", testDB.Dir) in, err := testDB.InsertTRC(ctx, SignedTRC) require.NoError(t, err) require.True(t, in) - persistedTRC := xtest.LoadTRC(t, persistedTrcPath) + persistedTRC := xtest.LoadTRC(t, persistedTRCPath) require.Equal(t, SignedTRC, persistedTRC) }) t.Run("insert TRC already present in DB and FS", func(t *testing.T) { - SignedTRC, persistedTrcPath := getTRC(t, "ISD1-B1-S1.trc", testDB.Dir) - mtimeBeforeInsert := getModTime(t, persistedTrcPath) + SignedTRC, persistedTRCPath := getTRC(t, "ISD1-B1-S1.trc", testDB.Dir) + mtimeBeforeInsert := getModTime(t, persistedTRCPath) - persistedTRC := xtest.LoadTRC(t, persistedTrcPath) + persistedTRC := xtest.LoadTRC(t, persistedTRCPath) require.Equal(t, SignedTRC, persistedTRC) in, err := testDB.InsertTRC(ctx, SignedTRC) require.NoError(t, err) require.False(t, in) - mtimeAfterInsert := getModTime(t, persistedTrcPath) + mtimeAfterInsert := getModTime(t, persistedTRCPath) require.Equal(t, mtimeBeforeInsert, mtimeAfterInsert) - persistedTRC = xtest.LoadTRC(t, persistedTrcPath) + persistedTRC = xtest.LoadTRC(t, persistedTRCPath) require.Equal(t, SignedTRC, persistedTRC) }) t.Run("insert TRC not present in DB but present on FS", func(t *testing.T) { - SignedTRC, persistedTrcPath := getTRC(t, "ISD2-B1-S1.trc", testDB.Dir) - require.NoError(t, os.WriteFile(persistedTrcPath, SignedTRC.Raw, 0644)) - mtimeBeforeInsert := getModTime(t, persistedTrcPath) + SignedTRC, persistedTRCPath := getTRC(t, "ISD2-B1-S1.trc", testDB.Dir) + require.NoError(t, os.WriteFile(persistedTRCPath, SignedTRC.Raw, 0644)) + mtimeBeforeInsert := getModTime(t, persistedTRCPath) in, err := testDB.InsertTRC(ctx, SignedTRC) require.NoError(t, err) require.True(t, in) - mtimeAfterInsert := getModTime(t, persistedTrcPath) + mtimeAfterInsert := getModTime(t, persistedTRCPath) require.Equal(t, mtimeBeforeInsert, mtimeAfterInsert) }) t.Run("insert TRC that is already present in DB but not on FS", func(t *testing.T) { - SignedTRC, persistedTrcPath := getTRC(t, "ISD1-B1-S1.trc", testDB.Dir) - err := os.Remove(persistedTrcPath) + SignedTRC, persistedTRCPath := getTRC(t, "ISD1-B1-S1.trc", testDB.Dir) + err := os.Remove(persistedTRCPath) require.NoError(t, err) in, err := testDB.InsertTRC(ctx, SignedTRC) require.NoError(t, err) require.False(t, in) - persistedTRC := xtest.LoadTRC(t, persistedTrcPath) + persistedTRC := xtest.LoadTRC(t, persistedTRCPath) require.Equal(t, SignedTRC, persistedTRC) }) @@ -164,8 +164,8 @@ func getModTime(t *testing.T, file string) int64 { } func getTRC(t *testing.T, trcName, persistDir string) (cppki.SignedTRC, string) { - testTrcPath := filepath.Join(testTrcsDir, trcName) - trc := xtest.LoadTRC(t, testTrcPath) - persistedTrcPath := filepath.Join(persistDir, trcName) - return trc, persistedTrcPath + testTRCPath := filepath.Join(testTRCsDir, trcName) + trc := xtest.LoadTRC(t, testTRCPath) + persistedTRCPath := filepath.Join(persistDir, trcName) + return trc, persistedTRCPath } diff --git a/private/topology/interface.go b/private/topology/interface.go index 5100f70438..eb8d9879a2 100644 --- a/private/topology/interface.go +++ b/private/topology/interface.go @@ -39,7 +39,7 @@ type Topology interface { // Core returns whether the local AS is core. Core() bool // InterfaceIDs returns all interface IDS from the local AS. - InterfaceIDs() []common.IFIDType + IfIDs() []common.IfIDType // PortRange returns the first and last ports of the port range (both included), // in which endhost listen for SCION/UDP application using the UDP/IP underlay. PortRange() (uint16, uint16) @@ -59,7 +59,7 @@ type Topology interface { UnderlayMulticast(svc addr.SVC) ([]*net.UDPAddr, error) // UnderlayNextHop returns the internal underlay address of the router // containing the interface ID. - UnderlayNextHop(ifID common.IFIDType) (*net.UDPAddr, bool) + UnderlayNextHop(ifID common.IfIDType) (*net.UDPAddr, bool) // MakeHostInfos returns the underlay addresses of all services for the specified service type. MakeHostInfos(st ServiceType) ([]*net.UDPAddr, error) @@ -144,10 +144,10 @@ func (t *topologyS) MTU() uint16 { return uint16(t.Topology.MTU) } -func (t *topologyS) InterfaceIDs() []common.IFIDType { - intfs := make([]common.IFIDType, 0, len(t.Topology.IFInfoMap)) - for ifid := range t.Topology.IFInfoMap { - intfs = append(intfs, ifid) +func (t *topologyS) IfIDs() []common.IfIDType { + intfs := make([]common.IfIDType, 0, len(t.Topology.IFInfoMap)) + for ifID := range t.Topology.IFInfoMap { + intfs = append(intfs, ifID) } return intfs } @@ -156,8 +156,8 @@ func (t *topologyS) PortRange() (uint16, uint16) { return t.Topology.DispatchedPortStart, t.Topology.DispatchedPortEnd } -func (t *topologyS) UnderlayNextHop(ifid common.IFIDType) (*net.UDPAddr, bool) { - ifInfo, ok := t.Topology.IFInfoMap[ifid] +func (t *topologyS) UnderlayNextHop(ifID common.IfIDType) (*net.UDPAddr, bool) { + ifInfo, ok := t.Topology.IFInfoMap[ifID] if !ok { return nil, false } diff --git a/private/topology/json/json.go b/private/topology/json/json.go index 175cd2e344..5c4ebc273b 100644 --- a/private/topology/json/json.go +++ b/private/topology/json/json.go @@ -94,7 +94,7 @@ type ServerInfo struct { // BRInfo contains Border Router specific information. type BRInfo struct { InternalAddr string `json:"internal_addr"` - Interfaces map[common.IFIDType]*BRInterface `json:"interfaces"` + Interfaces map[common.IfIDType]*BRInterface `json:"interfaces"` } // GatewayInfo contains SCION gateway information. @@ -113,7 +113,7 @@ type BRInterface struct { LinkTo string `json:"link_to"` MTU int `json:"mtu"` BFD *BFD `json:"bfd,omitempty"` - RemoteIFID common.IFIDType `json:"remote_interface_id,omitempty"` + RemoteIfID common.IfIDType `json:"remote_interface_id,omitempty"` } // Underlay is the underlay information for a BR interface. @@ -139,8 +139,8 @@ func (i ServerInfo) String() string { func (i BRInfo) String() string { var s []string s = append(s, fmt.Sprintf("Loc addrs:\n %s\nInterfaces:", i.InternalAddr)) - for ifid, intf := range i.Interfaces { - s = append(s, fmt.Sprintf("%d: %+v", ifid, intf)) + for ifID, intf := range i.Interfaces { + s = append(s, fmt.Sprintf("%d: %+v", ifID, intf)) } return strings.Join(s, "\n") } diff --git a/private/topology/json/json_test.go b/private/topology/json/json_test.go index 4968571bec..25f590e771 100644 --- a/private/topology/json/json_test.go +++ b/private/topology/json/json_test.go @@ -46,7 +46,7 @@ func TestLoadRawFromFile(t *testing.T) { BorderRouters: map[string]*jsontopo.BRInfo{ "borderrouter6-f00:0:362-1": { InternalAddr: "10.1.0.1:0", - Interfaces: map[common.IFIDType]*jsontopo.BRInterface{ + Interfaces: map[common.IfIDType]*jsontopo.BRInterface{ 91: { Underlay: jsontopo.Underlay{ Local: "192.0.2.1:4997", @@ -65,7 +65,7 @@ func TestLoadRawFromFile(t *testing.T) { }, "borderrouter6-f00:0:362-9": { InternalAddr: "[2001:db8:a0b:12f0::2]:0", - Interfaces: map[common.IFIDType]*jsontopo.BRInterface{ + Interfaces: map[common.IfIDType]*jsontopo.BRInterface{ 32: { Underlay: jsontopo.Underlay{ Local: "[2001:db8:a0b:12f0::1]:4997", diff --git a/private/topology/mock_topology/mock.go b/private/topology/mock_topology/mock.go index 5efe3794b3..c141aaec03 100644 --- a/private/topology/mock_topology/mock.go +++ b/private/topology/mock_topology/mock.go @@ -124,18 +124,18 @@ func (mr *MockTopologyMockRecorder) IFInfoMap() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IFInfoMap", reflect.TypeOf((*MockTopology)(nil).IFInfoMap)) } -// InterfaceIDs mocks base method. -func (m *MockTopology) InterfaceIDs() []common.IFIDType { +// IfIDs mocks base method. +func (m *MockTopology) IfIDs() []common.IfIDType { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InterfaceIDs") - ret0, _ := ret[0].([]common.IFIDType) + ret := m.ctrl.Call(m, "IfIDs") + ret0, _ := ret[0].([]common.IfIDType) return ret0 } -// InterfaceIDs indicates an expected call of InterfaceIDs. -func (mr *MockTopologyMockRecorder) InterfaceIDs() *gomock.Call { +// IfIDs indicates an expected call of IfIDs. +func (mr *MockTopologyMockRecorder) IfIDs() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InterfaceIDs", reflect.TypeOf((*MockTopology)(nil).InterfaceIDs)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IfIDs", reflect.TypeOf((*MockTopology)(nil).IfIDs)) } // MTU mocks base method. @@ -256,7 +256,7 @@ func (mr *MockTopologyMockRecorder) UnderlayMulticast(arg0 interface{}) *gomock. } // UnderlayNextHop mocks base method. -func (m *MockTopology) UnderlayNextHop(arg0 common.IFIDType) (*net.UDPAddr, bool) { +func (m *MockTopology) UnderlayNextHop(arg0 common.IfIDType) (*net.UDPAddr, bool) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UnderlayNextHop", arg0) ret0, _ := ret[0].(*net.UDPAddr) diff --git a/private/topology/reload.go b/private/topology/reload.go index 1ec5d4b9e1..37a2cf4251 100644 --- a/private/topology/reload.go +++ b/private/topology/reload.go @@ -133,16 +133,16 @@ func (l *Loader) UnderlayNextHop(ifID uint16) *net.UDPAddr { l.mtx.Lock() defer l.mtx.Unlock() - addr, _ := l.topo.UnderlayNextHop(common.IFIDType(ifID)) + addr, _ := l.topo.UnderlayNextHop(common.IfIDType(ifID)) return addr } -func (l *Loader) InterfaceIDs() []uint16 { +func (l *Loader) IfIDs() []uint16 { l.mtx.Lock() defer l.mtx.Unlock() var ids []uint16 - for _, id := range l.topo.InterfaceIDs() { + for _, id := range l.topo.IfIDs() { ids = append(ids, uint16(id)) } return ids @@ -182,7 +182,7 @@ func (l *Loader) Gateways() ([]GatewayInfo, error) { return l.topo.Gateways() } -func (l *Loader) InterfaceInfoMap() map[common.IFIDType]IFInfo { +func (l *Loader) InterfaceInfoMap() map[common.IfIDType]IFInfo { l.mtx.Lock() defer l.mtx.Unlock() diff --git a/private/topology/reload_test.go b/private/topology/reload_test.go index e801ea2e05..831fdcf36e 100644 --- a/private/topology/reload_test.go +++ b/private/topology/reload_test.go @@ -42,7 +42,7 @@ func TestLoader(t *testing.T) { assert.Equal(t, addr.MustParseIA("1-ff00:0:311"), l.IA()) assert.Equal(t, uint16(1472), l.MTU()) assert.Equal(t, false, l.Core()) - assert.ElementsMatch(t, []uint16{1, 3, 8, 11}, l.InterfaceIDs()) + assert.ElementsMatch(t, []uint16{1, 3, 8, 11}, l.IfIDs()) assert.ElementsMatch(t, xtest.MustParseUDPAddrs(t, "127.0.0.67:30073", diff --git a/private/topology/topology.go b/private/topology/topology.go index 0590743209..f7646112bd 100644 --- a/private/topology/topology.go +++ b/private/topology/topology.go @@ -53,7 +53,7 @@ type ( // // The second section concerns the Border routers. // The BR map points from border router names to BRInfo structs, which in turn - // are lists of IFID type slices, thus defines the IFIDs that belong to a + // are lists of IfID type slices, thus defines the IfIDs that belong to a // particular border router. The IFInfoMap points from interface IDs to IFInfo structs. // // The third section in RWTopology concerns the SCION-specific services in the topology. @@ -94,26 +94,26 @@ type ( Name string // InternalAddr is the local data-plane address. InternalAddr netip.AddrPort - // IFIDs is a sorted list of the interface IDs. - IFIDs []common.IFIDType + // IfIDs is a sorted list of the interface IDs. + IfIDs []common.IfIDType // IFs is a map of interface IDs. - IFs map[common.IFIDType]*IFInfo + IFs map[common.IfIDType]*IFInfo } // IfInfoMap maps interface ids to the interface information. - IfInfoMap map[common.IFIDType]IFInfo + IfInfoMap map[common.IfIDType]IFInfo // IFInfo describes a border router link to another AS, including the internal data-plane // address applications should send traffic to and information about the link itself and the // remote side of it. IFInfo struct { // ID is the interface ID. It is unique per AS. - ID common.IFIDType + ID common.IfIDType BRName string InternalAddr netip.AddrPort Local netip.AddrPort Remote netip.AddrPort - RemoteIFID common.IFIDType + RemoteIfID common.IfIDType IA addr.IA LinkType LinkType MTU int @@ -267,17 +267,17 @@ func (t *RWTopology) populateBR(raw *jsontopo.Topology) error { brInfo := BRInfo{ Name: name, InternalAddr: intAddr, - IFs: make(map[common.IFIDType]*IFInfo), + IFs: make(map[common.IfIDType]*IFInfo), } - for ifid, rawIntf := range rawBr.Interfaces { + for ifID, rawIntf := range rawBr.Interfaces { var err error - // Check that ifid is unique - if _, ok := t.IFInfoMap[ifid]; ok { - return serrors.New("IFID already exists", "ID", ifid) + // Check that ifID is unique + if _, ok := t.IFInfoMap[ifID]; ok { + return serrors.New("IfID already exists", "ID", ifID) } - brInfo.IFIDs = append(brInfo.IFIDs, ifid) + brInfo.IfIDs = append(brInfo.IfIDs, ifID) ifinfo := IFInfo{ - ID: ifid, + ID: ifID, BRName: name, InternalAddr: intAddr, MTU: rawIntf.MTU, @@ -287,7 +287,7 @@ func (t *RWTopology) populateBR(raw *jsontopo.Topology) error { } ifinfo.LinkType = LinkTypeFromString(rawIntf.LinkTo) if ifinfo.LinkType == Peer { - ifinfo.RemoteIFID = rawIntf.RemoteIFID + ifinfo.RemoteIfID = rawIntf.RemoteIfID } if err = ifinfo.CheckLinks(t.IsCore, name); err != nil { @@ -305,8 +305,8 @@ func (t *RWTopology) populateBR(raw *jsontopo.Topology) error { // These fields are only necessary for the border router. // Parsing should not fail if all fields are empty. if rawIntf.Underlay == (jsontopo.Underlay{}) { - brInfo.IFs[ifid] = &ifinfo - t.IFInfoMap[ifid] = ifinfo + brInfo.IFs[ifID] = &ifinfo + t.IFInfoMap[ifID] = ifinfo continue } if ifinfo.Local, err = rawBRIntfLocalAddr(&rawIntf.Underlay); err != nil { @@ -317,11 +317,11 @@ func (t *RWTopology) populateBR(raw *jsontopo.Topology) error { return serrors.WrapStr("unable to extract "+ "underlay external data-plane remote address", err) } - brInfo.IFs[ifid] = &ifinfo - t.IFInfoMap[ifid] = ifinfo + brInfo.IFs[ifID] = &ifinfo + t.IFInfoMap[ifID] = ifinfo } - sort.Slice(brInfo.IFIDs, func(i, j int) bool { - return brInfo.IFIDs[i] < brInfo.IFIDs[j] + sort.Slice(brInfo.IfIDs, func(i, j int) bool { + return brInfo.IfIDs[i] < brInfo.IfIDs[j] }) t.BR[name] = brInfo } @@ -467,16 +467,16 @@ func (i *BRInfo) copy() *BRInfo { return &BRInfo{ Name: i.Name, InternalAddr: i.InternalAddr, - IFIDs: append(i.IFIDs[:0:0], i.IFIDs...), + IfIDs: append(i.IfIDs[:0:0], i.IfIDs...), IFs: copyIFsMap(i.IFs), } } -func copyIFsMap(m map[common.IFIDType]*IFInfo) map[common.IFIDType]*IFInfo { +func copyIFsMap(m map[common.IfIDType]*IFInfo) map[common.IfIDType]*IFInfo { if m == nil { return nil } - newM := make(map[common.IFIDType]*IFInfo) + newM := make(map[common.IfIDType]*IFInfo) for k, v := range m { newM[k] = v.copy() } diff --git a/private/topology/topology_test.go b/private/topology/topology_test.go index c54e283b95..5830dc9b39 100644 --- a/private/topology/topology_test.go +++ b/private/topology/topology_test.go @@ -58,17 +58,17 @@ func TestBRs(t *testing.T) { brs := map[string]BRInfo{ "br1-ff00:0:311-1": { - IFIDs: []common.IFIDType{1, 3, 8}, + IfIDs: []common.IfIDType{1, 3, 8}, }, "br1-ff00:0:311-2": { - IFIDs: []common.IFIDType{11}, + IfIDs: []common.IfIDType{11}, }, } for name, info := range brs { t.Run("checking BR details for "+name, func(t *testing.T) { - for _, i := range info.IFIDs { - assert.Contains(t, c.BR[name].IFIDs, i) + for _, i := range info.IfIDs { + assert.Contains(t, c.BR[name].IfIDs, i) } }) } @@ -312,16 +312,16 @@ func TestBRsCoreAS(t *testing.T) { c := MustLoadTopo(t, "testdata/core.json") brCases := []struct { name string - interfaces []common.IFIDType + interfaces []common.IfIDType }{ - {name: "borderrouter6-ff00:0:362-1", interfaces: []common.IFIDType{91}}, - {name: "borderrouter6-ff00:0:362-9", interfaces: []common.IFIDType{32}}, + {name: "borderrouter6-ff00:0:362-1", interfaces: []common.IfIDType{91}}, + {name: "borderrouter6-ff00:0:362-9", interfaces: []common.IfIDType{32}}, } for _, test := range brCases { t.Run(test.name, func(t *testing.T) { assert.Contains(t, c.BR, test.name) for _, intf := range test.interfaces { - assert.Contains(t, c.BR[test.name].IFIDs, intf) + assert.Contains(t, c.BR[test.name].IfIDs, intf) } }) } diff --git a/private/trust/grpc/fetcher.go b/private/trust/grpc/fetcher.go index d164accd0d..f5c04cc149 100644 --- a/private/trust/grpc/fetcher.go +++ b/private/trust/grpc/fetcher.go @@ -128,7 +128,7 @@ func (f Fetcher) TRC(ctx context.Context, id cppki.TRCID, return cppki.SignedTRC{}, serrors.WrapStr("receiving TRC", err) } - trc, err := cppki.DecodeSignedTRC(rep.Trc) + trc, err := cppki.DecodeSignedTRC(rep.Trc) // nolint - name from protobuf if err != nil { f.updateMetric(span, labels.WithResult(trustmetrics.ErrParse), err) return cppki.SignedTRC{}, serrors.WrapStr("parse TRC reply", err) diff --git a/private/trust/grpc/fetcher_test.go b/private/trust/grpc/fetcher_test.go index 0cd77ea50f..51df4fd0f2 100644 --- a/private/trust/grpc/fetcher_test.go +++ b/private/trust/grpc/fetcher_test.go @@ -210,7 +210,10 @@ func TestFetcherTRC(t *testing.T) { Server: func(mctrl *gomock.Controller) *mock_cp.MockTrustMaterialServiceServer { srv := mock_cp.NewMockTrustMaterialServiceServer(mctrl) srv.EXPECT().TRC(gomock.Any(), gomock.Any()).Return( - &cppb.TRCResponse{Trc: []byte("garbage")}, nil, + &cppb.TRCResponse{ + Trc: []byte("garbage"), // nolint - name from published protobuf + }, + nil, ) return srv }, @@ -224,7 +227,7 @@ func TestFetcherTRC(t *testing.T) { srv := mock_cp.NewMockTrustMaterialServiceServer(mctrl) srv.EXPECT().TRC(gomock.Any(), gomock.Any()).Return( - &cppb.TRCResponse{Trc: rawBase}, nil, + &cppb.TRCResponse{Trc: rawBase}, nil, // nolint - name from published protobuf ) return srv }, @@ -235,7 +238,10 @@ func TestFetcherTRC(t *testing.T) { Server: func(mctrl *gomock.Controller) *mock_cp.MockTrustMaterialServiceServer { srv := mock_cp.NewMockTrustMaterialServiceServer(mctrl) srv.EXPECT().TRC(gomock.Any(), gomock.Any()).Return( - &cppb.TRCResponse{Trc: updated.Raw}, nil, + &cppb.TRCResponse{ + Trc: updated.Raw, // nolint - name from published protobuf + }, + nil, ) return srv }, diff --git a/private/trust/signer.go b/private/trust/signer.go index 5f4e1789cb..71c5ba4631 100644 --- a/private/trust/signer.go +++ b/private/trust/signer.go @@ -67,8 +67,8 @@ func (s Signer) Sign( id := &cppb.VerificationKeyID{ IsdAs: uint64(s.IA), - TrcBase: uint64(s.TRCID.Base), - TrcSerial: uint64(s.TRCID.Serial), + TrcBase: uint64(s.TRCID.Base), // nolint - name from published protobuf + TrcSerial: uint64(s.TRCID.Serial), // nolint - name from published protobuf SubjectKeyId: s.SubjectKeyID, } rawID, err := proto.Marshal(id) diff --git a/private/trust/verifier.go b/private/trust/verifier.go index 8b9ba81700..5ea498676a 100644 --- a/private/trust/verifier.go +++ b/private/trust/verifier.go @@ -94,8 +94,8 @@ func (v Verifier) Verify(ctx context.Context, signedMsg *cryptopb.SignedMessage, return nil, serrors.New("nil engine that provides cert chains") } id := cppki.TRCID{ISD: ia.ISD(), - Base: scrypto.Version(keyID.TrcBase), - Serial: scrypto.Version(keyID.TrcSerial), + Base: scrypto.Version(keyID.TrcBase), // nolint - name from published protobuf + Serial: scrypto.Version(keyID.TrcSerial), // nolint - name from published protobuf } if err := v.notifyTRC(ctx, id); err != nil { metrics.Verifier.Verify(l.WithResult(metrics.ErrInternal)).Inc() diff --git a/router/connector.go b/router/connector.go index 839a772595..6c9fccef71 100644 --- a/router/connector.go +++ b/router/connector.go @@ -80,7 +80,7 @@ func (c *Connector) AddInternalInterface(ia addr.IA, local netip.AddrPort) error } // AddExternalInterface adds a link between the local and remote address. -func (c *Connector) AddExternalInterface(localIfID common.IFIDType, link control.LinkInfo, +func (c *Connector) AddExternalInterface(localIfID common.IfIDType, link control.LinkInfo, owned bool) error { c.mtx.Lock() @@ -110,16 +110,16 @@ func (c *Connector) AddExternalInterface(localIfID common.IFIDType, link control c.externalInterfaces = make(map[uint16]control.ExternalInterface) } c.externalInterfaces[intf] = control.ExternalInterface{ - InterfaceID: intf, - Link: link, - State: control.InterfaceDown, + IfID: intf, + Link: link, + State: control.InterfaceDown, } } else { if len(c.siblingInterfaces) == 0 { c.siblingInterfaces = make(map[uint16]control.SiblingInterface) } c.siblingInterfaces[intf] = control.SiblingInterface{ - InterfaceID: intf, + IfID: intf, InternalInterface: link.Remote.Addr, Relationship: link.LinkTo, MTU: link.MTU, @@ -192,7 +192,7 @@ func (c *Connector) ListExternalInterfaces() ([]control.ExternalInterface, error externalInterfaceList := make([]control.ExternalInterface, 0, len(c.externalInterfaces)) for _, externalInterface := range c.externalInterfaces { - externalInterface.State = c.DataPlane.getInterfaceState(externalInterface.InterfaceID) + externalInterface.State = c.DataPlane.getInterfaceState(externalInterface.IfID) externalInterfaceList = append(externalInterfaceList, externalInterface) } return externalInterfaceList, nil @@ -204,7 +204,7 @@ func (c *Connector) ListSiblingInterfaces() ([]control.SiblingInterface, error) siblingInterfaceList := make([]control.SiblingInterface, 0, len(c.siblingInterfaces)) for _, siblingInterface := range c.siblingInterfaces { - siblingInterface.State = c.DataPlane.getInterfaceState(siblingInterface.InterfaceID) + siblingInterface.State = c.DataPlane.getInterfaceState(siblingInterface.IfID) siblingInterfaceList = append(siblingInterfaceList, siblingInterface) } return siblingInterfaceList, nil diff --git a/router/control/conf.go b/router/control/conf.go index f98f570bb3..f9676c12ea 100644 --- a/router/control/conf.go +++ b/router/control/conf.go @@ -32,7 +32,7 @@ import ( type Dataplane interface { CreateIACtx(ia addr.IA) error AddInternalInterface(ia addr.IA, local netip.AddrPort) error - AddExternalInterface(localIfID common.IFIDType, info LinkInfo, owned bool) error + AddExternalInterface(localIfID common.IfIDType, info LinkInfo, owned bool) error AddSvc(ia addr.IA, svc addr.SVC, a netip.AddrPort) error DelSvc(ia addr.IA, svc addr.SVC, a netip.AddrPort) error SetKey(ia addr.IA, index int, key []byte) error @@ -57,7 +57,7 @@ type LinkInfo struct { type LinkEnd struct { IA addr.IA Addr netip.AddrPort - IFID common.IFIDType + IfID common.IfIDType } type ObservableDataplane interface { @@ -75,7 +75,7 @@ type InternalInterface struct { // ExternalInterface represents an external interface of a router. type ExternalInterface struct { // InterfaceID is the identifier of the external interface. - InterfaceID uint16 + IfID uint16 // Link is the information associated with this link. Link LinkInfo // State indicates the interface state. @@ -85,7 +85,7 @@ type ExternalInterface struct { // SiblingInterface represents a sibling interface of a router. type SiblingInterface struct { // InterfaceID is the identifier of the external interface. - InterfaceID uint16 + IfID uint16 // InternalInterfaces is the local address (internal interface) // of the sibling router that owns this interface. InternalInterface netip.AddrPort @@ -163,30 +163,30 @@ func DeriveHFMacKey(k []byte) []byte { } func confExternalInterfaces(dp Dataplane, cfg *Config) error { - // Sort out keys/ifids to get deterministic order for unit testing + // Sort out keys/ifIDs to get deterministic order for unit testing infoMap := cfg.Topo.IFInfoMap() if len(infoMap) == 0 { // nothing to do return nil } - ifids := []common.IFIDType{} + ifIDs := []common.IfIDType{} for k := range infoMap { - ifids = append(ifids, k) + ifIDs = append(ifIDs, k) } - sort.Slice(ifids, func(i, j int) bool { return ifids[i] < ifids[j] }) + sort.Slice(ifIDs, func(i, j int) bool { return ifIDs[i] < ifIDs[j] }) // External interfaces - for _, ifid := range ifids { - iface := infoMap[ifid] + for _, ifID := range ifIDs { + iface := infoMap[ifID] linkInfo := LinkInfo{ Local: LinkEnd{ IA: cfg.IA, Addr: iface.Local, - IFID: iface.ID, + IfID: iface.ID, }, Remote: LinkEnd{ IA: iface.IA, Addr: iface.Remote, - IFID: iface.RemoteIFID, + IfID: iface.RemoteIfID, }, Instance: iface.BRName, BFD: BFD(iface.BFD), @@ -194,7 +194,7 @@ func confExternalInterfaces(dp Dataplane, cfg *Config) error { MTU: iface.MTU, } - _, owned := cfg.BR.IFs[ifid] + _, owned := cfg.BR.IFs[ifID] if !owned { // XXX The current implementation effectively uses IP/UDP tunnels to create // the SCION network as an overlay, with forwarding to local hosts being a special case. @@ -207,7 +207,7 @@ func confExternalInterfaces(dp Dataplane, cfg *Config) error { linkInfo.BFD = BFD{} } - if err := dp.AddExternalInterface(ifid, linkInfo, owned); err != nil { + if err := dp.AddExternalInterface(ifID, linkInfo, owned); err != nil { return err } } diff --git a/router/control/internal/metrics/metrics.go b/router/control/internal/metrics/metrics.go index 1c47320808..d33f57af83 100644 --- a/router/control/internal/metrics/metrics.go +++ b/router/control/internal/metrics/metrics.go @@ -65,9 +65,9 @@ func (l IntfLabels) Values() []string { return []string{l.Intf, l.NeighIA} } -func IntfToLabel(ifid common.IFIDType) string { - if ifid == 0 { +func IntfToLabel(ifID common.IfIDType) string { + if ifID == 0 { return "loc" } - return ifid.String() + return ifID.String() } diff --git a/router/dataplane.go b/router/dataplane.go index 306e14cea5..e318c3729f 100644 --- a/router/dataplane.go +++ b/router/dataplane.go @@ -464,9 +464,9 @@ func (d *DataPlane) addExternalInterfaceBFD(ifID uint16, conn BatchConn, // getInterfaceState checks if there is a bfd session for the input interfaceID and // returns InterfaceUp if the relevant bfdsession state is up, or if there is no BFD // session. Otherwise, it returns InterfaceDown. -func (d *DataPlane) getInterfaceState(interfaceID uint16) control.InterfaceState { +func (d *DataPlane) getInterfaceState(ifID uint16) control.InterfaceState { bfdSessions := d.bfdSessions - if bfdSession, ok := bfdSessions[interfaceID]; ok && !bfdSession.IsUp() { + if bfdSession, ok := bfdSessions[ifID]; ok && !bfdSession.IsUp() { return control.InterfaceDown } return control.InterfaceUp @@ -1835,7 +1835,7 @@ func (p *scionPacketProcessor) egressRouterAlertFlag() *bool { return &p.hopField.EgressRouterAlert } -func (p *slowPathPacketProcessor) handleSCMPTraceRouteRequest(interfaceID uint16) error { +func (p *slowPathPacketProcessor) handleSCMPTraceRouteRequest(ifID uint16) error { if p.lastLayer.NextLayerType() != slayers.LayerTypeSCMP { log.Debug("Packet with router alert, but not SCMP") @@ -1861,7 +1861,7 @@ func (p *slowPathPacketProcessor) handleSCMPTraceRouteRequest(interfaceID uint16 Identifier: scmpP.Identifier, Sequence: scmpP.Sequence, IA: p.d.localIA, - Interface: uint64(interfaceID), + Interface: uint64(ifID), } return p.packSCMP(slayers.SCMPTypeTracerouteReply, 0, &scmpP, false) } @@ -2709,11 +2709,11 @@ func nextHdr(layer gopacket.DecodingLayer) slayers.L4ProtocolType { func (d *DataPlane) initMetrics() { d.forwardingMetrics = make(map[uint16]interfaceMetrics) d.forwardingMetrics[0] = newInterfaceMetrics(d.Metrics, 0, d.localIA, d.neighborIAs) - for id := range d.external { - if _, notOwned := d.internalNextHops[id]; notOwned { + for ifID := range d.external { + if _, notOwned := d.internalNextHops[ifID]; notOwned { continue } - d.forwardingMetrics[id] = newInterfaceMetrics(d.Metrics, id, d.localIA, d.neighborIAs) + d.forwardingMetrics[ifID] = newInterfaceMetrics(d.Metrics, ifID, d.localIA, d.neighborIAs) } // Start our custom /proc/pid/stat collector to export iowait time and (in the future) other diff --git a/router/mgmtapi/api.go b/router/mgmtapi/api.go index 639b8832e2..eb127c88b7 100644 --- a/router/mgmtapi/api.go +++ b/router/mgmtapi/api.go @@ -102,7 +102,7 @@ func (s *Server) GetInterfaces(w http.ResponseWriter, r *http.Request) { Enabled: !*(intf.Link.BFD.Disable), RequiredMinimumReceive: intf.Link.BFD.RequiredMinRxInterval.String(), }, - InterfaceId: int(intf.InterfaceID), + InterfaceId: int(intf.IfID), // nolint - name from published API. InternalInterface: findInternalInterface(intf.Link.Local.IA), Neighbor: InterfaceNeighbor{ Address: intf.Link.Remote.Addr.String(), @@ -118,7 +118,7 @@ func (s *Server) GetInterfaces(w http.ResponseWriter, r *http.Request) { for _, intf := range siblingInterfaces { siblingInterface := SiblingInterface{ - InterfaceId: int(intf.InterfaceID), + InterfaceId: int(intf.IfID), // nolint - name from published API. InternalInterface: intf.InternalInterface.String(), Neighbor: SiblingNeighbor{ IsdAs: intf.NeighborIA.String(), diff --git a/router/mgmtapi/api_test.go b/router/mgmtapi/api_test.go index c6e01412e3..8683a86544 100644 --- a/router/mgmtapi/api_test.go +++ b/router/mgmtapi/api_test.go @@ -154,7 +154,7 @@ func TestAPI(t *testing.T) { func createExternalIntfs(t *testing.T) []control.ExternalInterface { return []control.ExternalInterface{ { - InterfaceID: 1, + IfID: 1, Link: control.LinkInfo{ Local: control.LinkEnd{ IA: addr.MustParseIA("1-ff00:0:110"), @@ -177,7 +177,7 @@ func createExternalIntfs(t *testing.T) []control.ExternalInterface { State: control.InterfaceUp, }, { - InterfaceID: 2, + IfID: 2, Link: control.LinkInfo{ Local: control.LinkEnd{ IA: addr.MustParseIA("1-ff00:0:110"), @@ -200,7 +200,7 @@ func createExternalIntfs(t *testing.T) []control.ExternalInterface { State: control.InterfaceUp, }, { - InterfaceID: 5, + IfID: 5, Link: control.LinkInfo{ Local: control.LinkEnd{ IA: addr.MustParseIA("1-ff00:0:111"), @@ -223,7 +223,7 @@ func createExternalIntfs(t *testing.T) []control.ExternalInterface { State: control.InterfaceUp, }, { - InterfaceID: 6, + IfID: 6, Link: control.LinkInfo{ Local: control.LinkEnd{ IA: addr.MustParseIA("1-ff00:0:112"), @@ -264,7 +264,7 @@ func createInternalIntfs(t *testing.T) []control.InternalInterface { func createSiblingIntfs(t *testing.T) []control.SiblingInterface { return []control.SiblingInterface{ { - InterfaceID: 5, + IfID: 5, InternalInterface: netip.MustParseAddrPort("172.20.0.20:30042"), Relationship: topology.Parent, MTU: 1280, diff --git a/scion/cmd/scion/common.go b/scion/cmd/scion/common.go index 1bd4abe356..edf290ed8d 100644 --- a/scion/cmd/scion/common.go +++ b/scion/cmd/scion/common.go @@ -43,7 +43,7 @@ type Path struct { // Hop represents an hop on the path. type Hop struct { - ID common.IFIDType `json:"interface" yaml:"interface"` + ID common.IfIDType `json:"interface" yaml:"interface"` IA addr.IA `json:"isd_as" yaml:"isd_as"` } diff --git a/scion/cmd/scion/traceroute.go b/scion/cmd/scion/traceroute.go index addbc9b231..4438ccf1cf 100644 --- a/scion/cmd/scion/traceroute.go +++ b/scion/cmd/scion/traceroute.go @@ -266,14 +266,14 @@ func fmtRemote(remote snet.SCIONAddress, intf uint64) string { func getHopInfo(u traceroute.Update, hop Hop) HopInfo { if u.Remote == (snet.SCIONAddress{}) { - return HopInfo{IA: hop.IA, InterfaceID: uint16(hop.ID)} + return HopInfo{IA: hop.IA, InterfaceID: uint16(hop.ID)} // nolint - name from published API } RTTs := make([]durationMillis, 0, len(u.RTTs)) for _, rtt := range u.RTTs { RTTs = append(RTTs, durationMillis(rtt)) } return HopInfo{ - InterfaceID: uint16(u.Interface), + InterfaceID: uint16(u.Interface), // nolint - name from published protobuf IP: u.Remote.Host.IP().String(), IA: u.Remote.IA, RoundTripTimes: RTTs, diff --git a/scion/showpaths/showpaths.go b/scion/showpaths/showpaths.go index 85b6c0b833..37319efd0d 100644 --- a/scion/showpaths/showpaths.go +++ b/scion/showpaths/showpaths.go @@ -58,7 +58,7 @@ type Path struct { // Hop represents an hop on the path. type Hop struct { - IfID common.IFIDType `json:"ifid"` + IfID common.IfIDType `json:"interface"` IA addr.IA `json:"isd_as"` } @@ -242,8 +242,8 @@ func humanInternalHops(p *snet.PathMetadata) string { if numHops == 0 { continue } - interfaceIdx := 2*i + 1 - ia := p.Interfaces[interfaceIdx].IA + interfaceIndex := 2*i + 1 + ia := p.Interfaces[interfaceIndex].IA internalHops = append(internalHops, fmt.Sprintf("%s: %d", ia, numHops)) } if len(internalHops) == 0 { @@ -260,11 +260,11 @@ func humanNotes(p *snet.PathMetadata) string { if note == "" { continue } - interfaceIdx := 0 + interfaceIndex := 0 if i > 0 { - interfaceIdx = 2*i - 1 + interfaceIndex = 2*i - 1 } - ia := p.Interfaces[interfaceIdx].IA + ia := p.Interfaces[interfaceIndex].IA notes = append(notes, fmt.Sprintf("%s: \"%s\"", ia, sanitizeString(note))) } if len(notes) == 0 { diff --git a/tools/wireshark/scion.lua b/tools/wireshark/scion.lua index 5ec622c68b..3ef19b2f2e 100644 --- a/tools/wireshark/scion.lua +++ b/tools/wireshark/scion.lua @@ -129,6 +129,27 @@ scion_proto.experts = { e_nosup_proto, } +-- This function heuristically identifies SCION packets. If the packet looks like it may be +-- a SCION packet, it returns true, which causes the associated scion disector to be invoked. +-- This doesn't have much data available to weed out non-SCION packets. False positives end-up being +-- described as broken SCION packets and are not passed to the vanilla UDP parser. +-- However, with the removal of the dispatcher, we have no narrow set of UDP ports to identify +-- SCION traffic from. So, there's no choice. +local function scion_proto_filter(tvbuf, pktinfo, root) + local version_valid = (bit.rshift(tvbuf(0,1):uint(), 4) == 0) + local next_hdr_valid = (hdrTypes[tvbuf(4, 1):uint()] ~= nil) + local path_type_valid = (tvbuf(8, 1):uint() < 5) + local addr_type_dst_valid = (addrTypes[bit.rshift(tvbuf(9, 1):uint(), 4)] ~= nil) + local addr_type_src_valid = (addrTypes[bit.band(tvbuf(9, 1):uint(), 0xf)] ~= nil) + local rsv_valid = (tvbuf(10, 2):uint() == 0) + + if version_valid and next_hdr_valid and path_type_valid and addr_type_dst_valid and addr_type_src_valid and rsv_valid then + pktinfo.conversation = scion_proto + return true + end + return false +end + function scion_proto.dissector(tvbuf, pktinfo, root) local tree = root:add(scion_proto, tvbuf()) local header_str = tree @@ -280,9 +301,9 @@ end function addr_str(buf, addrTypeLen, with_svc) local addrType = addrTypes[addrTypeLen] if addrType == "IPv4" then - return string.format("%s", buf:ipv4()) + return string.format("%s", tostring(buf:ipv4())) elseif addrType == "IPv6" then - return string.format("%s", buf:ipv6()) + return string.format("%s", tostring(buf:ipv6())) elseif with_svc and addrType == "SVC" then local svcVal = buf(0, 2):uint() local svc = svcTypes[svcVal] @@ -1152,21 +1173,28 @@ function scmp_proto_dissect(tvbuf, pktinfo, root) end --- Below we configure Wireshark to identify SCION as the next protocol when using --- the specified range of ports. --- -- SCION packet on UDP/IP overlay. -table_udp = DissectorTable.get("udp.port") --- intra-AS traffic -for i = 30000, 32000, 1 do - table_udp:add(i, scion_proto) -end --- inter-AS BR traffic -for i = 40000, 40050, 1 do - table_udp:add(i, scion_proto) -end --- FIXME remove once acceptance tests are updated to use ports above --- acceptance tests -for i = 50000, 50050, 1 do - table_udp:add(i, scion_proto) -end +-- Two options are available. Identify SCION traffic by port number, or heuristically, by +-- looking for clues in the header. The heuristic is not extremely robust. It may mistake +-- non-SCION packet for SCION packets. If you know precisely which ports carry SCION +-- traffic (which is made difficult by the removal of the dispatcher), you may prefer to +-- identify them by port. Keep the unwanted option commented out. + +-- Heuristic selection +scion_proto:register_heuristic("udp", scion_proto_filter) + +-- Port-based selection +-- table_udp = DissectorTable.get("udp.port") +-- -- intra-AS traffic +-- for i = 31000, 32767, 1 do +-- table_udp:add(i, scion_proto) +-- end +-- -- inter-AS BR traffic +-- for i = 40000, 40050, 1 do +-- table_udp:add(i, scion_proto) +-- end +-- -- FIXME remove once acceptance tests are updated to use ports above +-- -- acceptance tests +-- for i = 50000, 50050, 1 do +-- table_udp:add(i, scion_proto) +-- end