Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

Commit a35db1d

Browse files
authored
Merge pull request #44 from libp2p/feat/connmgr-option
add WithConnectionManager option to blankhost
2 parents 0fd4631 + d685d71 commit a35db1d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

blank.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,29 @@ type BlankHost struct {
3636
}
3737
}
3838

39-
func NewBlankHost(n network.Network) *BlankHost {
39+
type config struct {
40+
cmgr connmgr.ConnManager
41+
}
42+
43+
type Option = func(cfg *config)
44+
45+
func WithConnectionManager(cmgr connmgr.ConnManager) Option {
46+
return func(cfg *config) {
47+
cfg.cmgr = cmgr
48+
}
49+
}
50+
51+
func NewBlankHost(n network.Network, options ...Option) *BlankHost {
52+
cfg := config{
53+
cmgr: &connmgr.NullConnMgr{},
54+
}
55+
for _, opt := range options {
56+
opt(&cfg)
57+
}
58+
4059
bh := &BlankHost{
4160
n: n,
42-
cmgr: &connmgr.NullConnMgr{},
61+
cmgr: cfg.cmgr,
4362
mux: mstream.NewMultistreamMuxer(),
4463
eventbus: eventbus.NewBus(),
4564
}

0 commit comments

Comments
 (0)