types

package
v0.0.0-...-4449afe Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package types is a super-package that contains all library code that toversok would need to interact with. Such as data layer parsing, higher-level types such as relay information, and more.

This package exists to avoid import cycles, and to clean up all misc/"leaf" functions and types into one hierarchy.

As a general rule to avoid import cycles inside this package:

  • Only import parent packages, don't import child packages
  • Importing from a "sibling" package (up the tree) is allowed.

Index

Constants

View Source
const LevelTrace slog.Level = -8

Variables

This section is empty.

Functions

func IsContextDone

func IsContextDone(ctx context.Context) bool

IsContextDone does a quick check on a context to see if its dead.

func Map

func Map[T, U any](ts []T, f func(T) U) []U

Map is a generic slice mapping function taken from https://stackoverflow.com/a/71624929/8700553, since golang loves to not give its developers any usable tools.

func NormaliseAddr

func NormaliseAddr(addr netip.Addr) netip.Addr

func NormaliseAddrPort

func NormaliseAddrPort(ap netip.AddrPort) netip.AddrPort

func NormaliseAddrPortSlice

func NormaliseAddrPortSlice(s []netip.AddrPort) []netip.AddrPort

func NormaliseAddrSlice

func NormaliseAddrSlice(s []netip.Addr) []netip.Addr

func ParseAddrPort

func ParseAddrPort(b [18]byte) netip.AddrPort

func PrettyAddrPortSlice

func PrettyAddrPortSlice(s []netip.AddrPort) string

func PtrOr

func PtrOr[T any](v *T, def T) T

func PutAddrPort

func PutAddrPort(ap netip.AddrPort) []byte

func RandStringBytesMaskImprSrc

func RandStringBytesMaskImprSrc(n int) string

RandStringBytesMaskImprSrc returns a random hexadecimal string of length n.

func ReadUint32

func ReadUint32(reader *bufio.Reader) (uint32, error)

ReadUint32 reads an uint32 in big-endian order to the reader

func SetSubtraction

func SetSubtraction[T comparable](a, b []T) []T

SetSubtraction returns the elements in `a` that aren't in `b`.

in set notation: a - b

func SetUnion

func SetUnion[T comparable](a, b []T) []T

SetUnion returns a set of elements that were either in a and b in set notation: a u b

func SliceOrEmpty

func SliceOrEmpty[T any](v []T) []T

func SliceOrNil

func SliceOrNil[T any](v []T) []T

func WriteUint32

func WriteUint32(writer *bufio.Writer, v uint32) error

WriteUint32 writes an uint32 in big-endian order to the writer

Types

type CCCKEY

type CCCKEY int
const CCC CCCKEY = 112

type Incomparable

type Incomparable [0]func()

Incomparable is a zero-width incomparable type. If added as the first field in a struct, it marks that struct as not comparable (can't do == or be a map key) and usually doesn't add any width to the struct (unless the struct has only small fields).

Be making a struct incomparable, you can prevent misuse (prevent people from using ==), but also you can shrink generated binaries, as the compiler can omit equality funcs from the binary.

(Taken from the tailscale types library)

type LogonCallback

type LogonCallback func(url string, deviceKey chan<- string) error

type MetaConn

type MetaConn interface {
	io.Closer
	SetDeadline(time.Time) error
	SetReadDeadline(time.Time) error
	SetWriteDeadline(time.Time) error
}

type UDPConn

type UDPConn interface {
	SetReadDeadline(t time.Time) error

	ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error)

	Write(b []byte) (int, error)
	WriteToUDPAddrPort(b []byte, addr netip.AddrPort) (int, error)

	Close() error
}

UDPConn interface for actors.Stage to more easily deal with.

type UDPConnCloseCatcher

type UDPConnCloseCatcher struct {
	UDPConn

	Closed bool
}

func (*UDPConnCloseCatcher) Close

func (c *UDPConnCloseCatcher) Close() error

Directories

Path Synopsis
Package control pertains to all code related to contacting, serving, and talking to control.
Package control pertains to all code related to contacting, serving, and talking to control.
controlhttp
Package controlhttp pertains to implementing control interfaces in a HTTP client/dialer and server handler.
Package controlhttp pertains to implementing control interfaces in a HTTP client/dialer and server handler.
Package dial contains an implementation of TCP/HTTP dialing.
Package dial contains an implementation of TCP/HTTP dialing.
Package ifaces contains interface definitions commonly shared amongst code in `types`.
Package ifaces contains interface definitions commonly shared amongst code in `types`.
Package key contains Session, Node, and Control key definitions, private and public, and associated functions.
Package key contains Session, Node, and Control key definitions, private and public, and associated functions.
Package msgactor contains definitions for messages directly sent and received between actors of the toversok stage.
Package msgactor contains definitions for messages directly sent and received between actors of the toversok stage.
Package msgcontrol contains types, constants, and interfaces related to control messages.
Package msgcontrol contains types, constants, and interfaces related to control messages.
Package msgsess contains session message definitions and parsing methods, to be sent over relay or directly.
Package msgsess contains session message definitions and parsing methods, to be sent over relay or directly.
Package relay contains all code necessary to establish a connection with a relay server, create a relay server, and communicate with one.
Package relay contains all code necessary to establish a connection with a relay server, create a relay server, and communicate with one.
relayhttp
Package relayhttp contains an implementation of a relay server in HTTP.
Package relayhttp contains an implementation of a relay server in HTTP.
Package stage contains some miscellaneous types required in both toversok and types/ifaces.
Package stage contains some miscellaneous types required in both toversok and types/ifaces.
Package stun contains all the code pertaining to STUN resolution.
Package stun contains all the code pertaining to STUN resolution.

Jump to

Keyboard shortcuts

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