mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-25 13:59:08 +01:00
Extend the cmd with argument handling
- add cobra to relay server - add logger instance for handshaker
This commit is contained in:
@@ -111,6 +111,7 @@ func NewClient(ctx context.Context, serverAddress, peerID string) *Client {
|
||||
|
||||
// Connect establishes a connection to the relay server. It blocks until the connection is established or an error occurs.
|
||||
func (c *Client) Connect() error {
|
||||
log.Infof("connecting to relay server: %s", c.serverAddress)
|
||||
c.readLoopMutex.Lock()
|
||||
defer c.readLoopMutex.Unlock()
|
||||
|
||||
@@ -139,6 +140,7 @@ func (c *Client) Connect() error {
|
||||
c.wgReadLoop.Add(1)
|
||||
go c.readLoop(c.relayConn)
|
||||
|
||||
log.Infof("relay connection established with: %s", c.serverAddress)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+24
-4
@@ -6,13 +6,27 @@ import (
|
||||
"syscall"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/netbirdio/netbird/relay/server"
|
||||
"github.com/netbirdio/netbird/util"
|
||||
)
|
||||
|
||||
var (
|
||||
listenAddress string
|
||||
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "relay",
|
||||
Short: "Relay service",
|
||||
Long: "Relay service for Netbird agents",
|
||||
Run: execute,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
util.InitLog("trace", "console")
|
||||
_ = util.InitLog("trace", "console")
|
||||
rootCmd.PersistentFlags().StringVarP(&listenAddress, "listen-address", "l", ":1235", "listen address")
|
||||
|
||||
}
|
||||
|
||||
func waitForExitSignal() {
|
||||
@@ -21,10 +35,9 @@ func waitForExitSignal() {
|
||||
_ = <-osSigs
|
||||
}
|
||||
|
||||
func main() {
|
||||
address := "10.145.236.1:1235"
|
||||
func execute(cmd *cobra.Command, args []string) {
|
||||
srv := server.NewServer()
|
||||
err := srv.Listen(address)
|
||||
err := srv.Listen(listenAddress)
|
||||
if err != nil {
|
||||
log.Errorf("failed to bind server: %s", err)
|
||||
os.Exit(1)
|
||||
@@ -38,3 +51,10 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user