Skip to content

Commit 6c4273f

Browse files
committed
update simnet dependency
1 parent 61bc00c commit 6c4273f

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/libp2p/go-reuseport v0.4.0
3030
github.com/libp2p/go-yamux/v5 v5.0.1
3131
github.com/libp2p/zeroconf/v2 v2.2.0
32-
github.com/marcopolo/simnet v0.0.1
32+
github.com/marcopolo/simnet v0.0.4
3333
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd
3434
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b
3535
github.com/mr-tron/base58 v1.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ github.com/libp2p/go-yamux/v5 v5.0.1 h1:f0WoX/bEF2E8SbE4c/k1Mo+/9z0O4oC/hWEA+nfY
6666
github.com/libp2p/go-yamux/v5 v5.0.1/go.mod h1:en+3cdX51U0ZslwRdRLrvQsdayFt3TSUKvBGErzpWbU=
6767
github.com/libp2p/zeroconf/v2 v2.2.0 h1:Cup06Jv6u81HLhIj1KasuNM/RHHrJ8T7wOTS4+Tv53Q=
6868
github.com/libp2p/zeroconf/v2 v2.2.0/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs=
69-
github.com/marcopolo/simnet v0.0.1 h1:rSMslhPz6q9IvJeFWDoMGxMIrlsbXau3NkuIXHGJxfg=
70-
github.com/marcopolo/simnet v0.0.1/go.mod h1:WDaQkgLAjqDUEBAOXz22+1j6wXKfGlC5sD5XWt3ddOs=
69+
github.com/marcopolo/simnet v0.0.4 h1:50Kx4hS9kFGSRIbrt9xUS3NJX33EyPqHVmpXvaKLqrY=
70+
github.com/marcopolo/simnet v0.0.4/go.mod h1:tfQF1u2DmaB6WHODMtQaLtClEf3a296CKQLq5gAsIS0=
7171
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd h1:br0buuQ854V8u83wA0rVZ8ttrq5CpaPZdvrK0LP2lOk=
7272
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd/go.mod h1:QuCEs1Nt24+FYQEqAAncTDPJIuGs+LxK1MCiFL25pMU=
7373
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=

p2p/protocol/holepunch/holepunch_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,8 @@ func quicSimnet(isPubliclyReachably bool, router *simnet.SimpleFirewallRouter) l
637637
if isPubliclyReachably {
638638
router.SetAddrPubliclyReachable(address)
639639
}
640-
c := simnet.NewSimConn(address, router)
640+
c := simnet.NewSimConn(address)
641+
router.AddNode(address, c)
641642
return c, nil
642643
}))
643644
}

x/simlibp2p/libp2p.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,12 @@ type NetworkSettings struct {
207207
BlankHostOptsForHostIdx func(idx int) BlankHostOpts
208208
}
209209

210-
func SimpleLibp2pNetwork(linkSettings []NodeLinkSettingsAndCount, networkSettings NetworkSettings) (*simnet.Simnet, *SimpleLibp2pNetworkMeta, error) {
211-
nw := &simnet.Simnet{}
210+
type LatencyFunc func(*simnet.Packet) time.Duration
211+
212+
func SimpleLibp2pNetwork(linkSettings []NodeLinkSettingsAndCount, latencyFunc LatencyFunc, networkSettings NetworkSettings) (*simnet.Simnet, *SimpleLibp2pNetworkMeta, error) {
213+
nw := &simnet.Simnet{
214+
LatencyFunc: latencyFunc,
215+
}
212216
meta := &SimpleLibp2pNetworkMeta{
213217
AddrToNode: make(map[string]HostAndIdx),
214218
}
@@ -261,12 +265,12 @@ func SimpleLibp2pNetwork(linkSettings []NodeLinkSettingsAndCount, networkSetting
261265
// GetBasicHostPair gets a new pair of hosts.
262266
// The first host initiates the connection to the second host.
263267
func GetBasicHostPair(t *testing.T) (host.Host, host.Host) {
264-
network, meta, err := SimpleLibp2pNetwork([]NodeLinkSettingsAndCount{
265-
{LinkSettings: simnet.NodeBiDiLinkSettings{
266-
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps, Latency: 100 * time.Millisecond / 2}, // Divide by two since this is latency for each direction
267-
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps, Latency: 100 * time.Millisecond / 2},
268+
network, meta, err := SimpleLibp2pNetwork([]NodeLinkSettingsAndCount{{
269+
LinkSettings: simnet.NodeBiDiLinkSettings{
270+
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps},
271+
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * OneMbps},
268272
}, Count: 2},
269-
}, NetworkSettings{})
273+
}, simnet.StaticLatency(100/2*time.Millisecond), NetworkSettings{})
270274
require.NoError(t, err)
271275
network.Start()
272276
t.Cleanup(func() {

x/simlibp2p/synctest_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ func TestSimpleLibp2pNetwork_synctest(t *testing.T) {
2323
latency := 10 * time.Millisecond
2424
network, meta, err := simlibp2p.SimpleLibp2pNetwork([]simlibp2p.NodeLinkSettingsAndCount{
2525
{LinkSettings: simnet.NodeBiDiLinkSettings{
26-
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps, Latency: latency / 2}, // Divide by two since this is latency for each direction
27-
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps, Latency: latency / 2},
26+
Downlink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps}, // Divide by two since this is latency for each direction
27+
Uplink: simnet.LinkSettings{BitsPerSecond: 20 * simlibp2p.OneMbps},
2828
}, Count: 100},
29-
}, simlibp2p.NetworkSettings{})
29+
}, simnet.StaticLatency(latency/2), simlibp2p.NetworkSettings{})
3030
require.NoError(t, err)
3131
network.Start()
3232
defer network.Close()
@@ -74,19 +74,17 @@ func TestSimpleLibp2pNetwork_synctest(t *testing.T) {
7474
}
7575

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

8081
const bandwidth = 10 * simlibp2p.OneMbps
81-
const latency = 10 * time.Millisecond
8282
linkSettings := simnet.NodeBiDiLinkSettings{
8383
Downlink: simnet.LinkSettings{
8484
BitsPerSecond: bandwidth,
85-
Latency: latency / 2,
8685
},
8786
Uplink: simnet.LinkSettings{
8887
BitsPerSecond: bandwidth,
89-
Latency: latency / 2,
9088
},
9189
}
9290

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

104-
err := router.Start()
105-
require.NoError(t, err)
102+
router.Start()
106103
defer router.Close()
107104

108105
defer hostA.Close()
109106
defer hostB.Close()
110107

111-
err = hostA.Connect(context.Background(), peer.AddrInfo{
108+
err := hostA.Connect(context.Background(), peer.AddrInfo{
112109
ID: hostB.ID(),
113110
Addrs: hostB.Addrs(),
114111
})

0 commit comments

Comments
 (0)