netlist

package
v4.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSorted   = errors.New("list is not sorted")
	ErrInvalidAddr = errors.New("addr is invalid")
)

Functions

func Load

func Load(l *List, ip string) error

Load loads data from entry. If entry begin with "ext:", Load loads the file by using LoadFromFile. Else it loads the entry as a text pattern by using LoadFromText.

func LoadFromReader

func LoadFromReader(l *List, reader io.Reader) error

LoadFromReader loads IP list from a reader. It might modify the List and causes List unsorted.

func LoadFromText

func LoadFromText(l *List, s string) error

LoadFromText loads an IP from s. It might modify the List and causes List unsorted.

func LoadFromV2CIDR

func LoadFromV2CIDR(l *List, cidr []*v2data.CIDR) error

LoadFromV2CIDR loads ip from v2ray CIDR. It might modify the List and causes List unsorted.

func LoadGeoIPListFromDAT

func LoadGeoIPListFromDAT(b []byte) (*v2data.GeoIPList, error)

Types

type DynamicMatcher

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

func NewDynamicMatcher

func NewDynamicMatcher(parseFunc func(in []byte) (*List, error)) *DynamicMatcher

func (*DynamicMatcher) Len

func (d *DynamicMatcher) Len() int

func (*DynamicMatcher) Match

func (d *DynamicMatcher) Match(addr netip.Addr) (bool, error)

func (*DynamicMatcher) Update

func (d *DynamicMatcher) Update(newData []byte) error

type List

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

List is a list of netip.Prefix. It stores all netip.Prefix in one single slice and use binary search. It is suitable for large static cidr search.

func NewList

func NewList() *List

NewList returns a *List.

func NewV2rayIPDat

func NewV2rayIPDat(v *v2data.GeoIPList, args string) (*List, error)

NewV2rayIPDat builds a List from given v and args. The format of args is "tag1,tag2,...". Only lists that are matched by given tags will be loaded to List.

func ParseV2rayIPDat

func ParseV2rayIPDat(in []byte, args string) (*List, error)

func (*List) Append

func (list *List) Append(newNet ...netip.Prefix)

Append appends new netip.Prefix(s) to the list. This modified the list. Caller must call List.Sort() before calling List.Contains()

func (*List) Contains

func (list *List) Contains(addr netip.Addr) (bool, error)

Contains reports whether the list includes the given netip.Addr.

func (*List) Len

func (list *List) Len() int

Len implements sort Interface.

func (*List) Less

func (list *List) Less(i, j int) bool

Less implements sort Interface.

func (*List) Match

func (list *List) Match(addr netip.Addr) (bool, error)

func (*List) Sort

func (list *List) Sort()

Sort sorts the list, this must be called after list being modified and before calling List.Contains().

func (*List) Swap

func (list *List) Swap(i, j int)

Swap implements sort Interface.

type Matcher

type Matcher interface {
	Match(addr netip.Addr) (bool, error)
	Len() int
}

type MatcherGroup

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

func BatchLoadProvider

func BatchLoadProvider(e []string, dm *data_provider.DataManager) (*MatcherGroup, error)

BatchLoadProvider is a helper func to load multiple files using Load.

func (*MatcherGroup) Len

func (m *MatcherGroup) Len() int

func (*MatcherGroup) Match

func (m *MatcherGroup) Match(addr netip.Addr) (bool, error)

Jump to

Keyboard shortcuts

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