go-ethereum: github.com/axiomzen/go-ethereum/p2p/netutil Index | Examples | Files

package netutil

import "github.com/axiomzen/go-ethereum/p2p/netutil"

Package netutil contains extensions to the net package.

Index

Examples

Package Files

addrutil.go error.go iptrack.go net.go toobig_notwindows.go

func AddrIP Uses

func AddrIP(addr net.Addr) net.IP

AddrIP gets the IP address contained in addr. It returns nil if no address is present.

func CheckRelayIP Uses

func CheckRelayIP(sender, addr net.IP) error

CheckRelayIP reports whether an IP relayed from the given sender IP is a valid connection target.

There are four rules:

- Special network addresses are never valid.
- Loopback addresses are OK if relayed by a loopback host.
- LAN addresses are OK if relayed by a LAN host.
- All other addresses are always acceptable.

func IsLAN Uses

func IsLAN(ip net.IP) bool

IsLAN reports whether an IP is a local network address.

func IsSpecialNetwork Uses

func IsSpecialNetwork(ip net.IP) bool

IsSpecialNetwork reports whether an IP is located in a special-use network range This includes broadcast, multicast and documentation addresses.

func IsTemporaryError Uses

func IsTemporaryError(err error) bool

IsTemporaryError checks whether the given error should be considered temporary.

func SameNet Uses

func SameNet(bits uint, ip, other net.IP) bool

SameNet reports whether two IP addresses have an equal prefix of the given bit length.

Code:

// This returns true because the IPs are in the same /24 network:
fmt.Println(SameNet(24, net.IP{127, 0, 0, 1}, net.IP{127, 0, 0, 3}))
// This call returns false:
fmt.Println(SameNet(24, net.IP{127, 3, 0, 1}, net.IP{127, 5, 0, 3}))

Output:

true
false

type DistinctNetSet Uses

type DistinctNetSet struct {
    Subnet uint // number of common prefix bits
    Limit  uint // maximum number of IPs in each subnet
    // contains filtered or unexported fields
}

DistinctNetSet tracks IPs, ensuring that at most N of them fall into the same network range.

func (*DistinctNetSet) Add Uses

func (s *DistinctNetSet) Add(ip net.IP) bool

Add adds an IP address to the set. It returns false (and doesn't add the IP) if the number of existing IPs in the defined range exceeds the limit.

func (DistinctNetSet) Contains Uses

func (s DistinctNetSet) Contains(ip net.IP) bool

Contains whether the given IP is contained in the set.

func (DistinctNetSet) Len Uses

func (s DistinctNetSet) Len() int

Len returns the number of tracked IPs.

func (*DistinctNetSet) Remove Uses

func (s *DistinctNetSet) Remove(ip net.IP)

Remove removes an IP from the set.

func (DistinctNetSet) String Uses

func (s DistinctNetSet) String() string

String implements fmt.Stringer

type IPTracker Uses

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

IPTracker predicts the external endpoint, i.e. IP address and port, of the local host based on statements made by other hosts.

func NewIPTracker Uses

func NewIPTracker(window, contactWindow time.Duration, minStatements int) *IPTracker

NewIPTracker creates an IP tracker.

The window parameters configure the amount of past network events which are kept. The minStatements parameter enforces a minimum number of statements which must be recorded before any prediction is made. Higher values for these parameters decrease 'flapping' of predictions as network conditions change. Window duration values should typically be in the range of minutes.

func (*IPTracker) AddContact Uses

func (it *IPTracker) AddContact(host string)

AddContact records that a packet containing our endpoint information has been sent to a certain host.

func (*IPTracker) AddStatement Uses

func (it *IPTracker) AddStatement(host, endpoint string)

AddStatement records that a certain host thinks our external endpoint is the one given.

func (*IPTracker) PredictEndpoint Uses

func (it *IPTracker) PredictEndpoint() string

PredictEndpoint returns the current prediction of the external endpoint.

func (*IPTracker) PredictFullConeNAT Uses

func (it *IPTracker) PredictFullConeNAT() bool

PredictFullConeNAT checks whether the local host is behind full cone NAT. It predicts by checking whether any statement has been received from a node we didn't contact before the statement was made.

type Netlist Uses

type Netlist []net.IPNet

Netlist is a list of IP networks.

func ParseNetlist Uses

func ParseNetlist(s string) (*Netlist, error)

ParseNetlist parses a comma-separated list of CIDR masks. Whitespace and extra commas are ignored.

func (*Netlist) Add Uses

func (l *Netlist) Add(cidr string)

Add parses a CIDR mask and appends it to the list. It panics for invalid masks and is intended to be used for setting up static lists.

func (*Netlist) Contains Uses

func (l *Netlist) Contains(ip net.IP) bool

Contains reports whether the given IP is contained in the list.

func (Netlist) MarshalTOML Uses

func (l Netlist) MarshalTOML() interface{}

MarshalTOML implements toml.MarshalerRec.

func (*Netlist) UnmarshalTOML Uses

func (l *Netlist) UnmarshalTOML(fn func(interface{}) error) error

UnmarshalTOML implements toml.UnmarshalerRec.

Package netutil imports 8 packages (graph). Updated 2019-07-06. Refresh now. Tools for package owners.