Skip to content

Commit

Permalink
feat: provide public IP discovered from the server
Browse files Browse the repository at this point in the history
Discovery Service provides public IP as seen by the server.

This public IP can be used to provide additional information to the
node.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Nov 15, 2022
1 parent 230f317 commit a5c19c6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Client struct {

discoveredMu sync.Mutex
discoveredAffiliates map[string]*Affiliate
discoveredPublicIP []byte

gcm cipher.AEAD
backoff *backoff.ExponentialBackOff
Expand Down Expand Up @@ -222,6 +223,14 @@ func (client *Client) GetAffiliates() []*Affiliate {
return result
}

// GetPublicIP returns client's discovered public IP.
func (client *Client) GetPublicIP() []byte {
client.discoveredMu.Lock()
defer client.discoveredMu.Unlock()

return append([]byte(nil), client.discoveredPublicIP...)
}

// Run the client loop.
//
// Client automatically keeps the connection, refreshes data based on TTL.
Expand Down Expand Up @@ -470,6 +479,10 @@ func (client *Client) sendHello(ctx context.Context, discoveryClient serverpb.Cl
return "", err
}

client.discoveredMu.Lock()
client.discoveredPublicIP = resp.ClientIp
client.discoveredMu.Unlock()

if resp.Redirect != nil {
return resp.Redirect.Endpoint, nil
}
Expand Down

0 comments on commit a5c19c6

Please sign in to comment.