ipdict

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	IP_SIZE     = 16 // TODO: optimize memory usage for ipv4 address
	HEADER_LEN  = 32
	MAX_LINE    = 1000000
	MAX_LOC_LEN = 1024
)
View Source
const (
	IP_LENGTH = 16
)

Variables

This section is empty.

Functions

func Hash

func Hash(ip []byte) uint64

Hash is a hash method which convert net.IP to type uint64.

Types

type IPItems

type IPItems struct {
	Version string
	// contains filtered or unexported fields
}

IPItems manage single IP(hashSet) and ipPairs

func NewIPItems

func NewIPItems(maxSingleIPNum int, maxPairIPNum int) (*IPItems, error)

NewIPItems creates new IPItems

func (*IPItems) InsertPair

func (ipItems *IPItems) InsertPair(startIP, endIP net.IP) error

InsertPair provides insert startIP,endIP into IpItems

func (*IPItems) InsertSingle

func (ipItems *IPItems) InsertSingle(ip net.IP) error

InsertSingle insert single ip into ipitems

func (*IPItems) Length

func (ipItems *IPItems) Length() int

Length return num of IPItems

func (*IPItems) Sort

func (ipItems *IPItems) Sort()

Sort provides for sorting dict according startIP by descending order

  1. Origin dict startIPStr endIPStr

------------------------ 10.26.74.55 10.26.74.255 10.12.14.2 10.12.14.50 10.21.34.5 10.23.77.100 10.23.77.88 10.23.77.240 ------------------------

  1. Sorted dict startIPStr endIPStr

------------------------ 10.26.74.55 10.26.74.255 10.23.77.88 10.23.77.240 10.21.34.5 10.23.77.100 10.12.14.2 10.12.14.50 ------------------------

  1. Merged sorted dict startIPStr endIPStr

------------------------ 10.26.74.55 10.26.74.255 10.21.34.5 10.23.77.240 10.12.14.2 10.12.14.50 0.0.0.0 0.0.0.0 ------------------------

  1. Dict after resliced startIPStr endIPStr

------------------------ 10.26.74.55 10.26.74.255 10.21.34.5 10.23.77.240 10.12.14.2 10.12.14.50 ------------------------

type IPTable

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

func NewIPTable

func NewIPTable() *IPTable

func (*IPTable) Search

func (t *IPTable) Search(srcIP net.IP) bool

Search provides for binary search IP in dict

func (*IPTable) Update

func (t *IPTable) Update(items *IPItems)

Update provides for thread-safe switching items

func (*IPTable) Version

func (t *IPTable) Version() string

type IpLocationTable

type IpLocationTable struct {
	Version string

	LocLen uint32
	// contains filtered or unexported fields
}

func NewIpLocationTable

func NewIpLocationTable(maxSize uint32, locLen uint32) (*IpLocationTable, error)

func (*IpLocationTable) Add

func (t *IpLocationTable) Add(startIP, endIP net.IP, location string) error

Add ip location dict to locations buffer assume add startIP:EndIP have been sorted every add startIP:EndIP region does not overlap

func (*IpLocationTable) Search

func (t *IpLocationTable) Search(cip net.IP) (string, error)

Search find the ip's location. search sort of array(order from small to large)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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