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

Chore/remove gogo #15

Merged
merged 8 commits into from
Aug 5, 2024
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
9 changes: 4 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
golang:
- 1.19.x
- 1.21.x
steps:
- uses: actions/checkout@v3
- name: Set up Go
Expand All @@ -24,16 +24,15 @@ jobs:
- name: golangci-lint
uses: golangci/[email protected]
with:
go-version: ${{ matrix.golang }}
version: v1.50.1
version: v1.59.1
args: --timeout=10m

go-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
golang: ['1.19', '1.20']
os: ['ubuntu-latest', 'macos-latest']
golang: ["1.21", "1.22"]
os: ["ubuntu-latest", "macos-latest"]
env:
OS: ${{ matrix.os }}
GOLANG: ${{ matrix.golang }}
Expand Down
5 changes: 5 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/go
out: ./pb
opt: module=github.com/berty/go-libp2p-rendezvous/pb
34 changes: 15 additions & 19 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import (
"math/rand"
"time"

ggio "github.com/gogo/protobuf/io"
"github.com/libp2p/go-libp2p/core/host"
inet "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"

pb "github.com/berty/go-libp2p-rendezvous/pb"
protoio "github.com/berty/go-libp2p-rendezvous/protoio"
)

var (
DiscoverAsyncInterval = 2 * time.Minute
)
var DiscoverAsyncInterval = 2 * time.Minute

type RendezvousPoint interface {
Register(ctx context.Context, ns string, ttl int) (time.Duration, error)
Expand Down Expand Up @@ -76,8 +74,8 @@ func (rp *rendezvousPoint) Register(ctx context.Context, ns string, ttl int) (ti
}
defer s.Reset()

r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
w := ggio.NewDelimitedWriter(s)
r := protoio.NewDelimitedReader(s, inet.MessageSizeMax)
w := protoio.NewDelimitedWriter(s)

addrs := rp.addrFactory(rp.host.Addrs())
if len(addrs) == 0 {
Expand All @@ -92,8 +90,7 @@ func (rp *rendezvousPoint) Register(ctx context.Context, ns string, ttl int) (ti
}

var res pb.Message
err = r.ReadMsg(&res)
if err != nil {
if err := r.ReadMsg(&res); err != nil {
return 0, err
}

Expand Down Expand Up @@ -163,7 +160,7 @@ func (rp *rendezvousPoint) Unregister(ctx context.Context, ns string) error {
}
defer s.Close()

w := ggio.NewDelimitedWriter(s)
w := protoio.NewDelimitedWriter(s)
req := newUnregisterMessage(ns, rp.host.ID())
return w.WriteMsg(req)
}
Expand All @@ -179,13 +176,12 @@ func (rp *rendezvousPoint) Discover(ctx context.Context, ns string, limit int, c
}
defer s.Reset()

r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
w := ggio.NewDelimitedWriter(s)

r := protoio.NewDelimitedReader(s, inet.MessageSizeMax)
w := protoio.NewDelimitedWriter(s)
return discoverQuery(ns, limit, cookie, r, w)
}

func discoverQuery(ns string, limit int, cookie []byte, r ggio.Reader, w ggio.Writer) ([]Registration, []byte, error) {
func discoverQuery(ns string, limit int, cookie []byte, r protoio.Reader, w protoio.Writer) ([]Registration, []byte, error) {
req := newDiscoverMessage(ns, limit, cookie)
err := w.WriteMsg(req)
if err != nil {
Expand All @@ -199,7 +195,7 @@ func discoverQuery(ns string, limit int, cookie []byte, r ggio.Reader, w ggio.Wr
}

if res.GetType() != pb.Message_DISCOVER_RESPONSE {
return nil, nil, fmt.Errorf("Unexpected response: %s", res.GetType().String())
return nil, nil, fmt.Errorf("unexpected response: %s", res.GetType().String())
}

status := res.GetDiscoverResponse().GetStatus()
Expand Down Expand Up @@ -236,8 +232,8 @@ func discoverAsync(ctx context.Context, ns string, s inet.Stream, ch chan Regist
defer s.Reset()
defer close(ch)

r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
w := ggio.NewDelimitedWriter(s)
r := protoio.NewDelimitedReader(s, inet.MessageSizeMax)
w := protoio.NewDelimitedWriter(s)

const batch = 200

Expand Down Expand Up @@ -343,8 +339,8 @@ func (rp *rendezvousPoint) DiscoverSubscribe(ctx context.Context, ns string, ser
}
defer s.Close()

r := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
w := ggio.NewDelimitedWriter(s)
r := protoio.NewDelimitedReader(s, inet.MessageSizeMax)
w := protoio.NewDelimitedWriter(s)

subType, subDetails, err := discoverSubscribeQuery(ns, serviceTypes, r, w)
if err != nil {
Expand Down Expand Up @@ -386,7 +382,7 @@ func (rp *rendezvousPoint) DiscoverSubscribe(ctx context.Context, ns string, ser
return ch, nil
}

func discoverSubscribeQuery(ns string, serviceTypes []string, r ggio.Reader, w ggio.Writer) (subType string, subDetails string, err error) {
func discoverSubscribeQuery(ns string, serviceTypes []string, r protoio.Reader, w protoio.Writer) (subType string, subDetails string, err error) {
req := &pb.Message{
Type: pb.Message_DISCOVER_SUBSCRIBE,
DiscoverSubscribe: newDiscoverSubscribeMessage(ns, serviceTypes),
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"
"time"

mocknet "github.com/berty/go-libp2p-mock"
"github.com/libp2p/go-libp2p/core/peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"

"github.com/berty/go-libp2p-rendezvous/test_utils"
"github.com/libp2p/go-libp2p/core/host"
Expand Down
4 changes: 2 additions & 2 deletions db/sqlcipher/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestOpenCloseFSDB(t *testing.T) {
nonce1 := db.nonce

// let the flush goroutine run its cleanup act
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)

err = db.Close()
if err != nil {
Expand All @@ -108,7 +108,7 @@ func TestOpenCloseFSDB(t *testing.T) {
nonce2 := db.nonce

// let the flush goroutine run its cleanup act
time.Sleep(1 * time.Second)
time.Sleep(2 * time.Second)

err = db.Close()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"testing"
"time"

mocknet "github.com/berty/go-libp2p-mock"
"github.com/libp2p/go-libp2p/core/discovery"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
)

func getRendezvousDiscovery(hosts []host.Host) []discovery.Discovery {
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ go 1.22
toolchain go1.22.5

require (
github.com/berty/go-libp2p-mock v1.0.2-0.20240719150538-d7088679a8a7
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.4.0
github.com/ipfs/go-log/v2 v2.5.1
github.com/libp2p/go-libp2p v0.34.1
github.com/mattn/go-sqlite3 v1.14.16
github.com/multiformats/go-multiaddr v0.12.4
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
github.com/stretchr/testify v1.9.0
google.golang.org/protobuf v1.34.1
)

require (
Expand Down Expand Up @@ -91,7 +89,6 @@ require (
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)
24 changes: 4 additions & 20 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pb/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
name: buf.build/berty/go-libp2p-rendezvous
breaking:
use:
- FILE
lint:
use:
- DEFAULT
Loading
Loading