crawl

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: 16 Imported by: 0

Documentation

Index

Constants

View Source
const P_CIDR = 103

Variables

View Source
var (
	// ErrCIDROverflow is returned when a CIDR block is too large.
	ErrCIDROverflow = errors.New("CIDR overflow")
)

Functions

This section is empty.

Types

type CIDR

type CIDR struct {
	Port int
	Net  *net.IPNet
	// contains filtered or unexported fields
}

The CIDR crawl-strategy iterates through a subnet in pseudorandom order, skipping over the network and broadcast addresses, issuing requests to a fixed port.

Note that /32 subnets for IPv4 and /128 subnets for IPv6 are not supported, and will result in no-ops due to the aforementioned address-skipping behavior.

This is the recommended strategy for hosting environments without IP Multicast support.

func (*CIDR) Next

func (c *CIDR) Next(addr net.Addr) bool

Next updates addr with the next IP in the CIDR block traversal, and the target port. The supplied Addr MUST be a non-nil *net.UDPAddr or *net.TCPAddr. If addr.IP == nil, it is automatically populated. Note that a call to Next MAY use addr.IP as scratch space, even if the call to Next returns false. When Next returns false, the CIDR iteration has been exhausted.

func (*CIDR) Reset

func (c *CIDR) Reset()

Reset internal state, allowing p to be reused. Does not affect subnet or port.

type Crawler

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

func New

func New(h host.Host, conn net.PacketConn, s Strategy, opt ...socket.Option) *Crawler

func (*Crawler) Advertise

func (c *Crawler) Advertise(_ context.Context, ns string, opt ...discovery.Option) (ttl time.Duration, err error)

func (*Crawler) Close

func (c *Crawler) Close() error

func (*Crawler) FindPeers

func (c *Crawler) FindPeers(ctx context.Context, ns string, opt ...discovery.Option) (<-chan peer.AddrInfo, error)

type PortRange

type PortRange struct {
	IP        net.IP
	Low, High uint16
	// contains filtered or unexported fields
}

PortRange iterates through ports on the specified IP, in order, from Low to High.

If len(ip) == 0, it defaults to 127.0.0.1.

If Low = High = 0, the port-range defaults to match all non- reserved ports, i.e. all ports in the range (1024, 65535).

func (*PortRange) Next

func (p *PortRange) Next(addr net.Addr) (ok bool)

func (*PortRange) Reset

func (p *PortRange) Reset()

Reset internal state, allowing p to be reused. Does not affect IP or port range.

type Range

type Range interface {
	Next(a net.Addr) bool
}

type Strategy

type Strategy func() (Range, error)

func NewCIDR

func NewCIDR(cidr string, port int) Strategy

NewCIDR returns a range that iterates through a block of IP addreses in pseudorandom order, with a fixed port.

func NewPortRange

func NewPortRange(ip net.IP, low, high int) Strategy

NewPortRange returns a PortRange from low to high on the supplied IP address. If Low = High = 0, the range defaults to match all non-reserved ports. See PortRange.

func ParseCIDR

func ParseCIDR(maddr ma.Multiaddr) (Strategy, error)

type TranscoderCIDR

type TranscoderCIDR struct{}

TranscoderCIDR decodes a uint8 CIDR block

func (TranscoderCIDR) BytesToString

func (ct TranscoderCIDR) BytesToString(b []byte) (string, error)

func (TranscoderCIDR) StringToBytes

func (ct TranscoderCIDR) StringToBytes(cidrBlock string) ([]byte, error)

func (TranscoderCIDR) ValidateBytes

func (ct TranscoderCIDR) ValidateBytes(b []byte) error

Jump to

Keyboard shortcuts

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