diff --git a/channel/channel.go b/channel/channel.go index 677ac23..2b040c5 100644 --- a/channel/channel.go +++ b/channel/channel.go @@ -301,6 +301,7 @@ func (ch *Channel) readLoop(ctx context.Context) error { for { select { case <-ctx.Done(): + close(drain) return ctx.Err() case r := <-ch.readers: ch.opts.Logger.Debug("replaced reader", zap.String("remote", ch.remote.String()), zap.String("addr", r.Conn.RemoteAddr().String())) diff --git a/peer/opt.go b/peer/opt.go index dec9232..2df0884 100644 --- a/peer/opt.go +++ b/peer/opt.go @@ -93,6 +93,26 @@ func DefaultDiscoveryOptions() DiscoveryOptions { } } +func (opts DiscoveryOptions) WithLogger(logger *zap.Logger) DiscoveryOptions { + opts.Logger = logger + return opts +} + +func (opts DiscoveryOptions) WithAlpha(alpha int) DiscoveryOptions { + opts.Alpha = alpha + return opts +} + +func (opts DiscoveryOptions) WithMaxExpectedPeers(max int) DiscoveryOptions { + opts.MaxExpectedPeers = max + return opts +} + +func (opts DiscoveryOptions) WithPingTimePeriod(period time.Duration) DiscoveryOptions { + opts.PingTimePeriod = period + return opts +} + type Options struct { SyncerOptions GossiperOptions @@ -128,6 +148,11 @@ func (opts Options) WithGossiperOptions(gossiperOptions GossiperOptions) Options return opts } +func (opts Options) WithDiscoveryOptions(discoveryOptions DiscoveryOptions) Options { + opts.DiscoveryOptions = discoveryOptions + return opts +} + func (opts Options) WithLogger(logger *zap.Logger) Options { opts.Logger = logger return opts