Skip to content

Commit

Permalink
Get current nonce atomically
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed May 16, 2019
1 parent 7dd5887 commit 36efc97
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/httpauth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Client struct {
key cipher.PubKey
sec cipher.SecKey
Addr string // sanitized address of the client, which may differ from addr used in NewClient
nonce uint64
nonce uint64 // has to be handled with the atomic package at all time
}

// NewClient creates a new client setting a public key to the client to be used for Auth.
Expand Down Expand Up @@ -164,7 +164,7 @@ func (c *Client) doRequest(req *http.Request, body []byte) (*http.Response, erro
}

func (c *Client) getCurrentNonce() Nonce {
return Nonce(c.nonce)
return Nonce(atomic.LoadUint64(&c.nonce))
}

func (c *Client) incrementNonce() {
Expand Down

0 comments on commit 36efc97

Please sign in to comment.