nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: libp2p/go-libp2p
Pull request #2613 (2023-10-20 04:45:29)

test/basichost: fix flaky test due to rcmgr


Patch:
diff --git a/p2p/net/swarm/swarm.go b/p2p/net/swarm/swarm.go
index 9ecb5dbf..a76edce6 100644
--- a/p2p/net/swarm/swarm.go
+++ b/p2p/net/swarm/swarm.go
@@ -137,8 +137,8 @@ func WithIPv6BlackHoleConfig(enabled bool, n, min int) Option {
 // communication. The Chan sends/receives Messages, which note the
 // destination or source Peer.
 type Swarm struct {
-	nextConnID   uint64 // guarded by atomic
-	nextStreamID uint64 // guarded by atomic
+	nextConnID   atomic.Uint64
+	nextStreamID atomic.Uint64
 
 	// Close refcount. This allows us to fully wait for the swarm to be torn
 	// down before continuing.
@@ -350,7 +350,7 @@ func (s *Swarm) addConn(tc transport.CapableConn, dir network.Direction) (*Conn,
 		conn:  tc,
 		swarm: s,
 		stat:  stat,
-		id:    atomic.AddUint64(&s.nextConnID, 1),
+		id:    s.nextConnID.Add(1),
 	}
 
 	// we ONLY check upgraded connections here so we can send them a Disconnect message.
diff --git a/p2p/net/swarm/swarm_conn.go b/p2p/net/swarm/swarm_conn.go
index fd159b85..8c3ce7c5 100644
--- a/p2p/net/swarm/swarm_conn.go
+++ b/p2p/net/swarm/swarm_conn.go
@@ -5,7 +5,6 @@ import (
 	"errors"
 	"fmt"
 	"sync"
-	"sync/atomic"
 	"time"
 
 	ic "github.com/libp2p/go-libp2p/core/crypto"
@@ -239,7 +238,7 @@ func (c *Conn) addStream(ts network.MuxedStream, dir network.Direction, scope ne
 			Direction: dir,
 			Opened:    time.Now(),
 		},
-		id:                             atomic.AddUint64(&c.swarm.nextStreamID, 1),
+		id:                             c.swarm.nextStreamID.Add(1),
 		acceptStreamGoroutineCompleted: dir != network.DirInbound,
 	}
 	c.stat.NumStreams++


Test patch:
diff --git a/p2p/test/basichost/basic_host_test.go b/p2p/test/basichost/basic_host_test.go
index 13800fef..d00dd9d5 100644
--- a/p2p/test/basichost/basic_host_test.go
+++ b/p2p/test/basichost/basic_host_test.go
@@ -21,12 +21,14 @@ func TestNoStreamOverTransientConnection(t *testing.T) {
 	h1, err := libp2p.New(
 		libp2p.NoListenAddrs,
 		libp2p.EnableRelay(),
+		libp2p.ResourceManager(&network.NullResourceManager{}),
 	)
 	require.NoError(t, err)
 
 	h2, err := libp2p.New(
 		libp2p.NoListenAddrs,
 		libp2p.EnableRelay(),
+		libp2p.ResourceManager(&network.NullResourceManager{}),
 	)
 	require.NoError(t, err)
 
@@ -80,12 +82,14 @@ func TestNewStreamTransientConnection(t *testing.T) {
 	h1, err := libp2p.New(
 		libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"),
 		libp2p.EnableRelay(),
+		libp2p.ResourceManager(&network.NullResourceManager{}),
 	)
 	require.NoError(t, err)
 
 	h2, err := libp2p.New(
 		libp2p.ListenAddrStrings("/ip4/127.0.0.1/udp/0/quic-v1"),
 		libp2p.EnableRelay(),
+		libp2p.ResourceManager(&network.NullResourceManager{}),
 	)
 	require.NoError(t, err)
Repository: libp2p/go-libp2p
Pull request #2683 (2024-01-13 01:11:39)

chore(p2p/host): typo fix
few typo fix, one is in a readme file, other is an error message displayed to the user, rest are comments.
Hope I could be of any help.



Patch:
diff --git a/p2p/host/resource-manager/README.md b/p2p/host/resource-manager/README.md
index 72eb192a..68ce0aa0 100644
--- a/p2p/host/resource-manager/README.md
+++ b/p2p/host/resource-manager/README.md
@@ -161,7 +161,7 @@ belong to some service in the system. Hence, this suggests that apart
 from global limits, we can constrain stream usage at finer
 granularity, at the protocol and service level.
 
-Once again, we disinguish between inbound and outbound streams.
+Once again, we distinguish between inbound and outbound streams.
 Inbound streams are initiated by remote peers and consume resources in
 response to network events; controlling inbound stream usage is again
 paramount for protecting the system from overload or attack.


Test patch:
diff --git a/p2p/host/resource-manager/scope_test.go b/p2p/host/resource-manager/scope_test.go
index abef4762..7bf7ff72 100644
--- a/p2p/host/resource-manager/scope_test.go
+++ b/p2p/host/resource-manager/scope_test.go
@@ -74,7 +74,7 @@ func TestCheckMemory(t *testing.T) {
 			limit = 1024
 		}
 		currentMem = (currentMem % limit) // We can't have reserved more than our limit
-		res = (res >> 14)                 // We won't resonably ever have a reservation > 2^50
+		res = (res >> 14)                 // We won't reasonably ever have a reservation > 2^50
 		rc := resources{limit: &BaseLimit{
 			Memory:          int64(limit),
 			StreamsInbound:  1,
@@ -88,7 +88,7 @@ func TestCheckMemory(t *testing.T) {
 		rc.memory = int64(currentMem)
 
 		priShift = (priShift % 9)
-		// Check different priorties at 2^0, 2^1,...2^8. This lets our math be correct in the check below (and avoid overflows).
+		// Check different priorities at 2^0, 2^1,...2^8. This lets our math be correct in the check below (and avoid overflows).
 		pri := uint8((1 << priShift) - 1)
 
 		err := rc.checkMemory(int64(res), pri)
Repository: libp2p/go-libp2p
Pull request #2747 (2024-03-21 16:45:40)

ci: uci/copy-templates
This PR was created automatically by the @web3-bot as a part of the [Unified CI](https://github.com/pl-strflt/uci) project.


Patch:
diff --git a/.github/workflows/go-check.yml b/.github/workflows/go-check.yml
index 09ee2fc9..a1cc205f 100644
--- a/.github/workflows/go-check.yml
+++ b/.github/workflows/go-check.yml
@@ -15,6 +15,6 @@ concurrency:
 
 jobs:
   go-check:
-    uses: pl-strflt/uci/.github/workflows/go-check.yml@v0.0
+    uses: ipdxco/unified-github-workflows/.github/workflows/go-check.yml@v1.0
     with:
       go-generate-ignore-protoc-version-comments: true
diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml
index bda61600..0b5ff607 100644
--- a/.github/workflows/release-check.yml
+++ b/.github/workflows/release-check.yml
@@ -16,4 +16,4 @@ concurrency:
 
 jobs:
   release-check:
-    uses: pl-strflt/uci/.github/workflows/release-check.yml@v0.0
+    uses: ipdxco/unified-github-workflows/.github/workflows/release-check.yml@v1.0
diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml
index dd8081b9..2ebdbed3 100644
--- a/.github/workflows/releaser.yml
+++ b/.github/workflows/releaser.yml
@@ -14,4 +14,4 @@ concurrency:
 
 jobs:
   releaser:
-    uses: pl-strflt/uci/.github/workflows/releaser.yml@v0.0
+    uses: ipdxco/unified-github-workflows/.github/workflows/releaser.yml@v1.0
diff --git a/.github/workflows/tagpush.yml b/.github/workflows/tagpush.yml
index 59de8cb9..5ef3fb9e 100644
--- a/.github/workflows/tagpush.yml
+++ b/.github/workflows/tagpush.yml
@@ -15,4 +15,4 @@ concurrency:
 
 jobs:
   releaser:
-    uses: pl-strflt/uci/.github/workflows/tagpush.yml@v0.0
+    uses: ipdxco/unified-github-workflows/.github/workflows/tagpush.yml@v1.0


Test patch:
diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml
index 452137ac..e33480c0 100644
--- a/.github/workflows/go-test.yml
+++ b/.github/workflows/go-test.yml
@@ -15,6 +15,8 @@ concurrency:
 
 jobs:
   go-test:
-    uses: libp2p/uci/.github/workflows/go-test.yml@v0.0
+    uses: libp2p/uci/.github/workflows/go-test.yml@v1.0
     with:
       go-versions: '["1.21.x", "1.22.x"]'
+    secrets:
+      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Repository: libp2p/go-libp2p
Pull request #2810 (2024-05-22 13:29:26)

config: fix "Insecure-security" constructor


Patch:
diff --git a/config/config.go b/config/config.go
index 8f1c2108..cc689baf 100644
--- a/config/config.go
+++ b/config/config.go
@@ -372,12 +372,11 @@ func (cfg *Config) NewNode() (host.Host, error) {
 			return sw
 		}),
 		fx.Provide(cfg.newBasicHost),
-		fx.Provide(func(h *bhost.BasicHost, lifecycle fx.Lifecycle) host.Host {
-			lifecycle.Append(fx.StartHook(h.Start))
-			return h
+		fx.Provide(func(bh *bhost.BasicHost) host.Host {
+			return bh
 		}),
-		fx.Provide(func(h host.Host) peer.ID { return h.ID() }),
-		fx.Provide(func(h host.Host) crypto.PrivKey { return h.Peerstore().PrivKey(h.ID()) }),
+		fx.Provide(func(h *swarm.Swarm) peer.ID { return h.LocalPeer() }),
+		fx.Provide(func(h *swarm.Swarm) crypto.PrivKey { return h.Peerstore().PrivKey(h.LocalPeer()) }),
 	}
 	transportOpts, err := cfg.addTransports()
 	if err != nil {
@@ -418,6 +417,9 @@ func (cfg *Config) NewNode() (host.Host, error) {
 
 	var bh *bhost.BasicHost
 	fxopts = append(fxopts, fx.Invoke(func(bho *bhost.BasicHost) { bh = bho }))
+	fxopts = append(fxopts, fx.Invoke(func(h *bhost.BasicHost, lifecycle fx.Lifecycle) {
+		lifecycle.Append(fx.StartHook(h.Start))
+	}))
 
 	var rh *routed.RoutedHost
 	if cfg.Routing != nil {
@@ -430,7 +432,12 @@ func (cfg *Config) NewNode() (host.Host, error) {
 	}
 
 	if err := cfg.addAutoNAT(bh); err != nil {
-		rh.Close()
+		app.Stop(context.Background())
+		if cfg.Routing != nil {
+			rh.Close()
+		} else {
+			bh.Close()
+		}
 		return nil, err
 	}
 
@@ -505,6 +512,7 @@ func (cfg *Config) addAutoNAT(h *bhost.BasicHost) error {
 				return dialer, err
 
 			}),
+			fx.Provide(func(s *swarm.Swarm) peer.ID { return s.LocalPeer() }),
 			fx.Provide(func() crypto.PrivKey { return autonatPrivKey }),
 		)
 		app := fx.New(fxopts...)


Test patch:
diff --git a/libp2p_test.go b/libp2p_test.go
index 343681be..1c21146b 100644
--- a/libp2p_test.go
+++ b/libp2p_test.go
@@ -376,6 +376,21 @@ func TestAutoNATService(t *testing.T) {
 	h.Close()
 }
 
+func TestInsecureConstructor(t *testing.T) {
+	h, err := New(
+		EnableNATService(),
+		NoSecurity,
+	)
+	require.NoError(t, err)
+	h.Close()
+
+	h, err = New(
+		NoSecurity,
+	)
+	require.NoError(t, err)
+	h.Close()
+}
+
 func TestDisableIdentifyAddressDiscovery(t *testing.T) {
 	h, err := New(DisableIdentifyAddressDiscovery())
 	require.NoError(t, err)
Repository: libp2p/go-libp2p
Pull request #2832 (2024-06-11 11:53:15)

webrtc: fix ufrag prefix for dialing
Closes: #2827 

Should we reject connections attempts with ufrag that don't have this prefix? 

I think it is fine to accept all attempts. The purpose of this prefix is to allow us to extend this in the future. So when we do v2 we can make that check aggressive and consider all ufrags without any prefix to be v1. 


Patch:
diff --git a/p2p/transport/webrtc/transport.go b/p2p/transport/webrtc/transport.go
index b04753ec..68a2988c 100644
--- a/p2p/transport/webrtc/transport.go
+++ b/p2p/transport/webrtc/transport.go
@@ -415,15 +415,17 @@ func genUfrag() string {
 		uFragAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
 		uFragPrefix   = "libp2p+webrtc+v1/"
 		uFragIdLength = 32
-		uFragIdOffset = len(uFragPrefix)
-		uFragLength   = uFragIdOffset + uFragIdLength
+		uFragLength   = len(uFragPrefix) + uFragIdLength
 	)
 
 	seed := [8]byte{}
 	rand.Read(seed[:])
 	r := mrand.New(mrand.NewSource(binary.BigEndian.Uint64(seed[:])))
 	b := make([]byte, uFragLength)
-	for i := uFragIdOffset; i < uFragLength; i++ {
+	for i := 0; i < len(uFragPrefix); i++ {
+		b[i] = uFragPrefix[i]
+	}
+	for i := len(uFragPrefix); i < uFragLength; i++ {
 		b[i] = uFragAlphabet[r.Intn(len(uFragAlphabet))]
 	}
 	return string(b)


Test patch:
diff --git a/p2p/transport/webrtc/transport_test.go b/p2p/transport/webrtc/transport_test.go
index a3054a82..5831a257 100644
--- a/p2p/transport/webrtc/transport_test.go
+++ b/p2p/transport/webrtc/transport_test.go
@@ -860,3 +860,10 @@ func TestMaxInFlightRequests(t *testing.T) {
 	require.Equal(t, count, int(success.Load()), "expected exactly 3 dial successes")
 	require.Equal(t, 1, int(fails.Load()), "expected exactly 1 dial failure")
 }
+
+func TestGenUfrag(t *testing.T) {
+	for i := 0; i < 10; i++ {
+		s := genUfrag()
+		require.True(t, strings.HasPrefix(s, "libp2p+webrtc+v1/"))
+	}
+}