Skip to content

Commit

Permalink
Merge pull request #263 from gravitl/GRA-1363-port-check
Browse files Browse the repository at this point in the history
GRA-1363: set ports on register/join
  • Loading branch information
0xdcarns authored Mar 10, 2023
2 parents 61386e4 + f46f735 commit fd17b6c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions functions/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ func JoinNetwork(flags *viper.Viper) (*config.Node, *config.Server, error) {
if internetGateway != nil {
config.Netclient().InternetGateway = *internetGateway
}
if joinResponse.Host.ListenPort != 0 { // just duct tape till access keys removed
config.Netclient().ListenPort = joinResponse.Host.ListenPort
}
if joinResponse.Host.ProxyListenPort != 0 {
config.Netclient().ProxyListenPort = joinResponse.Host.ProxyListenPort
}
return &newNode, server, nil
}

Expand Down
18 changes: 12 additions & 6 deletions functions/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,32 @@ func Register(token string) error {
if shouldUpdateHost { // get most up to date values before submitting to server
host = config.Netclient()
}
api := httpclient.JSONEndpoint[models.ServerConfig, models.ErrorResponse]{
api := httpclient.JSONEndpoint[models.RegisterResponse, models.ErrorResponse]{
URL: "https://" + serverData.Server,
Route: "/api/v1/host/register/" + token,
Method: http.MethodPost,
Data: host,
Response: models.ServerConfig{},
Response: models.RegisterResponse{},
ErrorResponse: models.ErrorResponse{},
}
registerResponse, errData, err := api.GetJSON(models.ServerConfig{}, models.ErrorResponse{})
registerResponse, errData, err := api.GetJSON(models.RegisterResponse{}, models.ErrorResponse{})
if err != nil {
if errors.Is(err, httpclient.ErrStatus) {
logger.FatalLog("error registering with server", strconv.Itoa(errData.Code), errData.Message)
}
return err
}
config.UpdateServerConfig(&registerResponse)
server := config.GetServer(registerResponse.Server)
if err := config.SaveServer(registerResponse.Server, *server); err != nil {
config.UpdateServerConfig(&registerResponse.ServerConf)
server := config.GetServer(registerResponse.ServerConf.Server)
if err := config.SaveServer(registerResponse.ServerConf.Server, *server); err != nil {
logger.Log(0, "failed to save server", err.Error())
}
if registerResponse.RequestedHost.ListenPort > 0 {
config.Netclient().ListenPort = registerResponse.RequestedHost.ListenPort
}
if registerResponse.RequestedHost.ProxyListenPort > 0 {
config.Netclient().ProxyListenPort = registerResponse.RequestedHost.ProxyListenPort
}
if err := config.WriteNetclientConfig(); err != nil {
logger.Log(0, "error saving netclient config", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/nftables v0.1.0
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.5.0
github.com/gravitl/netmaker v0.18.3-0.20230309174451-286781a1a3de
github.com/gravitl/netmaker v0.18.3-0.20230310181223-aebc364e07ac
github.com/gravitl/txeh v0.0.0-20230210102514-3bcf9822a4cc
github.com/guumaster/hostctl v1.1.3
github.com/hashicorp/go-version v1.6.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ github.com/gravitl/netmaker v0.18.2-0.20230303153704-dba954c5299a h1:7qJpoPVmFgy
github.com/gravitl/netmaker v0.18.2-0.20230303153704-dba954c5299a/go.mod h1:QEy/5E6JtG+qNh3gZ/DZo6O/AIDuhZQnkkHMZdwGakI=
github.com/gravitl/netmaker v0.18.3-0.20230309174451-286781a1a3de h1:thrgjpJ/Er1FTRmhSmQsc/we85e147tgdsvl1rdQ7Cg=
github.com/gravitl/netmaker v0.18.3-0.20230309174451-286781a1a3de/go.mod h1:0OxyWajFh7BJ/zA1+My2S/+y0uXr3mtu2q8hbieohoQ=
github.com/gravitl/netmaker v0.18.3-0.20230310161829-7484e3f6da5c h1:AVCoI1tc/47dnxQ1q1ICRJ62OlTRjn23tMVmtFeX27Y=
github.com/gravitl/netmaker v0.18.3-0.20230310161829-7484e3f6da5c/go.mod h1:0OxyWajFh7BJ/zA1+My2S/+y0uXr3mtu2q8hbieohoQ=
github.com/gravitl/netmaker v0.18.3-0.20230310164326-ee9df20b0562 h1:s6K9ryxa2/EcJH5QAKRf3rRYR+/SPur5egEPrCyUNmo=
github.com/gravitl/netmaker v0.18.3-0.20230310164326-ee9df20b0562/go.mod h1:0OxyWajFh7BJ/zA1+My2S/+y0uXr3mtu2q8hbieohoQ=
github.com/gravitl/netmaker v0.18.3-0.20230310181223-aebc364e07ac h1:lIA+2C4dQBk6LwNrLl7cb39oO/My4ziI09HdW/tQ3/Q=
github.com/gravitl/netmaker v0.18.3-0.20230310181223-aebc364e07ac/go.mod h1:0OxyWajFh7BJ/zA1+My2S/+y0uXr3mtu2q8hbieohoQ=
github.com/gravitl/txeh v0.0.0-20230210102514-3bcf9822a4cc h1:PF7f+zhhn5pQDjAGNckcdola8ap7IkTa6OOMIEZcq0Q=
github.com/gravitl/txeh v0.0.0-20230210102514-3bcf9822a4cc/go.mod h1:92b/CoEzM+PNkeuYN1YyIf2SMH/8KNg5tlQYvuivbD8=
github.com/guumaster/hostctl v1.1.3 h1:b/yR3svkYsbr5VBdvfdyLXUl2xaKopSzgE/Xi7+1WRo=
Expand Down

0 comments on commit fd17b6c

Please sign in to comment.