seclient: syncronized state

This commit is contained in:
Vladislav Yarmak
2021-04-02 00:44:48 +03:00
parent b5090f10e9
commit ed153de1d0
+16 -3
View File
@@ -11,6 +11,7 @@ import (
"net/http/cookiejar" "net/http/cookiejar"
"net/url" "net/url"
"strings" "strings"
"sync"
dac "github.com/Snawoot/go-http-digest-auth-client" dac "github.com/Snawoot/go-http-digest-auth-client"
"golang.org/x/net/publicsuffix" "golang.org/x/net/publicsuffix"
@@ -66,6 +67,7 @@ type SEClient struct {
AssignedDeviceID string AssignedDeviceID string
AssignedDeviceIDHash string AssignedDeviceIDHash string
DevicePassword string DevicePassword string
StateMux sync.RWMutex
rng *rand.Rand rng *rand.Rand
} }
@@ -110,8 +112,13 @@ func (c *SEClient) AnonRegister(ctx context.Context) error {
return err return err
} }
c.SubscriberEmail = fmt.Sprintf("%s@%s.best.vpn", localPart, c.Settings.ClientType) subscriberEmail := fmt.Sprintf("%s@%s.best.vpn", localPart, c.Settings.ClientType)
c.SubscriberPassword = capitalHexSHA1(c.SubscriberEmail) subscriberPassword := capitalHexSHA1(subscriberEmail)
c.StateMux.Lock()
c.SubscriberEmail = subscriberEmail
c.SubscriberPassword = subscriberPassword
c.StateMux.Unlock()
return c.Register(ctx) return c.Register(ctx)
} }
@@ -149,9 +156,11 @@ func (c *SEClient) RegisterDevice(ctx context.Context) error {
regRes.Status.Code, regRes.Status.Message) regRes.Status.Code, regRes.Status.Message)
} }
c.StateMux.Lock()
c.AssignedDeviceID = regRes.Data.DeviceID c.AssignedDeviceID = regRes.Data.DeviceID
c.DevicePassword = regRes.Data.DevicePassword c.DevicePassword = regRes.Data.DevicePassword
c.AssignedDeviceIDHash = capitalHexSHA1(regRes.Data.DeviceID) c.AssignedDeviceIDHash = capitalHexSHA1(regRes.Data.DeviceID)
c.StateMux.Unlock()
return nil return nil
} }
@@ -209,7 +218,11 @@ func (c *SEClient) Login(ctx context.Context) error {
} }
func (c *SEClient) GetProxyCredentials() (string, string) { func (c *SEClient) GetProxyCredentials() (string, string) {
return c.AssignedDeviceIDHash, c.DevicePassword c.StateMux.RLock()
assignedDeviceIDHash := c.AssignedDeviceIDHash
devicePassword := c.DevicePassword
c.StateMux.RUnlock()
return assignedDeviceIDHash, devicePassword
} }
func (c *SEClient) populateRequest(req *http.Request) { func (c *SEClient) populateRequest(req *http.Request) {