From a5c19c65f4833a104ac68f35a3c0f8f37be8fe87 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 14 Nov 2022 22:20:10 +0400 Subject: [PATCH] feat: provide public IP discovered from the server 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 --- pkg/client/client.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/client/client.go b/pkg/client/client.go index f68984d..5a19486 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -71,6 +71,7 @@ type Client struct { discoveredMu sync.Mutex discoveredAffiliates map[string]*Affiliate + discoveredPublicIP []byte gcm cipher.AEAD backoff *backoff.ExponentialBackOff @@ -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. @@ -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 }