Skip to content

Commit

Permalink
Update libp2p and libp2p-pubsub (#192)
Browse files Browse the repository at this point in the history
* Update libp2p and libp2p-pubsub
* Do not limit connections per IP for tests
  • Loading branch information
gammazero authored May 21, 2024
1 parent 3bf944f commit e0a7fab
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 52 deletions.
8 changes: 8 additions & 0 deletions dagsync/ipnisync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func NewSync(lsys ipld.LinkSystem, blockHook func(peer.ID, cid.Cid), options ...
},
clientHost: &libp2phttp.Host{
StreamHost: opts.streamHost,
// Allow compatibility with older version of libp2phttp.
//
// This should be deprecated once all storage providers have
// upgraded to a version of ipni that uses go-libp2p v0.34.0.
EnableCompatibilityWithLegacyWellKnownEndpoint: true,
},
lsys: lsys,
authPeerID: opts.authPeerID,
Expand Down Expand Up @@ -124,6 +129,9 @@ func (s *Sync) NewSyncer(peerInfo peer.AddrInfo) (*Syncer, error) {
s.clientHostMutex.Unlock()
var plainHTTP bool
if err != nil {
if strings.Contains(err.Error(), "limit exceeded") {
return nil, err
}
httpAddrs := mautil.FindHTTPAddrs(peerInfo.Addrs)
if len(httpAddrs) == 0 {
return nil, ErrNoHTTPServer
Expand Down
5 changes: 2 additions & 3 deletions dagsync/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ func TestConcurrentSync(t *testing.T) {
require.NoError(t, err)

wg := sync.WaitGroup{}
// Now sync again. We shouldn't call the hook because we persisted our latestSync
for _, pub := range publishers {
wg.Add(1)

Expand All @@ -211,12 +210,12 @@ func TestConcurrentSync(t *testing.T) {
ID: pub.h.ID(),
Addrs: pub.h.Addrs(),
}
t.Log("Connecting to:", peerInfo)
_, err := sub.SyncAdChain(context.Background(), peerInfo)
if err != nil {
panic("sync failed")
panic("sync failed: " + err.Error())
}
}(pub)

}

doneChan := make(chan struct{})
Expand Down
12 changes: 11 additions & 1 deletion dagsync/test/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -229,7 +230,16 @@ func Store(srcStore datastore.Batching, n ipld.Node) (ipld.Link, error) {
}

func MkTestHost(t *testing.T, options ...libp2p.Option) host.Host {
options = append(options, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"))
// Do not limit connections per IP as all test connections go to localhost.
mgr, err := rcmgr.NewResourceManager(
rcmgr.NewFixedLimiter(rcmgr.DefaultLimits.AutoScale()),
rcmgr.WithLimitPeersPerCIDR([]rcmgr.ConnLimitPerCIDR{}, []rcmgr.ConnLimitPerCIDR{}),
)
if err != nil {
panic(err)
}

options = append(options, libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"), libp2p.ResourceManager(mgr))
h, err := libp2p.New(options...)
require.NoError(t, err)
if err != nil {
Expand Down
48 changes: 32 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
github.com/ipfs/go-ipld-format v0.6.0
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipld/go-ipld-prime v0.21.0
github.com/libp2p/go-libp2p v0.33.2
github.com/libp2p/go-libp2p-pubsub v0.10.1
github.com/libp2p/go-libp2p v0.34.0
github.com/libp2p/go-libp2p-pubsub v0.11.0
github.com/libp2p/go-msgio v0.3.0
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.12.4
Expand All @@ -26,7 +26,7 @@ require (
github.com/whyrusleeping/cbor-gen v0.1.1
golang.org/x/crypto v0.23.0
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.1
)

require (
Expand All @@ -39,7 +39,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2 // indirect
Expand All @@ -62,7 +62,7 @@ require (
github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/ipfs/go-block-format v0.1.2 // indirect
github.com/ipfs/go-ipfs-pq v0.0.3 // indirect
Expand All @@ -75,7 +75,7 @@ require (
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
Expand All @@ -100,16 +100,32 @@ require (
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pion/datachannel v1.5.6 // indirect
github.com/pion/dtls/v2 v2.2.11 // indirect
github.com/pion/ice/v2 v2.3.24 // indirect
github.com/pion/interceptor v0.1.29 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.12 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.14 // indirect
github.com/pion/rtp v1.8.6 // indirect
github.com/pion/sctp v1.8.16 // indirect
github.com/pion/sdp/v3 v3.0.9 // indirect
github.com/pion/srtp/v2 v2.0.18 // indirect
github.com/pion/stun v0.6.1 // indirect
github.com/pion/transport/v2 v2.2.5 // indirect
github.com/pion/turn/v2 v2.1.6 // indirect
github.com/pion/webrtc/v3 v3.2.40 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.42.0 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/quic-go/quic-go v0.44.0 // indirect
github.com/quic-go/webtransport-go v0.8.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
Expand All @@ -120,17 +136,17 @@ require (
go.opentelemetry.io/otel/trace v1.13.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/dig v1.17.1 // indirect
go.uber.org/fx v1.20.1 // indirect
go.uber.org/fx v1.21.1 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/tools v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)
Loading

0 comments on commit e0a7fab

Please sign in to comment.