]> Sergey Matveev's repositories - btrtrc.git/blobdiff - ut-holepunching_test.go
Tweak logging
[btrtrc.git] / ut-holepunching_test.go
index 5df98bfbb11b6e1fe74215ef44f98e60ee17966d..ba3d6ad8c21b37bf66529a02f866912d8ede2af6 100644 (file)
@@ -18,6 +18,7 @@ import (
        qt "github.com/frankban/quicktest"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/require"
+       "golang.org/x/time/rate"
 
        "github.com/anacrolix/torrent/internal/testutil"
 )
@@ -36,9 +37,13 @@ func TestHolepunchConnect(t *testing.T) {
        cfg.DisablePEX = true
        cfg.Debug = true
        cfg.AcceptPeerConnections = false
-       // Listening, even without accepting, still means the leecher-leecher completes the dial to the seeder, and so it
-       // won't attempt to holepunch.
+       // Listening, even without accepting, still means the leecher-leecher completes the dial to the
+       // seeder, and so it won't attempt to holepunch.
        cfg.DisableTCP = true
+       // Ensure that responding to holepunch connects don't wait around for the dial limit. We also
+       // have to allow the initial connection to the leecher though, so it can rendezvous for us.
+       cfg.DialRateLimiter = rate.NewLimiter(0, 1)
+       cfg.Logger = cfg.Logger.WithContextText("seeder")
        seeder, err := NewClient(cfg)
        require.NoError(t, err)
        defer seeder.Close()
@@ -52,10 +57,11 @@ func TestHolepunchConnect(t *testing.T) {
        cfg.Seed = true
        cfg.DataDir = t.TempDir()
        cfg.AlwaysWantConns = true
+       cfg.Logger = cfg.Logger.WithContextText("leecher")
        // This way the leecher leecher will still try to use this peer as a relay, but won't be told
        // about the seeder via PEX.
        //cfg.DisablePEX = true
-       //cfg.Debug = true
+       cfg.Debug = true
        leecher, err := NewClient(cfg)
        require.NoError(t, err)
        defer leecher.Close()
@@ -67,6 +73,7 @@ func TestHolepunchConnect(t *testing.T) {
        cfg.MaxAllocPeerRequestDataPerConn = 4
        cfg.Debug = true
        cfg.NominalDialTimeout = time.Second
+       cfg.Logger = cfg.Logger.WithContextText("leecher-leecher")
        //cfg.DisableUTP = true
        leecherLeecher, _ := NewClient(cfg)
        require.NoError(t, err)