client

package
v0.0.0-...-064fa60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

This package defines some functionalities useful for building Roughtime clients. It's based on Google's original Go implementation of Roughtime. For more information, visit https://roughtime.googlesource.com/roughtime.

Index

Constants

View Source
const (
	DefaultQueryAttempts = 3
	DefaultQueryTimeout  = time.Second
)

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(configFile string) (servers []config.Server, skipped int, err error)

LoadConfig reads and parses a JSON-encoded string from configFile.

func MedianDeltaWithRadiusThresh

func MedianDeltaWithRadiusThresh(results []Result, t0 time.Time, thresh time.Duration) (time.Duration, error)

MedianDeltaWithRadiusThresh computes the median difference between t0 and the time reported by each server, rejecting responses whose uncertainty radii aren't within the accepted limit.

func ParseConfig

func ParseConfig(jsonData []byte) (servers []config.Server, skipped int, err error)

ParseConfig loads parses a JSON-encoded Roughtime-server configuration, skipping those servers that the client doesn't support. It returns the sequenc of servers with valid configurations, as well as the number of configurations it skipped.

If the server's address is a domain name, the client will attempt to resolve it. At the moment, the client only supports servers with an Ed25519 root public key and who are listening on UDP.

func SetLogger

func SetLogger(l *log.Logger)

SetLogger sets the logger used to log the output of Do and DoFromFile. If l == nil, then no output will be logged.

Types

type Chain

type Chain struct {
	*Roughtime
	// The server who signed the response.
	Server *config.Server
	// The next query in the chain.
	Next *Chain
}

Chain represents a sequence of ordered Roughtime queries.

func NewChain

func NewChain(results []Result) *Chain

NewChain returns a Roughtime chain comprised of the successful queries in a sequence of results.

func (*Chain) Verify

func (chain *Chain) Verify(prev *Roughtime) (bool, error)

Verify returns true if the chain is valid. A chain is valid if for each link in the chain, (1) the signature in the server's response is valid, and (2) the response was used to generate the nonce in the next link's request.

If prev != nil, then prev.Resp is used to compute the nonce for the first request in the chain.

type Result

type Result struct {
	*Roughtime
	// The configuration of the server used for the query.
	Server *config.Server
	// The network delay incurred by the query.
	Delay time.Duration
	// contains filtered or unexported fields
}

Result stores the request and response of a Roughtime query to a server. It is either a server's time or an error.

func Do

func Do(servers []config.Server, attempts int, timeout time.Duration, prev *Roughtime) []Result

Do requests Roughtime from a sequence of servers in order. If the request fails, then the error is recorded. The nonce of each request is computed from the response of the last, skipping requests that fail.

func DoFromFile

func DoFromFile(configFile string, attempts int, timeout time.Duration, prev *Roughtime) ([]Result, error)

DoFromFile loads a sequence of server configurations from configFile and requests Roughtime from them in order.

func (*Result) Error

func (r *Result) Error() error

Error returns the error resulting from the query, if any.

type Roughtime

type Roughtime struct {
	// The request and the blind used to generate the nonce of the request.
	Req, Blind []byte
	// The bytes of the response.
	Resp []byte
	// The time reported by the server.
	Midpoint time.Time
	// The "uncertainty radius" of the server's reported time. It indicates
	// that the server is "reasonably sure" that the real is within this number
	// of microseconds of the real time.
	Radius time.Duration
}

Roughtime stores the result of a successful Roughtime query.

func Get

func Get(server *config.Server, attempts int, timeout time.Duration, prev *Roughtime) (*Roughtime, error)

Get sends a request to a server and verifies the response. It makes at most as many attempts as specified, waiting for the given amount of time for each reply. It uses prev to generate the nonce of the request. This may be nil, in which case the request is the first in the chain.

func (*Roughtime) Now

func (rt *Roughtime) Now() (time.Time, time.Duration)

Now returns the time provided by a Roughtime response.

func (*Roughtime) String

func (rt *Roughtime) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL