mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-24 11:41:35 +02:00
feature: add stop handling for engine
This commit is contained in:
parent
74355a2292
commit
8088c7a591
@ -53,7 +53,7 @@ func SetupCloseHandler() {
|
|||||||
go func() {
|
go func() {
|
||||||
for range c {
|
for range c {
|
||||||
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
||||||
os.Exit(0)
|
stopUP <- 0
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ var (
|
|||||||
iFaceBlackList[config.IFaceBlackList[i]] = struct{}{}
|
iFaceBlackList[config.IFaceBlackList[i]] = struct{}{}
|
||||||
}
|
}
|
||||||
engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr, iFaceBlackList)
|
engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr, iFaceBlackList)
|
||||||
|
defer engine.Stop()
|
||||||
|
|
||||||
err = engine.Start(myKey, config.Peers)
|
err = engine.Start(myKey, config.Peers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,8 +49,9 @@ var (
|
|||||||
//signalClient.WaitConnected()
|
//signalClient.WaitConnected()
|
||||||
|
|
||||||
SetupCloseHandler()
|
SetupCloseHandler()
|
||||||
<-stopUP
|
code := <-stopUP
|
||||||
log.Println("Receive signal to stop running")
|
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,
|
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.
|
// 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
|
// 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?
|
// Saves tun device object - is it required?
|
||||||
var tunIface tun.Device
|
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.
|
// Create Creates a new Wireguard interface, sets a given IP and brings it up.
|
||||||
// Will reuse an existing one.
|
// Will reuse an existing one.
|
||||||
func Create(iface string, address string) error {
|
func Create(iface string, address string) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user