Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Upgrade libp2p and fix dropped message issue in gossip (#312)
Browse files Browse the repository at this point in the history
* Add buffer size of pubsub queue

* Fix build error

* Add comment about the reason of bufferSize
  • Loading branch information
Kourin1996 authored Dec 27, 2021
1 parent 4765373 commit 9a6905a
Show file tree
Hide file tree
Showing 300 changed files with 28,980 additions and 3,748 deletions.
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/btcsuite/btcd v0.21.0-beta
github.com/go-kit/kit v0.9.0
github.com/golang/protobuf v1.5.2
github.com/google/gopacket v1.1.18 // indirect
github.com/google/uuid v1.1.4
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/go-hclog v0.16.2
Expand All @@ -17,11 +16,11 @@ require (
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/vault/api v1.3.0
github.com/imdario/mergo v0.3.7
github.com/libp2p/go-libp2p v0.12.0
github.com/libp2p/go-libp2p-core v0.7.0
github.com/libp2p/go-libp2p v0.14.0
github.com/libp2p/go-libp2p-core v0.8.5
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/libp2p/go-libp2p-noise v0.1.1
github.com/libp2p/go-libp2p-pubsub v0.4.1
github.com/libp2p/go-libp2p-noise v0.2.0
github.com/libp2p/go-libp2p-pubsub v0.5.0
github.com/mitchellh/cli v1.0.0
github.com/multiformats/go-multiaddr v0.3.1
github.com/prometheus/client_golang v1.4.0
Expand Down
231 changes: 231 additions & 0 deletions go.sum

Large diffs are not rendered by default.

24 changes: 16 additions & 8 deletions network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import (
"google.golang.org/protobuf/proto"
)

const (
// bufferSize is the size of the queue in go-libp2p-pubsub
// we should have enough capacity of the queue
// because there is possibility of that node lose gossip messages when the queue is full
bufferSize = 512
)

type Topic struct {
logger hclog.Logger

Expand All @@ -31,7 +38,7 @@ func (t *Topic) Publish(obj proto.Message) error {
}

func (t *Topic) Subscribe(handler func(obj interface{})) error {
sub, err := t.topic.Subscribe()
sub, err := t.topic.Subscribe(pubsub.WithBufferSize(bufferSize))
if err != nil {
return err
}
Expand All @@ -54,13 +61,14 @@ func (t *Topic) readLoop(sub *pubsub.Subscription, handler func(obj interface{})
t.logger.Error("failed to get topic", "err", err)
continue
}

obj := t.createObj()
if err := proto.Unmarshal(msg.Data, obj); err != nil {
t.logger.Error("failed to unmarshal topic", "err", err)
continue
}
handler(obj)
go func() {
obj := t.createObj()
if err := proto.Unmarshal(msg.Data, obj); err != nil {
t.logger.Error("failed to unmarshal topic", "err", err)
return
}
handler(obj)
}()
}
}

Expand Down
10 changes: 0 additions & 10 deletions vendor/github.com/flynn/noise/.travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions vendor/github.com/flynn/noise/README.md

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

21 changes: 10 additions & 11 deletions vendor/github.com/flynn/noise/cipher_suite.go

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

8 changes: 8 additions & 0 deletions vendor/github.com/flynn/noise/go.mod

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

15 changes: 15 additions & 0 deletions vendor/github.com/flynn/noise/go.sum

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

2 changes: 1 addition & 1 deletion vendor/github.com/flynn/noise/patterns.go

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

Loading

0 comments on commit 9a6905a

Please sign in to comment.