mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-22 16:13:31 +01:00
feature: add stop handling for engine
This commit is contained in:
parent
74355a2292
commit
8088c7a591
@ -53,7 +53,7 @@ func SetupCloseHandler() {
|
||||
go func() {
|
||||
for range c {
|
||||
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
||||
os.Exit(0)
|
||||
stopUP <- 0
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ var (
|
||||
iFaceBlackList[config.IFaceBlackList[i]] = struct{}{}
|
||||
}
|
||||
engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr, iFaceBlackList)
|
||||
defer engine.Stop()
|
||||
|
||||
err = engine.Start(myKey, config.Peers)
|
||||
if err != nil {
|
||||
@ -48,8 +49,9 @@ var (
|
||||
//signalClient.WaitConnected()
|
||||
|
||||
SetupCloseHandler()
|
||||
<-stopUP
|
||||
code := <-stopUP
|
||||
log.Println("Receive signal to stop running")
|
||||
os.Exit(code)
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -46,6 +46,23 @@ func NewEngine(signal *signal.Client, stunsTurns []*ice.URL, wgIface string, wgA
|
||||
iFaceBlackList: iFaceBlackList,
|
||||
}
|
||||
}
|
||||
func (e *Engine) Stop() error {
|
||||
err := iface.Delete()
|
||||
if err != nil {
|
||||
log.Errorf("error while deleting Wireguard interface")
|
||||
return err
|
||||
}
|
||||
|
||||
err = e.signal.Close()
|
||||
if err != nil {
|
||||
log.Errorf("error while closing a connection to the signal server")
|
||||
return err
|
||||
}
|
||||
for _, c := range e.conns {
|
||||
c.Close() //nolint
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start creates a new tunnel interface and listens to signals from the Signal service.
|
||||
// It also creates an Go routine to handle each peer communication from the config file
|
||||
|
@ -19,6 +19,11 @@ const (
|
||||
// Saves tun device object - is it required?
|
||||
var tunIface tun.Device
|
||||
|
||||
// Delete deletes an existing Wireguard interface
|
||||
func Delete() error {
|
||||
return tunIface.Close()
|
||||
}
|
||||
|
||||
// Create Creates a new Wireguard interface, sets a given IP and brings it up.
|
||||
// Will reuse an existing one.
|
||||
func Create(iface string, address string) error {
|
||||
|
Loading…
Reference in New Issue
Block a user