Add a context object in nebula.Main to clean up on error (#550)

This commit is contained in:
brad-defined
2021-11-02 14:14:26 -04:00
committed by GitHub
parent 32cd9a93f1
commit 6ae8ba26f7
13 changed files with 139 additions and 40 deletions

View File

@@ -2,6 +2,7 @@ package nebula
import (
"bytes"
"context"
"crypto/rand"
"encoding/binary"
"errors"
@@ -66,14 +67,18 @@ func NewHandshakeManager(l *logrus.Logger, tunCidr *net.IPNet, preferredRanges [
}
}
func (c *HandshakeManager) Run(f EncWriter) {
clockSource := time.Tick(c.config.tryInterval)
func (c *HandshakeManager) Run(ctx context.Context, f EncWriter) {
clockSource := time.NewTicker(c.config.tryInterval)
defer clockSource.Stop()
for {
select {
case <-ctx.Done():
return
case vpnIP := <-c.trigger:
c.l.WithField("vpnIp", IntIp(vpnIP)).Debug("HandshakeManager: triggered")
c.handleOutbound(vpnIP, f, true)
case now := <-clockSource:
case now := <-clockSource.C:
c.NextOutboundHandshakeTimerTick(now, f)
}
}