iplist

package
v1.15.1-0...-8913225 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package iplist handles the P2P Plaintext Format described by https://en.wikipedia.org/wiki/PeerGuardian#P2P_plaintext_format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IPNetLast

func IPNetLast(in *net.IPNet) (last net.IP)

Returns the last, inclusive IP in a net.IPNet.

func MMapPackedFile

func MMapPackedFile(filename string) (
	ret interface {
		Ranger
		io.Closer
	},
	err error,
)

Types

type IPList

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

func New

func New(initSorted []Range) *IPList

Create a new IP list. The given ranges must already sorted by the lower bound IP in each range. Behaviour is undefined for lists of overlapping ranges.

func NewFromReader

func NewFromReader(f io.Reader) (ret *IPList, err error)

Creates an IPList from a line-delimited P2P Plaintext file.

func (*IPList) Lookup

func (ipl *IPList) Lookup(ip net.IP) (r Range, ok bool)

Return the range the given IP is in. ok if false if no range is found.

func (*IPList) NumRanges

func (ipl *IPList) NumRanges() int

func (*IPList) WritePacked

func (ipl *IPList) WritePacked(w io.Writer) (err error)

type PackedIPList

type PackedIPList []byte

func NewFromPacked

func NewFromPacked(b []byte) PackedIPList

func (PackedIPList) Lookup

func (pil PackedIPList) Lookup(ip net.IP) (r Range, ok bool)

func (PackedIPList) NumRanges

func (pil PackedIPList) NumRanges() int

type Range

type Range struct {
	First, Last net.IP
	Description string
}

func ParseBlocklistP2PLine

func ParseBlocklistP2PLine(l []byte) (r Range, ok bool, err error)

Parse a line of the PeerGuardian Text Lists (P2P) Format. Returns !ok but no error if a line doesn't contain a range but isn't erroneous, such as comment and blank lines.

func ParseCIDRListReader

func ParseCIDRListReader(r io.Reader) (ret []Range, err error)

func (Range) String

func (r Range) String() string

type Ranger

type Ranger interface {
	// Return a Range containing the IP.
	Lookup(net.IP) (r Range, ok bool)
	// If your ranges hurt, use this.
	NumRanges() int
}

An abstraction of IP list implementations.

Directories

Path Synopsis
cmd
pack-blocklist
Takes P2P blocklist text format in stdin, and outputs the packed format from the iplist package.
Takes P2P blocklist text format in stdin, and outputs the packed format from the iplist package.

Jump to

Keyboard shortcuts

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