Skip to content

Commit 9cb6f08

Browse files
committed
query: add onmaxtries config option
OnMaxTries config gives the caller access to the peer's address once a maximum number of retries have been attempted. This config helps meet the needs of different callers as some may use the address to immediately disconnect the peer vs others that may choose to try again.
1 parent 81d6cd2 commit 9cb6f08

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

query/workmanager.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ type Config struct {
9494
// make this configurable to easily mock the worker used during tests.
9595
NewWorker func(Peer) Worker
9696

97+
// OnMaxTries gives the caller access to the Peer object once a maximum
98+
// number of retries have been attempted. The caller can then access the
99+
// Peer's address and can choose to punish the peer accordingly.
100+
OnMaxTries func(Peer)
101+
97102
// Ranking is used to rank the connected peers when determining who to
98103
// give work to.
99104
Ranking PeerRanking
@@ -381,6 +386,14 @@ Loop:
381386
log.Debugf("Canceled batch %v",
382387
batchNum)
383388

389+
// Since we've reached this query's
390+
// maximum number of retries, now is the
391+
// time to call the OnMaxTries callback
392+
// function if it isn't nil.
393+
if w.cfg.OnMaxTries != nil {
394+
w.cfg.OnMaxTries(result.peer)
395+
}
396+
384397
continue Loop
385398
}
386399

0 commit comments

Comments
 (0)