disco

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Disco

type Disco interface {
	AddPeer(pubKey wgkey.DiscoPublicKey) DiscoPeer
	SetPeers(peers map[wgkey.DiscoPublicKey][]netip.AddrPort)
	GetAllStatuses() (res map[wgkey.DiscoPublicKey]DiscoPeerStatusReadOnly)
	Send(pkt *EncryptedDiscoPacket)
	SetStatusCallback(fn func(pubKey wgkey.DiscoPublicKey, status DiscoPeerStatusReadOnly))
	Close() error
}

func New

func New(
	privateKey wgkey.DiscoPrivateKey,
	packetConn types.PacketConn,
	logger *zap.Logger,
	newPeer NewDiscoPeerFunc,
	newEndpoint NewDiscoPeerEndpointFunc,
) Disco

func NewFromPacketConn

func NewFromPacketConn(
	privateKey wgkey.DiscoPrivateKey,
	packetConn types.PacketConn,
	logger *zap.Logger,
) Disco

func NewListen

func NewListen(privateKey wgkey.DiscoPrivateKey, port int, logger *zap.Logger) (Disco, error)

type DiscoPacket

type DiscoPacket struct {
	Header            DiscoPacketHeader
	SrcPublicDiscoKey [32]byte
	EndpointID        uint32
	ID                uint32

	Endpoint  netip.AddrPort
	SharedKey wgkey.DiscoSharedKey
}

func (*DiscoPacket) Decrypt

func (d *DiscoPacket) Decrypt(encrypted *EncryptedDiscoPacket) bool

func (*DiscoPacket) Encrypt

func (d *DiscoPacket) Encrypt() (*EncryptedDiscoPacket, bool)

type DiscoPacketHeader

type DiscoPacketHeader byte
const (
	PingMessage DiscoPacketHeader = 128 + iota
	PongMessage
)

func (DiscoPacketHeader) String

func (d DiscoPacketHeader) String() string

type DiscoPeer

type DiscoPeer interface {
	EnqueueReceivedPacket(pkt EncryptedDiscoPacket)
	SetEndpoints(endpoints []netip.AddrPort)
	Status() DiscoPeerStatus
	Close() error
}

func NewDiscoPeer

func NewDiscoPeer(
	d Sender,
	privateKey wgkey.DiscoPrivateKey,
	pubKey wgkey.DiscoPublicKey,
	onClose func(),
	logger *zap.Logger,
	newEndpoint NewDiscoPeerEndpointFunc,
) DiscoPeer

type DiscoPeerEndpoint

type DiscoPeerEndpoint interface {
	Endpoint() netip.AddrPort
	Status() DiscoPeerEndpointStatus
	SetPriority(priority ticker.Priority)
	EnqueueReceivedPacket(pkt DiscoPacket)
	ReceivePing()
	Close() error
}

func NewDiscoPeerEndpoint

func NewDiscoPeerEndpoint(
	endpointID uint32,
	endpoint netip.AddrPort,
	localPubKey wgkey.DiscoPublicKey,
	sharedKey wgkey.DiscoSharedKey,
	sender Sender,
	logger *zap.Logger,
) DiscoPeerEndpoint

type DiscoPeerEndpointStatus

type DiscoPeerEndpointStatus interface {
	Get() DiscoPeerEndpointStatusReadOnly
	NotifyStatus(fn func(status DiscoPeerEndpointStatusReadOnly))
}

type DiscoPeerEndpointStatusReadOnly

type DiscoPeerEndpointStatusReadOnly struct {
	State ticker.State
	RTT   time.Duration
}

type DiscoPeerStatus

type DiscoPeerStatus interface {
	Get() DiscoPeerStatusReadOnly
	NotifyStatus(fn func(status DiscoPeerStatusReadOnly))
}

type DiscoPeerStatusReadOnly

type DiscoPeerStatusReadOnly struct {
	ActiveEndpoint netip.AddrPort
	ActiveRTT      time.Duration
}

type EncryptedDiscoPacket

type EncryptedDiscoPacket struct {
	Header            DiscoPacketHeader
	SrcPublicDiscoKey wgkey.DiscoPublicKey
	EncryptedPayload  []byte

	Endpoint netip.AddrPort
}

func (*EncryptedDiscoPacket) Marshal

func (d *EncryptedDiscoPacket) Marshal() ([]byte, bool)

func (*EncryptedDiscoPacket) Unmarshal

func (d *EncryptedDiscoPacket) Unmarshal(b []byte) bool

type NewDiscoPeerEndpointFunc

type NewDiscoPeerEndpointFunc func(
	endpointID uint32,
	endpoint netip.AddrPort,
	peerPubKey wgkey.DiscoPublicKey,
	sharedKey wgkey.DiscoSharedKey,
	sender Sender,
	logger *zap.Logger,
) DiscoPeerEndpoint

type NewDiscoPeerFunc

type NewDiscoPeerFunc func(
	d Sender,
	privateKey wgkey.DiscoPrivateKey,
	pubKey wgkey.DiscoPublicKey,
	onClose func(),
	logger *zap.Logger,
	newEndpoint NewDiscoPeerEndpointFunc,
) DiscoPeer

type Sender

type Sender interface {
	Send(pkt *EncryptedDiscoPacket)
}

Directories

Path Synopsis
Package mock_disco is a generated GoMock package.
Package mock_disco is a generated GoMock package.
mock
Package mock_discotests is a generated GoMock package.
Package mock_discotests is a generated GoMock package.

Jump to

Keyboard shortcuts

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