mirror of
https://github.com/lightningequipment/circuitbreaker.git
synced 2026-08-13 12:33:02 +02:00
refactor peer controller switch
This commit is contained in:
parent
e5db10089f
commit
56fb959379
1 changed files with 8 additions and 6 deletions
|
|
@ -276,6 +276,8 @@ func (p *peerController) run(ctx context.Context) error {
|
|||
continue
|
||||
}
|
||||
|
||||
mode := p.cfg.Mode
|
||||
|
||||
switch {
|
||||
// If there is a queue, then don't jump the queue.
|
||||
case queue.Len() > 0:
|
||||
|
|
@ -284,20 +286,20 @@ func (p *peerController) run(ctx context.Context) error {
|
|||
case !newHtlcAllowed:
|
||||
logger.Infow("Pending htlc limit exceeded")
|
||||
|
||||
// Check the rate limit and forward immediately if allowed.
|
||||
case p.limiter.Allow():
|
||||
// Check the rate limit.
|
||||
case !p.limiter.Allow():
|
||||
logger.Infow("Rate limit exceeded")
|
||||
|
||||
// All signs green, forward the htlc.
|
||||
default:
|
||||
if err := p.forward(event.interceptEvent); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
|
||||
default:
|
||||
logger.Infow("Rate limit exceeded")
|
||||
}
|
||||
|
||||
// Queue if in one of the queue modes.
|
||||
mode := p.cfg.Mode
|
||||
if mode == ModeQueue ||
|
||||
(mode == ModeQueuePeerInitiated && event.peerInitiated) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue