Skip to content

Commit

Permalink
autoygg-client improvements:
Browse files Browse the repository at this point in the history
* feature: send client version on every request to the server and store
  it in the state file so that it can be displayed easily in LuCI.

* bugfix: do not keep retrying invalid actions

* bugfix: save DesiredState when disconnecting

* bugfix: do not consider routes that are not attached to a specific
interface when determining the default gateway interface

autoygg-server improvements:

* feature: save client version in database
  • Loading branch information
cure committed Aug 5, 2020
1 parent ac63e88 commit 59f54c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
type state struct {
State string `json:"state"`
DesiredState string `json:"desiredstate"`
ClientVersion string `json:"clientversion"`
Error string `json:"error"`
GatewayHost string `json:"gatewayhost"`
GatewayPort string `json:"gatewayport"`
Expand Down Expand Up @@ -85,7 +86,8 @@ func doRequestWorker(fs *flag.FlagSet, verb string, action string, gatewayHost s
}
if !validActions[action] {
err = errors.New("Invalid action: " + action)
return
// Invalid action is a fatal error, abort here
handleError(err, true)
}
var r registration
r.PublicKey, err = getSelfPublicKey()
Expand All @@ -95,6 +97,7 @@ func doRequestWorker(fs *flag.FlagSet, verb string, action string, gatewayHost s
r.ClientName = viper.GetString("clientname")
r.ClientEmail = viper.GetString("clientemail")
r.ClientPhone = viper.GetString("clientphone")
r.ClientVersion = version
req, err := json.Marshal(r)
if err != nil {
return
Expand Down Expand Up @@ -467,6 +470,7 @@ func ClientMain() {
if err != nil {
logAndExit(err.Error(), 1)
}
State.ClientVersion = version

if viper.GetBool("State") {
json, err := json.MarshalIndent(State, "", " ")
Expand All @@ -491,6 +495,7 @@ func ClientMain() {
State.DesiredState = "connected"
} else if viper.GetString("Action") == "release" {
State.DesiredState = "disconnected"
_ = saveState(State)
State, err = clientTearDownRoutes(State.ClientIP, State.ClientNetMask, State.ClientGateway, State.GatewayPublicKey, State)
if err != nil {
Fatal(err)
Expand Down Expand Up @@ -536,6 +541,7 @@ func ClientMain() {
}
gatewayIP = tmpIP.String()
gatewayDev = tmpDev
debug("Detected gatewayIP %s via gatewayDev %s\n", gatewayIP, gatewayDev)
}
State, err = clientSetupRoutes(r.ClientIP, r.ClientNetMask, r.ClientGateway, r.GatewayPublicKey, gatewayIP, gatewayDev, State)
}
Expand Down Expand Up @@ -566,6 +572,7 @@ func ClientMain() {
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
<-sig
fmt.Fprint(os.Stderr, "\r") // Overwrite any ^C that may have been printed on the screen
State.DesiredState = "disconnected"
State, _ = clientTearDownRoutes(r.ClientIP, r.ClientNetMask, r.ClientGateway, r.GatewayPublicKey, State)
_, State, _ = doRequest(fs, "release", viper.GetString("GatewayHost"), viper.GetString("GatewayPort"), State)
_ = saveState(State)
Expand Down Expand Up @@ -632,6 +639,12 @@ func parseLinuxProcNetRoute(YggdrasilInterface string, f []byte) (string, net.IP
debug("Skipping %s via %s\n", net.IP(ipd32), tokens[devfield])
continue
}
// If there are any routes that are not attached to a specific interface,
// like blacklist routes, skip those too
if tokens[devfield] == "*" {
debug("Skipping %s via %s\n", net.IP(ipd32), tokens[devfield])
continue
}

// format net.IP to dotted ipV4 string
debug("Returning %s via %s\n", net.IP(ipd32), tokens[devfield])
Expand Down
1 change: 1 addition & 0 deletions internal/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type registration struct {
ClientName string // Registration name (optional)
ClientEmail string // Registration email (optional)
ClientPhone string // Registration phone (optional)
ClientVersion string // Autoygg client software version
LeaseExpires time.Time
Error string
}
Expand Down

0 comments on commit 59f54c0

Please sign in to comment.