diff --git a/channelmonitor/channelmonitor.go b/channelmonitor/channelmonitor.go index 25d6a0ab..e14ee683 100644 --- a/channelmonitor/channelmonitor.go +++ b/channelmonitor/channelmonitor.go @@ -34,6 +34,10 @@ type Monitor struct { } type Config struct { + // Indicates whether push channel monitoring is enabled + MonitorPushChannels bool + // Indicates whether pull channel monitoring is enabled + MonitorPullChannels bool // Max time to wait for other side to accept open channel request before attempting restart AcceptTimeout time.Duration // Interval between checks of transfer rate @@ -111,6 +115,12 @@ func (m *Monitor) addChannel(chid datatransfer.ChannelID, isPush bool) monitored if !m.enabled() { return nil } + if isPush && !m.cfg.MonitorPushChannels { + return nil + } + if !isPush && !m.cfg.MonitorPullChannels { + return nil + } m.lk.Lock() defer m.lk.Unlock() diff --git a/channelmonitor/channelmonitor_test.go b/channelmonitor/channelmonitor_test.go index 86105637..410bcf0a 100644 --- a/channelmonitor/channelmonitor_test.go +++ b/channelmonitor/channelmonitor_test.go @@ -59,6 +59,7 @@ func TestPushChannelMonitorAutoRestart(t *testing.T) { mockAPI := newMockMonitorAPI(ch, tc.errOnRestart) m := NewMonitor(mockAPI, &Config{ + MonitorPushChannels: true, AcceptTimeout: time.Hour, Interval: 10 * time.Millisecond, ChecksPerInterval: 10, @@ -144,6 +145,7 @@ func TestPullChannelMonitorAutoRestart(t *testing.T) { mockAPI := newMockMonitorAPI(ch, tc.errOnRestart) m := NewMonitor(mockAPI, &Config{ + MonitorPullChannels: true, AcceptTimeout: time.Hour, Interval: 10 * time.Millisecond, ChecksPerInterval: 10, @@ -306,6 +308,7 @@ func TestPushChannelMonitorDataRate(t *testing.T) { checksPerInterval := uint32(1) m := NewMonitor(mockAPI, &Config{ + MonitorPushChannels: true, AcceptTimeout: time.Hour, Interval: time.Hour, ChecksPerInterval: checksPerInterval, @@ -374,6 +377,7 @@ func TestPullChannelMonitorDataRate(t *testing.T) { checksPerInterval := uint32(1) m := NewMonitor(mockAPI, &Config{ + MonitorPullChannels: true, AcceptTimeout: time.Hour, Interval: time.Hour, ChecksPerInterval: checksPerInterval, @@ -418,6 +422,8 @@ func TestChannelMonitorMaxConsecutiveRestarts(t *testing.T) { maxConsecutiveRestarts := 3 m := NewMonitor(mockAPI, &Config{ + MonitorPushChannels: isPush, + MonitorPullChannels: !isPush, AcceptTimeout: time.Hour, Interval: time.Hour, ChecksPerInterval: 1, @@ -536,6 +542,8 @@ func TestChannelMonitorTimeouts(t *testing.T) { acceptTimeout := 10 * time.Millisecond completeTimeout := 10 * time.Millisecond m := NewMonitor(mockAPI, &Config{ + MonitorPushChannels: isPush, + MonitorPullChannels: !isPush, AcceptTimeout: acceptTimeout, Interval: time.Hour, ChecksPerInterval: 1, @@ -550,7 +558,7 @@ func TestChannelMonitorTimeouts(t *testing.T) { mch := m.AddPushChannel(ch1).(*monitoredPushChannel) chCtx = mch.ctx } else { - mch := m.AddPushChannel(ch1).(*monitoredPushChannel) + mch := m.AddPullChannel(ch1).(*monitoredPullChannel) chCtx = mch.ctx } diff --git a/impl/integration_test.go b/impl/integration_test.go index 4abaad22..c9b00d88 100644 --- a/impl/integration_test.go +++ b/impl/integration_test.go @@ -659,6 +659,8 @@ func TestAutoRestart(t *testing.T) { // Set up restartConf := ChannelRestartConfig(channelmonitor.Config{ + MonitorPushChannels: true, + MonitorPullChannels: true, AcceptTimeout: 100 * time.Millisecond, Interval: 100 * time.Millisecond, MinBytesTransferred: 1,