2021-05-01 12:45:37 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/wiretrustee/wiretrustee/connection"
|
|
|
|
sig "github.com/wiretrustee/wiretrustee/signal"
|
2021-05-01 18:29:59 +02:00
|
|
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
2021-05-01 12:45:37 +02:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
upCmd = &cobra.Command{
|
|
|
|
Use: "up",
|
|
|
|
Short: "start wiretrustee",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2021-05-01 15:47:24 +02:00
|
|
|
InitLog(logLevel)
|
2021-05-01 12:45:37 +02:00
|
|
|
|
|
|
|
config, _ := Read(configPath)
|
|
|
|
|
2021-05-01 18:29:59 +02:00
|
|
|
myKey, err := wgtypes.ParseKey(config.PrivateKey)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed parsing Wireguard key %s: [%s]", config.PrivateKey, err.Error())
|
|
|
|
os.Exit(ExitSetupFailed)
|
|
|
|
}
|
|
|
|
|
2021-05-01 12:45:37 +02:00
|
|
|
ctx := context.Background()
|
2021-05-15 12:20:49 +02:00
|
|
|
signalClient, err := sig.NewClient(ctx, config.SignalAddr, myKey)
|
2021-05-01 12:45:37 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("error while connecting to the Signal Exchange Service %s: %s", config.SignalAddr, err)
|
|
|
|
os.Exit(ExitSetupFailed)
|
|
|
|
}
|
|
|
|
//todo proper close handling
|
|
|
|
defer func() { signalClient.Close() }()
|
|
|
|
|
2021-05-16 18:05:08 +02:00
|
|
|
iFaceBlackList := make(map[string]struct{})
|
|
|
|
for i := 0; i < len(config.IFaceBlackList); i += 2 {
|
|
|
|
iFaceBlackList[config.IFaceBlackList[i]] = struct{}{}
|
|
|
|
}
|
|
|
|
engine := connection.NewEngine(signalClient, config.StunTurnURLs, config.WgIface, config.WgAddr, iFaceBlackList)
|
2021-05-01 12:45:37 +02:00
|
|
|
|
2021-05-01 18:29:59 +02:00
|
|
|
err = engine.Start(myKey, config.Peers)
|
2021-05-15 12:20:49 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("error while starting the engine: %s", err)
|
|
|
|
os.Exit(ExitSetupFailed)
|
|
|
|
}
|
2021-05-01 12:45:37 +02:00
|
|
|
//signalClient.WaitConnected()
|
|
|
|
|
|
|
|
SetupCloseHandler()
|
2021-05-19 11:13:25 +02:00
|
|
|
select {}
|
2021-05-01 12:45:37 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
}
|