net

package
v0.0.0-...-31c1c1e Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package net provides convenience types around types from the golang/net package.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPortrangerProvided = errors.New("no portranger provided")

Functions

func AnonymizeIPString

func AnonymizeIPString(ipAddress string) (string, error)

func AnonymizeIPv4

func AnonymizeIPv4(ip net.IP) net.IP

IPv4 anonymizes an IPv4 address by zeroing it's host part.

func AnonymizeIPv6

func AnonymizeIPv6(ip net.IP) net.IP

IPv6 anonymizes an IPv4 address by zeroing it's host part.

Types

type IPLimiter

type IPLimiter interface {
	// Tests whether the IP is allowed in respect to the underlying implementation
	IsAllowed(ip string) bool
}

The IPLimiter interface allows to check whether a certain IP is allowed.

func NewIPLimiter

func NewIPLimiter(blocklist, allowlist []string) (IPLimiter, error)

NewIPLimiter creates a new IPLimiter with the given IP ranges for the allowed and blocked IPs. Empty strings are ignored. Returns an error if an invalid IP range has been found.

func NewNullIPLimiter

func NewNullIPLimiter() IPLimiter

type Portranger

type Portranger interface {
	// Get a new port from the pool. The port is from the range as providied at initialization.
	// If no more ports are available a negative port is returned and error is not nil.
	Get() (int, error)

	// Put a port back in the pool. It will be silently ignored if a port has already been returned back
	// to the pool or if the returned port is not in the range.
	Put(int)
}

The Portranger interface allows to get an available port from a pool and to put it back after use for later re-use.

func NewDummyPortrange

func NewDummyPortrange() Portranger

func NewPortrange

func NewPortrange(min, max int) (Portranger, error)

NewPortrange returns a new instance of a Portranger implementation. A minimal and maximal port number have to be provided for a valid port range. If the provided port range is invalid, nil and an error is retuned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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