add a WithEventBus constructor option
@@ -38,6 +38,7 @@ type BlankHost struct {
type config struct {
cmgr connmgr.ConnManager
+ eventBus event.Bus
}
type Option = func(cfg *config)
@@ -48,6 +49,12 @@ func WithConnectionManager(cmgr connmgr.ConnManager) Option {
}
}
+func WithEventBus(eventBus event.Bus) Option {
+ return func(cfg *config) {
+ cfg.eventBus = eventBus
+ }
+}
+
func NewBlankHost(n network.Network, options ...Option) *BlankHost {
cfg := config{
cmgr: &connmgr.NullConnMgr{},
@@ -60,7 +67,9 @@ func NewBlankHost(n network.Network, options ...Option) *BlankHost {
n: n,
cmgr: cfg.cmgr,
mux: mstream.NewMultistreamMuxer(),
- eventbus: eventbus.NewBus(),
+ }
+ if bh.eventbus == nil {
+ bh.eventbus = eventbus.NewBus()
}
// subscribe the connection manager to network notifications (has no effect with NullConnMgr)
