Skip to content

Commit

Permalink
feat: add config options to enable / disable push or pull monitoring …
Browse files Browse the repository at this point in the history
…individually
  • Loading branch information
dirkmc committed Mar 24, 2021
1 parent b1a43bd commit 5c3308f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions channelmonitor/channelmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion channelmonitor/channelmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
}

Expand Down

0 comments on commit 5c3308f

Please sign in to comment.