timenet

package
v0.0.0-...-eb47e43 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2015 License: BSD-2-Clause-Views Imports: 5 Imported by: 0

README

timenet

A simple timing network where all nodes randomly contact each other to synchronize their times.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

type Peer interface {
	ActualTime() (time time.Time)
}

type PeerProducer

type PeerProducer interface {
	Peers() map[string]Peer
}

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

Timer is an abstract time synchronization structure that needs a PeerProducer to provide it with peers from a set of other Timers. It will randomly contact the Peers produced by the PeerProducer to synchronize its time with other peers in the network.

It calculates deviation from _normal_ network latency, and only uses time measurements that respond within standard deviation from the normal response times when adjusting its timer.

func NewTimer

func NewTimer(producer PeerProducer) *Timer

func (*Timer) ActualTime

func (self *Timer) ActualTime() time.Time

ActualTime will return what time this Timer thinks it is. It may change forwards or backwards non continuously depending on network interactions.

func (*Timer) Conform

func (self *Timer) Conform(peer Peer)

Conform will adjust this Timer to be as exactly as possible that of the provided peer.

func (*Timer) ContinuousTime

func (self *Timer) ContinuousTime() (result int64)

ContinuousTime will return a continous nice version of the time this Timer thinks it is. It us guaranteed to never move backwards, and to only move forwards in a smooth fashion.

func (*Timer) Error

func (self *Timer) Error() (err time.Duration)

Error returns the deviation of the error of this Timer.

func (*Timer) Run

func (self *Timer) Run()

Run will make this Timer regularly Sample.

func (*Timer) Sample

func (self *Timer) Sample()

Sample will make this Timer sample a random Peer produced by the PeerProducer, and Skew according to the delta with the time of that Peer.

func (*Timer) Skew

func (self *Timer) Skew(delta time.Duration)

Skew will change the actual time of this timer with delta, adjusting the continuous time in a smooth fashion.

func (*Timer) Stability

func (self *Timer) Stability() (result time.Duration)

Stability returns the deviation of the latency between this Timer and its peers.

func (*Timer) Start

func (self *Timer) Start()

Start will start a goroutine Running this Timer.

func (*Timer) Stop

func (self *Timer) Stop()

Stop will permanently stop this Timer.

Jump to

Keyboard shortcuts

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