simpleclient

package
v0.0.0-...-b0fe11f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

simpleclient

Basic PTPv2.1 two-step unicast client implementation.

How to re-generate mocks

mockgen -source=client.go -destination conn_mock_test.go -package simpleclient

and then update the license header

Documentation

Overview

Package simpleclient provides very simplistic PTPv2 unicast client. It's not meant to be used in any project aiming to precisely sync time with it.

It's original purpose is to debug communication with PTP servers and illustrate protocol itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a very simplified PTPv2 unicast client. Whenever it has all the data to calculate offset/delay/etc it will call provided callback function with `MeasurementResult`.

func New

func New(cfg *Config, callback func(*MeasurementResult)) *Client

New initializes new PTPv2 unicast client

func (*Client) Close

func (c *Client) Close()

Close connections

func (*Client) Run

func (c *Client) Run() error

Run is the main function, it makes client talk to server provided in config

type Config

type Config struct {
	// address of a server to talk to
	Address string
	// interface name that we'll use to send/receive packets
	Iface string
	// timeout of whole session
	Timeout time.Duration
	// for how long we'll request unicast transmission from server
	Duration time.Duration
	// what type of typestamping to use
	Timestamping timestamp.Timestamp
}

Config specifies Client run options

type MeasurementResult

type MeasurementResult struct {
	Delay              time.Duration
	Offset             time.Duration
	ServerToClientDiff time.Duration
	ClientToServerDiff time.Duration
	Timestamp          time.Time
}

MeasurementResult is a single measured datapoint

type UDPConn

type UDPConn interface {
	ReadFromUDP(b []byte) (int, *net.UDPAddr, error)
	WriteTo(b []byte, addr net.Addr) (int, error)
	Close() error
}

UDPConn describes what functionality we expect from UDP connection

type UDPConnWithTS

type UDPConnWithTS interface {
	UDPConn
	WriteToWithTS(b []byte, addr net.Addr) (int, time.Time, error)
}

UDPConnWithTS describes what functionality we expect from UDP connection that allows us to read TX timestamps

Jump to

Keyboard shortcuts

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