Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
1e5f280a
Commit
1e5f280a
authored
Dec 10, 2014
by
Jeromy
Committed by
Brian Tiger Chow
Dec 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
give sessiongenerator a master context for easy cancelling
parent
33ae9d43
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
testutils.go
testutils.go
+19
-11
No files found.
testutils.go
View file @
1e5f280a
...
...
@@ -17,24 +17,33 @@ import (
func
NewSessionGenerator
(
net
tn
.
Network
,
rs
mockrouting
.
Server
)
SessionGenerator
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
TODO
())
return
SessionGenerator
{
net
:
net
,
rs
:
rs
,
ps
:
peer
.
NewPeerstore
(),
seq
:
0
,
ps
:
peer
.
NewPeerstore
(),
net
:
net
,
rs
:
rs
,
seq
:
0
,
ctx
:
ctx
,
cancel
:
cancel
,
}
}
type
SessionGenerator
struct
{
seq
int
net
tn
.
Network
rs
mockrouting
.
Server
ps
peer
.
Peerstore
seq
int
net
tn
.
Network
rs
mockrouting
.
Server
ps
peer
.
Peerstore
ctx
context
.
Context
cancel
context
.
CancelFunc
}
func
(
g
*
SessionGenerator
)
Stop
()
{
g
.
cancel
()
}
func
(
g
*
SessionGenerator
)
Next
()
Instance
{
g
.
seq
++
return
session
(
g
.
net
,
g
.
rs
,
g
.
ps
,
[]
byte
(
string
(
g
.
seq
)))
return
session
(
g
.
ctx
,
g
.
net
,
g
.
rs
,
g
.
ps
,
[]
byte
(
string
(
g
.
seq
)))
}
func
(
g
*
SessionGenerator
)
Instances
(
n
int
)
[]
Instance
{
...
...
@@ -67,7 +76,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// NB: It's easy make mistakes by providing the same peer ID to two different
// sessions. To safeguard, use the SessionGenerator to generate sessions. It's
// just a much better idea.
func
session
(
net
tn
.
Network
,
rs
mockrouting
.
Server
,
ps
peer
.
Peerstore
,
id
peer
.
ID
)
Instance
{
func
session
(
ctx
context
.
Context
,
net
tn
.
Network
,
rs
mockrouting
.
Server
,
ps
peer
.
Peerstore
,
id
peer
.
ID
)
Instance
{
p
:=
ps
.
WithID
(
id
)
adapter
:=
net
.
Adapter
(
p
)
...
...
@@ -82,7 +91,6 @@ func session(net tn.Network, rs mockrouting.Server, ps peer.Peerstore, id peer.I
}
const
alwaysSendToPeer
=
true
ctx
:=
context
.
TODO
()
bs
:=
New
(
ctx
,
p
,
adapter
,
htc
,
bstore
,
alwaysSendToPeer
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment