Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: replace deprecated grpc packages #4686

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion control/trust/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ go_test(
"//pkg/addr:go_default_library",
"//pkg/proto/control_plane:go_default_library",
"//pkg/scrypto/cppki:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
],
)
8 changes: 3 additions & 5 deletions control/trust/grpc/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"testing"
"time"

"github.com/golang/protobuf/ptypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"

trustgrpc "github.com/scionproto/scion/control/trust/grpc"
"github.com/scionproto/scion/pkg/addr"
Expand All @@ -31,10 +31,8 @@ import (

func TestReqToChainQuery(t *testing.T) {
now := time.Now().UTC()
validUntil, err := ptypes.TimestampProto(now)
require.NoError(t, err)
validSince, err := ptypes.TimestampProto(now.Add(-time.Hour))
require.NoError(t, err)
validUntil := timestamppb.New(now)
validSince := timestamppb.New(now.Add(-time.Hour))

req := &cppb.ChainsRequest{
IsdAs: uint64(addr.MustParseIA("1-ff00:0:110")),
Expand Down
2 changes: 1 addition & 1 deletion daemon/drkey/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ go_test(
"//pkg/proto/control_plane:go_default_library",
"//pkg/proto/control_plane/mock_control_plane:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
"@com_github_stretchr_testify//require:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
],
)
10 changes: 4 additions & 6 deletions daemon/drkey/grpc/fetching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"time"

"github.com/golang/mock/gomock"
"github.com/golang/protobuf/ptypes"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"

sd_drkey "github.com/scionproto/scion/daemon/drkey"
sd_grpc "github.com/scionproto/scion/daemon/drkey/grpc"
Expand All @@ -38,10 +38,8 @@ func TestGetHostHost(t *testing.T) {
defer ctrl.Finish()

now := time.Now().UTC()
epochBegin, err := ptypes.TimestampProto(now)
require.NoError(t, err)
epochEnd, err := ptypes.TimestampProto(now.Add(24 * time.Hour))
require.NoError(t, err)
epochBegin := timestamppb.New(now)
epochEnd := timestamppb.New(now.Add(24 * time.Hour))

resp := &cppb.DRKeyHostHostResponse{
Key: xtest.MustParseHexString("c584cad32613547c64823c756651b6f5"),
Expand All @@ -65,6 +63,6 @@ func TestGetHostHost(t *testing.T) {
}

meta := drkey.HostHostMeta{}
_, err = fetcher.HostHostKey(context.Background(), meta)
_, err := fetcher.HostHostKey(context.Background(), meta)
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions daemon/internal/servers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ go_library(
"//private/revcache:go_default_library",
"//private/topology:go_default_library",
"//private/trust:go_default_library",
"@com_github_golang_protobuf//ptypes/duration",
"@com_github_golang_protobuf//ptypes/timestamp",
"@com_github_opentracing_opentracing_go//:go_default_library",
"@org_golang_google_protobuf//types/known/durationpb:go_default_library",
"@org_golang_google_protobuf//types/known/emptypb:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
"@org_golang_x_sync//singleflight:go_default_library",
],
)
4 changes: 2 additions & 2 deletions daemon/internal/servers/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"net"
"time"

durationpb "github.com/golang/protobuf/ptypes/duration"
timestamppb "github.com/golang/protobuf/ptypes/timestamp"
"github.com/opentracing/opentracing-go"
"golang.org/x/sync/singleflight"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"

drkey_daemon "github.com/scionproto/scion/daemon/drkey"
"github.com/scionproto/scion/daemon/fetcher"
Expand Down
1 change: 1 addition & 0 deletions demo/drkey/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_library(
"//private/app/flag:go_default_library",
"@com_github_spf13_pflag//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/insecure:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
],
)
Expand Down
5 changes: 4 additions & 1 deletion demo/drkey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

flag "github.com/spf13/pflag"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/scionproto/scion/pkg/addr"
Expand Down Expand Up @@ -270,7 +271,9 @@ func (s Server) FetchSV(
}

// Contact CS directly for SV
conn, err := grpc.DialContext(ctx, cs[0], grpc.WithInsecure())
conn, err := grpc.DialContext(
ctx, cs[0], grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return drkey.SecretValue{}, serrors.Wrap("dialing control service", err)
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/cors v1.2.1
github.com/golang/mock v1.7.0-rc.1
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.6.0
github.com/google/gopacket v1.1.19
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
Expand Down
1 change: 0 additions & 1 deletion pkg/experimental/hiddenpath/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ go_library(
"//pkg/snet:go_default_library",
"//private/segment/segfetcher:go_default_library",
"//private/segment/verifier:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//peer:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
Expand Down
3 changes: 1 addition & 2 deletions pkg/experimental/hiddenpath/grpc/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import (

"github.com/scionproto/scion/pkg/experimental/hiddenpath"
"github.com/scionproto/scion/pkg/grpc"
libgrpc "github.com/scionproto/scion/pkg/grpc"
"github.com/scionproto/scion/pkg/private/serrors"
dspb "github.com/scionproto/scion/pkg/proto/discovery"
)

// Discoverer can be used to discover remote hidden path instances.
type Discoverer struct {
// Dialer dials a new gRPC connection.
Dialer libgrpc.Dialer
Dialer grpc.Dialer
}

// Discover discovers hidden path services at the discovery service that is
Expand Down
2 changes: 1 addition & 1 deletion pkg/experimental/hiddenpath/grpc/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"context"
"net"

"github.com/golang/protobuf/proto"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/proto"

"github.com/scionproto/scion/pkg/experimental/hiddenpath"
libgrpc "github.com/scionproto/scion/pkg/grpc"
Expand Down
1 change: 1 addition & 0 deletions pkg/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
"@com_github_uber_jaeger_client_go//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
"@org_golang_google_grpc//credentials/insecure:go_default_library",
"@org_golang_google_grpc//resolver:go_default_library",
"@org_golang_google_grpc//resolver/manual:go_default_library",
],
Expand Down
7 changes: 4 additions & 3 deletions pkg/grpc/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"

Expand All @@ -43,7 +44,7 @@ type SimpleDialer struct{}
// Dial dials the address by converting it to a string.
func (SimpleDialer) Dial(ctx context.Context, address net.Addr) (*grpc.ClientConn, error) {
return grpc.DialContext(ctx, address.String(),
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
UnaryClientInterceptor(),
StreamClientInterceptor(),
Expand Down Expand Up @@ -106,15 +107,15 @@ func (t *TCPDialer) Dial(ctx context.Context, dst net.Addr) (*grpc.ClientConn, e
r.InitialState(resolver.State{Addresses: targets})
return grpc.DialContext(ctx, r.Scheme()+":///"+v.SVC.BaseString(),
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin":{}}]}`),
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithResolvers(r),
UnaryClientInterceptor(),
StreamClientInterceptor(),
)
}

return grpc.DialContext(ctx, dst.String(),
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
UnaryClientInterceptor(),
StreamClientInterceptor(),
)
Expand Down
4 changes: 3 additions & 1 deletion pkg/private/xtest/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ func (s *GRPCService) Start(t *testing.T) {
}

func (s *GRPCService) Dial(ctx context.Context, addr net.Addr) (*grpc.ClientConn, error) {
transportSecurity := grpc.WithInsecure()
var transportSecurity grpc.DialOption
if s.clientCredentials != nil {
transportSecurity = grpc.WithTransportCredentials(s.clientCredentials)
} else {
transportSecurity = grpc.WithTransportCredentials(insecure.NewCredentials())
}
return grpc.DialContext(ctx, addr.String(),
grpc.WithContextDialer(
Expand Down
3 changes: 1 addition & 2 deletions pkg/scrypto/signed/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ go_library(
deps = [
"//pkg/private/serrors:go_default_library",
"//pkg/proto/crypto:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
"@com_github_golang_protobuf//ptypes/timestamp",
"@org_golang_google_protobuf//proto:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
],
)

Expand Down
16 changes: 4 additions & 12 deletions pkg/scrypto/signed/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
"fmt"
"time"

"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/timestamp"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/scionproto/scion/pkg/private/serrors"
cryptopb "github.com/scionproto/scion/pkg/proto/crypto"
Expand Down Expand Up @@ -66,13 +65,9 @@ func Sign(hdr Header, body []byte, signer crypto.Signer,
if err := checkPubKeyAlgo(hdr.SignatureAlgorithm, signer.Public()); err != nil {
return nil, err
}
var ts *timestamp.Timestamp
var ts *timestamppb.Timestamp
if !hdr.Timestamp.IsZero() {
var err error
ts, err = ptypes.TimestampProto(hdr.Timestamp)
if err != nil {
return nil, serrors.Wrap("converting timestamp", err)
}
ts = timestamppb.New(hdr.Timestamp)
}

inputHdr := &cryptopb.Header{
Expand Down Expand Up @@ -220,10 +215,7 @@ func extractHeaderAndBody(signed *cryptopb.SignedMessage) (*Header, []byte, erro
}
var ts time.Time
if hdr.Timestamp != nil {
var err error
if ts, err = ptypes.Timestamp(hdr.Timestamp); err != nil {
return nil, nil, err
}
ts = hdr.Timestamp.AsTime()
}
return &Header{
SignatureAlgorithm: signatureAlgorithmFromPB(hdr.SignatureAlgorithm),
Expand Down
1 change: 1 addition & 0 deletions pkg/snet/squic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ go_test(
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/insecure:go_default_library",
],
)
5 changes: 3 additions & 2 deletions pkg/snet/squic/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

cppb "github.com/scionproto/scion/pkg/proto/control_plane"
mock_cp "github.com/scionproto/scion/pkg/proto/control_plane/mock_control_plane"
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestAcceptLoopParallelism(t *testing.T) {

dialer := connDialer(t)
conn, err := grpc.DialContext(ctx, "server",
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) {
return dialer.Dial(ctx, srvConn.LocalAddr())
}),
Expand Down Expand Up @@ -131,7 +132,7 @@ func TestGRPCQUIC(t *testing.T) {

dialer := connDialer(t)
conn, err := grpc.DialContext(context.Background(), "server",
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) {
return dialer.Dial(ctx, srvConn.LocalAddr())
}),
Expand Down
2 changes: 1 addition & 1 deletion private/trust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ go_test(
"//scion-pki/testcrypto:go_default_library",
"//scion-pki/trcs:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_google_go_cmp//cmp:go_default_library",
"@com_github_patrickmn_go_cache//:go_default_library",
"@com_github_prometheus_client_golang//prometheus/testutil:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

Expand Down
3 changes: 1 addition & 2 deletions private/trust/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ go_library(
"//private/tracing:go_default_library",
"//private/trust:go_default_library",
"//private/trust/internal/metrics:go_default_library",
"@com_github_golang_protobuf//ptypes/timestamp",
"@com_github_opentracing_opentracing_go//:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
],
)

Expand All @@ -47,7 +47,6 @@ go_test(
"//private/trust/internal/metrics:go_default_library",
"//scion-pki/testcrypto:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
Expand Down
2 changes: 1 addition & 1 deletion private/trust/grpc/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package grpc
import (
"crypto/x509"

timestamppb "github.com/golang/protobuf/ptypes/timestamp"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/scionproto/scion/pkg/private/serrors"
cppb "github.com/scionproto/scion/pkg/proto/control_plane"
Expand Down
7 changes: 2 additions & 5 deletions private/trust/grpc/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"
"time"

"github.com/golang/protobuf/ptypes"
"github.com/stretchr/testify/assert"

"github.com/scionproto/scion/pkg/addr"
Expand All @@ -44,11 +43,9 @@ func TestChainQueryToReq(t *testing.T) {
req := trustgrpc.ChainQueryToReq(query)
assert.Equal(t, uint64(query.IA), req.IsdAs)
assert.Equal(t, query.SubjectKeyID, req.SubjectKeyId)
validSince, err := ptypes.Timestamp(req.AtLeastValidSince)
assert.NoError(t, err)
validSince := req.AtLeastValidSince.AsTime()
assert.Equal(t, query.Validity.NotBefore, validSince)
validUntil, err := ptypes.Timestamp(req.AtLeastValidUntil)
assert.NoError(t, err)
validUntil := req.AtLeastValidUntil.AsTime()
assert.Equal(t, query.Validity.NotAfter, validUntil)
}

Expand Down
2 changes: 1 addition & 1 deletion private/trust/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/scionproto/scion/pkg/addr"
cppb "github.com/scionproto/scion/pkg/proto/control_plane"
Expand Down
Loading