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

Move from gogo protobuf #975

Merged
merged 6 commits into from
Jan 29, 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
13 changes: 6 additions & 7 deletions crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"github.com/libp2p/go-libp2p/core/protocol"

logging "github.com/ipfs/go-log/v2"
//lint:ignore SA1019 TODO migrate away from gogo pb
"github.com/libp2p/go-msgio/protoio"
"github.com/libp2p/go-msgio/pbio"

pb "github.com/libp2p/go-libp2p-kad-dht/pb"
kbucket "github.com/libp2p/go-libp2p-kbucket"
Expand Down Expand Up @@ -85,12 +84,12 @@
return nil, err
}

w := protoio.NewDelimitedWriter(s)
w := pbio.NewDelimitedWriter(s)

Check warning on line 87 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L87

Added line #L87 was not covered by tests
if err := w.WriteMsg(pmes); err != nil {
return nil, err
}

r := protoio.NewDelimitedReader(s, network.MessageSizeMax)
r := pbio.NewDelimitedReader(s, network.MessageSizeMax)

Check warning on line 92 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L92

Added line #L92 was not covered by tests
defer func() { _ = s.Close() }()

msg := new(pb.Message)
Expand All @@ -102,9 +101,9 @@
return msg, nil
}

func ctxReadMsg(ctx context.Context, rc protoio.ReadCloser, mes *pb.Message) error {
func ctxReadMsg(ctx context.Context, rc pbio.ReadCloser, mes *pb.Message) error {

Check warning on line 104 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L104

Added line #L104 was not covered by tests
errc := make(chan error, 1)
go func(r protoio.ReadCloser) {
go func(r pbio.ReadCloser) {

Check warning on line 106 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L106

Added line #L106 was not covered by tests
defer close(errc)
err := r.ReadMsg(mes)
errc <- err
Expand All @@ -126,7 +125,7 @@
}
defer func() { _ = s.Close() }()

w := protoio.NewDelimitedWriter(s)
w := pbio.NewDelimitedWriter(s)

Check warning on line 128 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L128

Added line #L128 was not covered by tests
return w.WriteMsg(pmes)
}

Expand Down
2 changes: 1 addition & 1 deletion dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import (
record "github.com/libp2p/go-libp2p-record"
recpb "github.com/libp2p/go-libp2p-record/pb"

"github.com/gogo/protobuf/proto"
ds "github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log/v2"
"github.com/multiformats/go-base32"
ma "github.com/multiformats/go-multiaddr"
"go.opencensus.io/tag"
"go.uber.org/multierr"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion dht_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/libp2p/go-libp2p-kad-dht/internal/net"
"github.com/libp2p/go-libp2p-kad-dht/metrics"
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
"google.golang.org/protobuf/proto"

"github.com/libp2p/go-msgio"
"go.opencensus.io/stats"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (dht *IpfsDHT) handleNewMessage(s network.Stream) bool {
}
return false
}
err = req.Unmarshal(msgbytes)
err = proto.Unmarshal(msgbytes, &req)
r.ReleaseMsg(msgbytes)
if err != nil {
if c := baseLogger.Check(zap.DebugLevel, "error unmarshaling message"); c != nil {
Expand Down
7 changes: 4 additions & 3 deletions dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
manet "github.com/multiformats/go-multiaddr/net"
"github.com/multiformats/go-multihash"
"github.com/multiformats/go-multistream"
"google.golang.org/protobuf/proto"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1495,17 +1496,17 @@ func TestInvalidServer(t *testing.T) {
m1 := setupDHT(ctx, t, false, BucketSize(2)) // misbehabing server

// make m0 and m1 advertise all dht server protocols, but hang on all requests
for _, proto := range s0.serverProtocols {
for _, protocol := range s0.serverProtocols {
for _, m := range []*IpfsDHT{m0, m1} {
// Hang on every request.
m.host.SetStreamHandler(proto, func(s network.Stream) {
m.host.SetStreamHandler(protocol, func(s network.Stream) {
r := msgio.NewVarintReaderSize(s, network.MessageSizeMax)
msgbytes, err := r.ReadMsg()
if err != nil {
t.Fatal(err)
}
var req pb.Message
err = req.Unmarshal(msgbytes)
err = proto.Unmarshal(msgbytes, &req)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion fullrt/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
swarm "github.com/libp2p/go-libp2p/p2p/net/swarm"

"github.com/gogo/protobuf/proto"
"github.com/ipfs/go-cid"
ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
logging "github.com/ipfs/go-log/v2"
"google.golang.org/protobuf/proto"

kaddht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/libp2p/go-libp2p-kad-dht/crawler"
Expand Down
35 changes: 17 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ module github.com/libp2p/go-libp2p-kad-dht

go 1.22.0

toolchain go1.22.1

retract v0.24.3 // this includes a breaking change and should have been released as v0.25.0

require (
github.com/gogo/protobuf v1.3.2
github.com/google/gopacket v1.1.19
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru v1.0.2
github.com/ipfs/boxo v0.24.3
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/boxo v0.27.2
github.com/ipfs/go-cid v0.5.0
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipfs/go-test v0.0.4
github.com/libp2p/go-libp2p v0.38.1
github.com/libp2p/go-libp2p v0.38.2
github.com/libp2p/go-libp2p-kbucket v0.6.4
github.com/libp2p/go-libp2p-record v0.2.0
github.com/libp2p/go-libp2p-record v0.3.1
github.com/libp2p/go-libp2p-routing-helpers v0.7.4
github.com/libp2p/go-libp2p-testing v0.12.0
github.com/libp2p/go-libp2p-xor v0.1.0
Expand All @@ -34,11 +31,12 @@ require (
github.com/stretchr/testify v1.10.0
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1
go.opencensus.io v0.24.0
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel/trace v1.31.0
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/trace v1.34.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
gonum.org/v1/gonum v0.15.0
gonum.org/v1/gonum v0.15.1
google.golang.org/protobuf v1.36.3
)

require (
Expand All @@ -59,6 +57,7 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down Expand Up @@ -119,27 +118,27 @@ require (
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.48.2 // indirect
github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.23.0 // indirect
go.uber.org/mock v0.5.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.28.0 // indirect
google.golang.org/protobuf v1.36.0 // indirect
golang.org/x/tools v0.29.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
)
Loading
Loading