Documentation ¶
Index ¶
Constants ¶
const ( HostSelectRandom = iota HostSelectRoundRobin = iota )
Host selection algorithms
Variables ¶
var ( // DefaultTimeout is the default HTTP request timeout DefaultTimeout = 30 * time.Second // DefaultKeepAlive is the default HTTP keep-alive duration DefaultKeepAlive = 30 * time.Second // RetryLimit indicates how many times a connection should be retried before failing RetryLimit = 3 // RetryDelay is the duration to wait between retry attempts RetryDelay = 1 * time.Second // ErrHostNotFound is returned if the given host does not exist ErrHostNotFound = errors.New("host not found") )
var (
// DefaultHost is the default API host
DefaultHost = "api.taplink.co"
)
var ( // HTTPClient defines the HTTP client used for HTTP connections HTTPClient = &http.Client{ Timeout: DefaultTimeout, Transport: &http.Transport{ Dial: (&net.Dialer{ Timeout: DefaultTimeout, KeepAlive: DefaultKeepAlive, }).Dial, }, } )
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { // Config Config() Configuration // API funcs VerifyPassword(hash []byte, expectedHash []byte, versionID int64) (*VerifyPassword, error) NewPassword(hash []byte) (*NewPassword, error) // Stats returns stats about each host the client has connected to Stats() Statistics }
API is an interface which exposes TapLink API functionality
type Client ¶
Client is a struct which implements the API interface
func (*Client) Config ¶
func (c *Client) Config() Configuration
Config returns the current client configuration
func (*Client) NewPassword ¶
func (c *Client) NewPassword(hash1 []byte) (*NewPassword, error)
NewPassword calculates 'salt1' and 'hash2' for a new password, using the latest data pool settings. Also returns 'versionId' for the current settings, in case data pool settings are updated in the future Inputs:
'hash1Hex' - hash of the user's password, as a hex string 'callback' - function(err, hash2Hex, versionId) o err : 'err' from request, or null if request succeeded o hash2Hex : value of 'hash2' as a hex string o versionId : version id of the current data pool settings used for this request
func (*Client) Stats ¶
func (c *Client) Stats() Statistics
Stats returns stats about connections to the server
func (*Client) VerifyPassword ¶
func (c *Client) VerifyPassword(hash []byte, expected []byte, versionID int64) (*VerifyPassword, error)
VerifyPassword verifies a password for an existing user which was stored using blind hashing. 'hash' - hash of the user's password 'expected' - expected value of hash2 'versionId' - version identifier for data pool settings to use If a new 'versionId' and 'hash2' value are returned, they can either be ignored, or both must be updated in the data store together which will cause the latest data pool settings to be used when blind hashing for this user in the future. If the versionID is 0, the default version will be used
type Config ¶
Config defines basic configuration for connecting to the API
func (*Config) Host ¶
Host returns the API server to connect to based on the available servers and the host selection algorithm
func (*Config) LastModified ¶
LastModified returns the last modification of the TapLink configuration
func (*Config) Stats ¶
func (c *Config) Stats() Statistics
Stats returns a statistics interface for enabling/disabling/managing statistics.
type Configuration ¶
type Configuration interface { AppID() string Host(attempts int) string Headers() map[string]string LastModified() time.Time Servers() []string Load() error Stats() Statistics }
Configuration defines an interface which provides configuration info for requests to the API
type Errors ¶
Errors is a map of how error codes (key) and count of those codes (value)
type HostStats ¶
type HostStats interface { Errors() Errors Requests() int Timeouts() int Latency() Latency ErrorRate() float64 Last(time.Duration) HostStats }
HostStats defines an interface which provides detailed information about the statistics related to connections to the given host.
type Latency ¶
Latency is a slice of duration of the requests.
type NewPassword ¶
NewPassword returns a new password hash and the version it was created with
func (NewPassword) String ¶
func (p NewPassword) String() string
String returns the hex-encoded value of the password hash
type Salt ¶
type Salt struct { Salt []byte // VersionID is the version ID used in the request VersionID int64 `json:"-"` // NewVersionID is the new version ID to use, if any. NewVersionID int64 `json:"vid"` // NewSalt is the new salt to use if newer data pool settings are available NewSalt []byte `json:"-"` }
Salt contains a salt for the current version, and NewSalt if a new version is available
type Statistics ¶
type Statistics interface { Enable() Disable() AddSuccess(host string, latency time.Duration) AddError(host string, code int) AddTimeout(host string) Get(host string) HostStats SetServers(servers []string) Hosts() []string }
Statistics defines an interface for getting and setting connection statistics
type VerifyPassword ¶
type VerifyPassword struct { Matched bool VersionID int64 NewVersionID int64 Hash []byte NewHash []byte }
VerifyPassword provides information about whether a password matched and related hashes
func (VerifyPassword) String ¶
func (v VerifyPassword) String() string
String returns the hex-encoded value of the password hash