socket

package
v0.0.0-...-055f8da Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package socket implements signed datagram sockets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachingSealer

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

CachingSealer uses a simple LRU-cache strategy to reduce CPU load due to repeated signing. Additionally, it returns the signed bytes to a global free-list upon eviction.

func NewCachingSealer

func NewCachingSealer(pk crypto.PrivKey, size int) (*CachingSealer, error)

func NewCachingSealerFromHost

func NewCachingSealerFromHost(h host.Host, size int) (*CachingSealer, error)

func (*CachingSealer) Purge

func (c *CachingSealer) Purge()

func (*CachingSealer) Seal

func (c *CachingSealer) Seal(r record.Record) ([]byte, error)

type Hashable

type Hashable interface {
	Hash() (uint64, error)
}

Hashable is an optional interface that records MAY provide in order to override the default key-derivation function. This may be desireable when MarshalRecord() allocates heavily. Use of xxhash is RECOMMENDED.

See boot.Record for an example.

type Sealer

type Sealer interface {
	Seal(record.Record) ([]byte, error)
}

Sealer can sign and marshal a record. Implementations SHOULD cache results.

type Socket

type Socket struct {
	// Conn is a datagram-oriented connection that can read and
	// write packets.  This is most often a *net.UDPSocket, and
	// MAY be support multicast.
	Conn net.PacketConn

	// Sealer can marshal and sign a record.  Most applications
	// SHOULD use *CachingSealer.
	Sealer Sealer
}

Socket is a packet-oriented network interface that exchanges signed messages. A socket's maximum transmission unit (MTU) is exactly 2KB. Sockets will fail to unmarshal records from payloads exceeding 2 << 10 bytes. Bear in mind that payloads are automatically signed, which increases payload size. In practice, an overhead of 128 bytes is generally sufficient.

func (Socket) Close

func (s Socket) Close() error

Close the underlying PacketConn.

func (Socket) Read

func (s Socket) Read(r record.Record) (net.Addr, peer.ID, error)

Read a packet from the socket, unmarshal it, and verify its signature. Returns the address that was in the packet, and the ID of the signing peer.

func (Socket) Write

func (s Socket) Write(r record.Record, addr net.Addr) error

Write the record to the specified address.

Jump to

Keyboard shortcuts

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