-
-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: wiring startup with the flow [IN PROGRESS]
- Loading branch information
Showing
6 changed files
with
156 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
package wiretrustee | ||
package cmd | ||
|
||
import "golang.zx2c4.com/wireguard/wgctrl/wgtypes" | ||
|
||
type Config struct { | ||
// Wireguard private key of local peer | ||
PrivateKey wgtypes.Key | ||
// configured remote peers (Wireguard public keys) | ||
Peers string | ||
Peers []string | ||
StunURL string | ||
TurnURL string | ||
TurnUser string | ||
TurnPwd string | ||
// host:port of the signal server | ||
SignalAddr string | ||
WgAddr string | ||
WgIface string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
var ( | ||
rootCmd = &cobra.Command{ | ||
Use: "wiretrustee", | ||
Short: "", | ||
Long: "", | ||
} | ||
) | ||
|
||
// Execute executes the root command. | ||
func Execute() error { | ||
return rootCmd.Execute() | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(upCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/pion/ice/v2" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/wiretrustee/wiretrustee/engine" | ||
"github.com/wiretrustee/wiretrustee/signal" | ||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" | ||
"os" | ||
) | ||
|
||
const ( | ||
ExitSetupFailed = 1 | ||
) | ||
|
||
var ( | ||
cfgFile string | ||
|
||
upCmd = &cobra.Command{ | ||
Use: "up", | ||
Short: "start wiretrustee", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
/*config, err := ReadConfig("config.yml") | ||
if err != nil { | ||
log.Fatal("failed to load config") | ||
os.Exit(ExitSetupFailed) | ||
}*/ | ||
|
||
c := defaultConfig() | ||
|
||
//todo print config | ||
|
||
//todo connect to signal | ||
ctx := context.Background() | ||
signalClient, err := signal.NewClient(c.SignalAddr, ctx) | ||
if err != nil { | ||
log.Errorf("error while connecting to the Signal Exchange Service %s: %s", c.SignalAddr, err) | ||
os.Exit(ExitSetupFailed) | ||
} | ||
//todo proper close handling | ||
defer func() { signalClient.Close() }() | ||
|
||
stunURL, _ := ice.ParseURL(fmt.Sprintf("stun:%s", c.StunURL)) | ||
turnURL, _ := ice.ParseURL(fmt.Sprintf("turn:%s", c.StunURL)) | ||
turnURL.Password = c.TurnPwd | ||
turnURL.Username = c.TurnUser | ||
urls := []*ice.URL{turnURL, stunURL} | ||
|
||
s := c.PrivateKey.PublicKey().String() | ||
|
||
engine := engine.NewEngine(signalClient, urls, c.WgIface, c.WgAddr) | ||
err = engine.Start(s, c.Peers) | ||
|
||
signalClient.WaitConnected() | ||
|
||
select {} | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
upCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.wiretrustee.yaml)") | ||
//upCmd.MarkPersistentFlagRequired("config") | ||
fmt.Printf("") | ||
} | ||
|
||
func defaultConfig() *Config { | ||
|
||
key, _ := wgtypes.ParseKey("OCVgR9VJT4y4tBscRQ6SYHWocQlykUMCDI6APjp3ilY=") | ||
|
||
return &Config{ | ||
PrivateKey: key, | ||
Peers: []string{"uRoZAk1g90WXXvazH0SS6URZ2/Kmhx+hbVhUt2ipzlU="}, | ||
SignalAddr: "signal.wiretrustee.com:10000", | ||
StunURL: "stun.wiretrustee.com:3468", | ||
TurnURL: "stun.wiretrustee.com:3468", | ||
TurnPwd: "wt2021hello@", | ||
TurnUser: "wiretrustee", | ||
WgAddr: "10.30.30.1/24", | ||
WgIface: "wt0", | ||
} | ||
} | ||
|
||
func ReadConfig(path string) (*Config, error) { | ||
/*f, err := os.Open(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
bs, err := ioutil.ReadAll(f) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var cfg Config | ||
err = yaml.Unmarshal(bs, &cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &cfg, nil*/ | ||
|
||
return &Config{}, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/wiretrustee/wiretrustee/cmd" | ||
"os" | ||
) | ||
|
||
func main() { | ||
if err := cmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |