Documentation ¶
Overview ¶
package util provides common utility functions for networking.
Index ¶
- func AssignMulticastGroup(keys ...crypto.PublicKey) netip.Prefix
- func AssignToPrefix(prefix netip.Prefix, publicKey crypto.PublicKey) netip.Prefix
- func GenerateULA() (netip.Prefix, error)
- func GenerateULAWithKey(key crypto.PublicKey) (netip.Prefix, netip.Addr)
- func GenerateULAWithSeed(psk []byte) netip.Prefix
- func ParsePortRange(s string) (start int, end int, err error)
- func Ping(ctx context.Context, addr netip.Addr) error
- func RandomAddress(prefix netip.Prefix) netip.Addr
- func ResolveTCPAddr(ctx context.Context, lookup string, maxRetries int) (net.Addr, error)
- func VerifyChainOnly(rawCerts [][]byte, _ [][]*x509.Certificate) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignMulticastGroup ¶
AssignMulticastGroup assigns a multicast group to two or more public keys.
func AssignToPrefix ¶
AssignToPrefix assigns a /112 prefix within a /32 prefix using a public key. It does not check that the given prefix is a valid /32 prefix.
func GenerateULA ¶
GenerateULA generates a unique local address with a /32 prefix according to RFC 4193. The network is returned as a netip.Prefix.
func GenerateULAWithKey ¶
GenerateULAWithKey generates a unique local address with a /32 prefix using the key bytes as a seed. The network is returned as a netip.Prefix. It then computes another /112 prefix for the given public key's wireguard key. It returns the /112 prefix as the first /128 address within it.
func GenerateULAWithSeed ¶
GenerateULAWithSeed generates a unique local address with a /32 prefix using a seed value. The network is returned as a netip.Prefix.
func ParsePortRange ¶
ParsePortRange parses a port range string.
func Ping ¶
Ping sends ICMP echo requests to the given address. The context must have a timeout set and is used for the duration of the ping. The function returns an error if no replies were received.
func RandomAddress ¶
RandomAddress returns a random /128 address within a /112 prefix. This is typically used for picking local dialing addresses, but can also be used to assign relay addresses. The function does not check that the prefix is a valid /112 prefix. Addresses are not guaranteed to be unique.
func ResolveTCPAddr ¶
ResolveTCPAddr resolves a TCP address with retries and context.
func VerifyChainOnly ¶
func VerifyChainOnly(rawCerts [][]byte, _ [][]*x509.Certificate) error
VerifyChainOnly is a function that can be used in a TLS configuration to only verify that the certificate chain is valid.
Types ¶
This section is empty.