Skip to content

Commit 9bf820e

Browse files
authored
Merge pull request #308 from kcalvinalvin/2024-12-06-on-timout
query: add OnMaxTries
2 parents d7c6562 + 9cb6f08 commit 9bf820e

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)