Skip to content

Commit

Permalink
add WithConnectionManager option to blankhost
Browse files Browse the repository at this point in the history
  • Loading branch information
yusefnapora committed May 8, 2020
1 parent 29bca34 commit 4524c22
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions p2p/host/blank/blank.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,29 @@ type BlankHost struct {
}
}

func NewBlankHost(n network.Network) *BlankHost {
type config struct {
cmgr connmgr.ConnManager
}

type Option = func(cfg *config)

func WithConnectionManager(cmgr connmgr.ConnManager) Option {
return func(cfg *config) {
cfg.cmgr = cmgr
}
}

func NewBlankHost(n network.Network, options ...Option) *BlankHost {
cfg := config{
cmgr: &connmgr.NullConnMgr{},
}
for _, opt := range options {
opt(&cfg)
}

bh := &BlankHost{
n: n,
cmgr: &connmgr.NullConnMgr{},
cmgr: cfg.cmgr,
mux: mstream.NewMultistreamMuxer(),
eventbus: eventbus.NewBus(),
}
Expand Down

0 comments on commit 4524c22

Please sign in to comment.