Skip to content

Commit 30af194

Browse files
sukunrtMarcoPolo
authored andcommitted
gossipsub-interop: update go-libp2p to the latest version
1 parent 131b03f commit 30af194

4 files changed

Lines changed: 27 additions & 18 deletions

File tree

gossipsub-interop/go-libp2p/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,5 @@ require (
110110
google.golang.org/protobuf v1.36.5 // indirect
111111
lukechampine.com/blake3 v1.4.1 // indirect
112112
)
113+
114+
replace github.com/libp2p/go-libp2p-pubsub => /home/sukun/dev/go-libp2p-pubsub

gossipsub-interop/go-libp2p/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
pubsub "github.com/libp2p/go-libp2p-pubsub"
1919
"github.com/libp2p/go-libp2p-pubsub/partialmessages"
2020
pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb"
21+
"github.com/libp2p/go-libp2p/core/connmgr"
2122
"github.com/libp2p/go-libp2p/core/crypto"
2223
"github.com/libp2p/go-libp2p/core/host"
2324
"github.com/libp2p/go-libp2p/core/peer"
@@ -120,6 +121,7 @@ func main() {
120121
libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/9000"),
121122
// libp2p.ListenAddrStrings("/ip4/0.0.0.0/udp/9000/quic-v1"),
122123
libp2p.Identity(nodePrivKey(nodeId)),
124+
libp2p.ConnectionManager(connmgr.NullConnMgr{}),
123125
)
124126
if err != nil {
125127
panic(err)

gossipsub-interop/go-libp2p/partial.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"errors"
77
"math/bits"
88

9-
partialmessages "github.com/libp2p/go-libp2p-pubsub/partialmessages"
9+
"github.com/libp2p/go-libp2p-pubsub/partialmessages"
1010
)
1111

1212
const partLen = 1024
@@ -17,8 +17,8 @@ type PartialMessage struct {
1717
}
1818

1919
// PartsMetadata implements partialmessages.PartialMessage.
20-
func (p *PartialMessage) PartsMetadata() []byte {
21-
out := []byte{0}
20+
func (p *PartialMessage) PartsMetadata() partialmessages.PartsMetadata {
21+
out := partialmessages.PartsMetadata{0}
2222
for i := range p.parts {
2323
if len(p.parts[i]) > 0 {
2424
out[0] |= 1 << i
@@ -88,35 +88,29 @@ func (p *PartialMessage) Extend(data []byte) error {
8888
}
8989

9090
// PartialMessageBytes implements partialmessages.PartialMessage.
91-
func (p *PartialMessage) PartialMessageBytes(metadata []byte) ([]byte, []byte, error) {
91+
func (p *PartialMessage) PartialMessageBytes(metadata partialmessages.PartsMetadata) ([]byte, error) {
9292
if len(metadata) != 1 {
93-
return nil, nil, errors.New("invalid metadata length")
93+
return nil, errors.New("invalid metadata length")
9494
}
9595

9696
out := make([]byte, 0, 1+1024*(bits.OnesCount8(metadata[0]))+len(p.groupID))
9797
out = append(out, 0) // This byte will contain the parts we are including in the message
98-
remaining := []byte{metadata[0]}
99-
for i := range p.parts {
98+
for i, a := range p.parts {
10099
if metadata[0]&(1<<i) != 0 {
101100
// They already have this part
102101
continue
103102
}
104-
if len(p.parts[i]) == 0 {
103+
if len(a) == 0 {
105104
continue
106105
}
107-
remaining[0] ^= (1 << i)
108106
out[0] |= 1 << i
109-
out = append(out, p.parts[i]...)
107+
out = append(out, a...)
110108
}
111109
if out[0] == 0 {
112-
return nil, metadata, nil
110+
return nil, nil
113111
}
114112
out = append(out, p.groupID[:]...)
115-
if remaining[0] == 0 {
116-
remaining = nil
117-
}
118-
119-
return out, remaining, nil
113+
return out, nil
120114
}
121115

122-
var _ partialmessages.PartialMessage = (*PartialMessage)(nil)
116+
var _ partialmessages.Message = (*PartialMessage)(nil)

gossipsub-interop/go-libp2p/partial_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,22 @@ func (p *partialInvariantChecker) SplitIntoParts(in *PartialMessage) ([]*Partial
9494
}
9595

9696
// ShouldRequest implements partialmessages.InvariantChecker.
97-
func (p *partialInvariantChecker) ShouldRequest(a *PartialMessage, from peer.ID, partsMetadata []byte) bool {
97+
func (*partialInvariantChecker) ShouldRequest(a *PartialMessage, _ peer.ID, partsMetadata []byte) bool {
9898
aHas := a.PartsMetadata()[0]
9999
return len(partsMetadata) == 1 && aHas != partsMetadata[0]
100100
}
101101

102+
func (*partialInvariantChecker) MergePartsMetadata(left, right partialmessages.PartsMetadata) partialmessages.PartsMetadata {
103+
res := slices.Clone(left)
104+
if len(res) == 0 {
105+
return slices.Clone(right)
106+
}
107+
if len(right) > 0 {
108+
res[0] |= right[0]
109+
}
110+
return res
111+
}
112+
102113
var _ partialmessages.InvariantChecker[*PartialMessage] = (*partialInvariantChecker)(nil)
103114

104115
func TestPartialMessageInvariants(t *testing.T) {

0 commit comments

Comments
 (0)