Skip to content

Commit

Permalink
deps: replace inet.af/netaddr with net/netip and go4.org/netipx (#4313)
Browse files Browse the repository at this point in the history
Replace deprecated inet.af/netaddr with its standard library replacement
package net/netip. Use go4.org/netipx for some the pieces that were not
added to the standard library.

This change does not affect the `snet` API, or any other public API.
  • Loading branch information
marcfrei committed May 12, 2023
1 parent 91d8cfb commit c43f942
Show file tree
Hide file tree
Showing 50 changed files with 152 additions and 239 deletions.
1 change: 0 additions & 1 deletion control/beaconing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ go_test(
"//private/segment/verifier/mock_verifier:go_default_library",
"//private/topology:go_default_library",
"//private/trust:go_default_library",
"@af_inet_netaddr//:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion control/beaconing/originator.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (o *beaconOriginator) originateBeacon(ctx context.Context) error {
senderCtx,
topoInfo.IA,
o.intf.TopoInfo().ID,
topoInfo.InternalAddr.UDPAddr(),
net.UDPAddrFromAddrPort(topoInfo.InternalAddr),
)
if err != nil {
o.incrementMetrics(labels.WithResult(prom.ErrNetwork))
Expand Down
2 changes: 1 addition & 1 deletion control/beaconing/originator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestOriginatorRun(t *testing.T) {
// Check the interface matches.
assert.Equal(t, hopF.ConsEgress, egIfId)
// Check that the beacon is sent to the correct border router.
br := interfaceInfos(topo)[egIfId].InternalAddr.UDPAddr()
br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr)
assert.Equal(t, br, nextHop)
return nil
},
Expand Down
3 changes: 2 additions & 1 deletion control/beaconing/propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package beaconing

import (
"context"
"net"
"sort"
"strconv"
"sync"
Expand Down Expand Up @@ -266,7 +267,7 @@ func (p *propagator) Propagate(ctx context.Context) error {
senderCtx,
topoInfo.IA,
egress,
topoInfo.InternalAddr.UDPAddr(),
net.UDPAddrFromAddrPort(topoInfo.InternalAddr),
)
if err != nil {
for _, b := range p.beacons {
Expand Down
2 changes: 1 addition & 1 deletion control/beaconing/propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,6 @@ func validateSend(
// Check the interface matches.
assert.Equal(t, hopF.ConsEgress, egIfId)
// Check that the beacon is sent to the correct border router.
br := interfaceInfos(topo)[egIfId].InternalAddr.UDPAddr()
br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr)
assert.Equal(t, br, nextHop)
}
6 changes: 3 additions & 3 deletions control/beaconing/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"fmt"
"hash"
"net"
"net/netip"
"sync"
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"inet.af/netaddr"

"github.com/scionproto/scion/control/beacon"
"github.com/scionproto/scion/control/beaconing"
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestRegistrarRun(t *testing.T) {
assert.Equal(t, pathHopField.ConsEgress, segHopField.ConsEgress)

nextHop := pathHopField.ConsIngress
a := interfaceInfos(topo)[nextHop].InternalAddr.UDPAddr()
a := net.UDPAddrFromAddrPort(interfaceInfos(topo)[nextHop].InternalAddr)
assert.Equal(t, a, s.Addr.NextHop)
}
})
Expand Down Expand Up @@ -371,7 +371,7 @@ func interfaceInfos(topo topology.Topology) map[uint16]ifstate.InterfaceInfo {
ID: uint16(info.ID),
IA: info.IA,
LinkType: info.LinkType,
InternalAddr: netaddr.MustParseIPPort(info.InternalAddr.String()),
InternalAddr: netip.MustParseAddrPort(info.InternalAddr.String()),
RemoteID: uint16(info.RemoteIFID),
MTU: uint16(info.MTU),
}
Expand Down
2 changes: 1 addition & 1 deletion control/cmd/control/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ go_library(
"//private/trust/compat:go_default_library",
"//private/trust/grpc:go_default_library",
"//private/trust/metrics:go_default_library",
"@af_inet_netaddr//:go_default_library",
"@com_github_go_chi_chi_v5//:go_default_library",
"@com_github_go_chi_cors//:go_default_library",
"@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@in_gopkg_yaml_v2//:go_default_library",
"@org_go4_netipx//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//health:go_default_library",
"@org_golang_google_grpc//health/grpc_health_v1:go_default_library",
Expand Down
4 changes: 2 additions & 2 deletions control/cmd/control/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (
"github.com/go-chi/cors"
promgrpc "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/spf13/cobra"
"go4.org/netipx"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"inet.af/netaddr"

cs "github.com/scionproto/scion/control"
"github.com/scionproto/scion/control/beacon"
Expand Down Expand Up @@ -834,7 +834,7 @@ func createBeaconStore(
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 {
addr, ok := netaddr.FromStdAddr(
addr, ok := netipx.FromStdAddr(
info.InternalAddr.IP,
info.InternalAddr.Port,
info.InternalAddr.Zone,
Expand Down
2 changes: 0 additions & 2 deletions control/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ go_library(
"//private/mgmtapi/jwtauth:go_default_library",
"//private/storage:go_default_library",
"//private/trust/config:go_default_library",
"@af_inet_netaddr//:go_default_library",
],
)

Expand All @@ -41,7 +40,6 @@ go_test(
"//private/mgmtapi/mgmtapitest:go_default_library",
"//private/storage:go_default_library",
"//private/storage/test:go_default_library",
"@af_inet_netaddr//:go_default_library",
"@com_github_pelletier_go_toml//:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
Expand Down
7 changes: 3 additions & 4 deletions control/config/drkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ package config

import (
"io"
"net/netip"
"strings"
"time"

"inet.af/netaddr"

"github.com/scionproto/scion/pkg/addr"
"github.com/scionproto/scion/pkg/drkey"
"github.com/scionproto/scion/pkg/private/serrors"
Expand Down Expand Up @@ -138,7 +137,7 @@ func (cfg *SecretValueHostList) ConfigName() string {
}

type HostProto struct {
Host netaddr.IP
Host netip.Addr
Proto drkey.Protocol
}

Expand All @@ -147,7 +146,7 @@ func (cfg *SecretValueHostList) ToAllowedSet() map[HostProto]struct{} {
m := make(map[HostProto]struct{})
for proto, ipList := range *cfg {
for _, ip := range ipList {
host, err := netaddr.ParseIP(ip)
host, err := netip.ParseAddr(ip)
if err != nil {
continue
}
Expand Down
6 changes: 3 additions & 3 deletions control/config/drkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ package config

import (
"bytes"
"net/netip"
"os"
"testing"

toml "github.com/pelletier/go-toml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"inet.af/netaddr"

"github.com/scionproto/scion/pkg/drkey"
"github.com/scionproto/scion/private/storage"
Expand Down Expand Up @@ -107,9 +107,9 @@ func TestSecretValueHostListSyntax(t *testing.T) {
func TestToMapPerHost(t *testing.T) {
var cfg SecretValueHostList
sample := `scmp = ["1.1.1.1", "2.2.2.2"]`
ip1111, err := netaddr.ParseIP("1.1.1.1")
ip1111, err := netip.ParseAddr("1.1.1.1")
require.NoError(t, err)
ip2222, err := netaddr.ParseIP("2.2.2.2")
ip2222, err := netip.ParseAddr("2.2.2.2")
require.NoError(t, err)
err = toml.NewDecoder(bytes.NewReader([]byte(sample))).Strict(true).Decode(&cfg)
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions control/drkey/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go_library(
"//pkg/proto/drkey:go_default_library",
"//pkg/scrypto/cppki:go_default_library",
"//pkg/snet:go_default_library",
"@af_inet_netaddr//:go_default_library",
"@org_go4_netipx//:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
"@org_golang_google_grpc//peer:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
Expand Down Expand Up @@ -54,7 +54,6 @@ go_test(
"//private/trust:go_default_library",
"//private/trust/mock_trust:go_default_library",
"//scion-pki/testcrypto:go_default_library",
"@af_inet_netaddr//:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
Expand Down
4 changes: 2 additions & 2 deletions control/drkey/grpc/drkey_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"crypto/x509"
"net"

"go4.org/netipx"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/peer"
"google.golang.org/protobuf/types/known/timestamppb"
"inet.af/netaddr"

"github.com/scionproto/scion/control/config"
"github.com/scionproto/scion/pkg/addr"
Expand Down Expand Up @@ -263,7 +263,7 @@ func (d *Server) validateAllowedHost(protoId drkey.Protocol, peerAddr net.Addr)
return serrors.New("invalid peer address type, expected *net.TCPAddr",
"peer", peerAddr, "type", common.TypeOf(peerAddr))
}
localAddr, ok := netaddr.FromStdIP(tcpAddr.IP)
localAddr, ok := netipx.FromStdIP(tcpAddr.IP)
if !ok {
return serrors.New("unable to parse IP", "addr", tcpAddr.IP.String())
}
Expand Down
Loading

0 comments on commit c43f942

Please sign in to comment.