update simnet dependency

This commit is contained in:
Marco Munizaga
2026-01-07 11:17:42 -08:00
parent 61bc00c35d
commit 6c4273f47e
5 changed files with 24 additions and 22 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+2 -1
View File
@@ -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
}))
}
+11 -7
View File
@@ -207,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),
}
@@ -261,12 +265,12 @@ func SimpleLibp2pNetwork(linkSettings []NodeLinkSettingsAndCount, networkSetting
// 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, Latency: 100 * time.Millisecond / 2}, // Divide by two since this is latency for each direction
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps, Latency: 100 * time.Millisecond / 2},
network, meta, err := SimpleLibp2pNetwork([]NodeLinkSettingsAndCount{{
LinkSettings: simnet.NodeBiDiLinkSettings{
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps},
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps},
}, Count: 2},
}, NetworkSettings{})
}, simnet.StaticLatency(100/2*time.Millisecond), NetworkSettings{})
require.NoError(t, err)
network.Start()
t.Cleanup(func() {
+8 -11
View File
@@ -23,10 +23,10 @@ func TestSimpleLibp2pNetwork_synctest(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()
@@ -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,
},
}
@@ -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(),
})