Skip to content

Commit

Permalink
Merge pull request #44 from libp2p/feat/connmgr-option
Browse files Browse the repository at this point in the history
add WithConnectionManager option to blankhost
  • Loading branch information
vyzo authored May 8, 2020
2 parents f318aed + 4524c22 commit 693d670
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 @@ -36,10 +36,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 693d670

Please sign in to comment.