Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/actions/go-test-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ runs:
shell: bash
# This matches only tests with "NoCover" in their test name to avoid running all tests again.
run: go test -tags nocover -run NoCover -v ./...
- name: Run synctests tests. These are tests that require go 1.24 and the experimental testing/synctest package
- name: Run synctests tests. These are tests that require go 1.25 and the experimental testing/synctest package
shell: bash
if: ${{ contains(matrix.go, '1.24') }}
run: go test -tags goexperiment.synctest -run "_synctest$" -v ./...
if: ${{ contains(matrix.go, '1.25') }}
run: go test -run "_synctest$" -v ./...
- name: Install testing tools
shell: bash
run: cd scripts/test_analysis && go install ./cmd/gotest2sql
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/libp2p/go-reuseport v0.4.0
github.com/libp2p/go-yamux/v5 v5.0.1
github.com/libp2p/zeroconf/v2 v2.2.0
github.com/marcopolo/simnet v0.0.1
github.com/marcopolo/simnet v0.0.4
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b
github.com/mr-tron/base58 v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ github.com/libp2p/go-yamux/v5 v5.0.1 h1:f0WoX/bEF2E8SbE4c/k1Mo+/9z0O4oC/hWEA+nfY
github.com/libp2p/go-yamux/v5 v5.0.1/go.mod h1:en+3cdX51U0ZslwRdRLrvQsdayFt3TSUKvBGErzpWbU=
github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q=
github.com/libp2p/zeroconf/v2 v2.2.0/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs=
github.com/marcopolo/simnet v0.0.1 h1:rSMslhPz6q9IvJeFWDoMGxMIrlsbXau3NkuIXHGJxfg=
github.com/marcopolo/simnet v0.0.1/go.mod h1:WDaQkgLAjqDUEBAOXz22+1j6wXKfGlC5sD5XWt3ddOs=
github.com/marcopolo/simnet v0.0.4 h1:50Kx4hS9kFGSRIbrt9xUS3NJX33EyPqHVmpXvaKLqrY=
github.com/marcopolo/simnet v0.0.4/go.mod h1:tfQF1u2DmaB6WHODMtQaLtClEf3a296CKQLq5gAsIS0=
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk=
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU=
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
Expand Down
3 changes: 2 additions & 1 deletion p2p/protocol/holepunch/holepunch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ func quicSimnet(isPubliclyReachably bool, router *simnet.SimpleFirewallRouter) l
if isPubliclyReachably {
router.SetAddrPubliclyReachable(address)
}
c := simnet.NewSimConn(address, router)
c := simnet.NewSimConn(address)
router.AddNode(address, c)
return c, nil
}))
}
Expand Down
36 changes: 33 additions & 3 deletions x/simlibp2p/libp2p.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simconnlibp2p
package simlibp2p

import (
"context"
"crypto/rand"
"fmt"
"net"
Expand Down Expand Up @@ -206,8 +207,12 @@ type NetworkSettings struct {
BlankHostOptsForHostIdx func(idx int) BlankHostOpts
}

func SimpleLibp2pNetwork(linkSettings []NodeLinkSettingsAndCount, networkSettings NetworkSettings) (*simnet.Simnet, *SimpleLibp2pNetworkMeta, error) {
nw := &simnet.Simnet{}
type LatencyFunc func(*simnet.Packet) time.Duration

func SimpleLibp2pNetwork(linkSettings []NodeLinkSettingsAndCount, latencyFunc LatencyFunc, networkSettings NetworkSettings) (*simnet.Simnet, *SimpleLibp2pNetworkMeta, error) {
nw := &simnet.Simnet{
LatencyFunc: latencyFunc,
}
meta := &SimpleLibp2pNetworkMeta{
AddrToNode: make(map[string]HostAndIdx),
}
Expand Down Expand Up @@ -256,3 +261,28 @@ func SimpleLibp2pNetwork(linkSettings []NodeLinkSettingsAndCount, networkSetting

return nw, meta, nil
}

// GetBasicHostPair gets a new pair of hosts.
// The first host initiates the connection to the second host.
func GetBasicHostPair(t *testing.T) (host.Host, host.Host) {
network, meta, err := SimpleLibp2pNetwork([]NodeLinkSettingsAndCount{{
LinkSettings: simnet.NodeBiDiLinkSettings{
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps},
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps},
}, Count: 2},
}, simnet.StaticLatency(100/2*time.Millisecond), NetworkSettings{})
require.NoError(t, err)
network.Start()
t.Cleanup(func() {
network.Close()
})

h1 := meta.Nodes[0]
h2 := meta.Nodes[1]

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
h2pi := h2.Peerstore().PeerInfo(h2.ID())
require.NoError(t, h1.Connect(ctx, h2pi))
return h1, h2
}
27 changes: 12 additions & 15 deletions x/simlibp2p/synctest_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build goexperiment.synctest
//go:build go1.25

package simconnlibp2p_test
package simlibp2p_test

import (
"context"
Expand All @@ -13,20 +13,20 @@ import (
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
simlibp2p "github.com/libp2p/go-libp2p/x/simlibp2p"
"github.com/libp2p/go-libp2p/x/simlibp2p"
"github.com/marcopolo/simnet"
"github.com/stretchr/testify/require"
)

func TestSimpleLibp2pNetwork_synctest(t *testing.T) {
synctest.Run(func() {
synctest.Test(t, func(t *testing.T) {
latency := 10 * time.Millisecond
network, meta, err := simlibp2p.SimpleLibp2pNetwork([]simlibp2p.NodeLinkSettingsAndCount{
{LinkSettings: simnet.NodeBiDiLinkSettings{
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps, Latency: latency / 2}, // Divide by two since this is latency for each direction
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps, Latency: latency / 2},
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps}, // Divide by two since this is latency for each direction
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps},
}, Count: 100},
}, simlibp2p.NetworkSettings{})
}, simnet.StaticLatency(latency/2), simlibp2p.NetworkSettings{})
require.NoError(t, err)
network.Start()
defer network.Close()
Expand Down Expand Up @@ -74,19 +74,17 @@ func TestSimpleLibp2pNetwork_synctest(t *testing.T) {
}

func TestSimpleSimNetPing_synctest(t *testing.T) {
synctest.Run(func() {
router := &simnet.Simnet{}
synctest.Test(t, func(t *testing.T) {
const latency = 10 * time.Millisecond
router := &simnet.Simnet{LatencyFunc: simnet.StaticLatency(latency / 2)}

const bandwidth = 10 * simlibp2p.OneMbps
const latency = 10 * time.Millisecond
linkSettings := simnet.NodeBiDiLinkSettings{
Downlink: simnet.LinkSettings{
BitsPerSecond: bandwidth,
Latency: latency / 2,
},
Uplink: simnet.LinkSettings{
BitsPerSecond: bandwidth,
Latency: latency / 2,
},
}

Expand All @@ -101,14 +99,13 @@ func TestSimpleSimNetPing_synctest(t *testing.T) {
simlibp2p.QUICSimnet(router, linkSettings),
)

err := router.Start()
require.NoError(t, err)
router.Start()
defer router.Close()

defer hostA.Close()
defer hostB.Close()

err = hostA.Connect(context.Background(), peer.AddrInfo{
err := hostA.Connect(context.Background(), peer.AddrInfo{
ID: hostB.ID(),
Addrs: hostB.Addrs(),
})
Expand Down
Loading