refactor peer controller switch

This commit is contained in:
Joost Jager 2023-02-13 14:29:36 +01:00
parent e5db10089f
commit 56fb959379
No known key found for this signature in database
GPG key ID: B9A26449A5528325

View file

@ -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) {