Version: v0.2.0 Latest Latest

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

Go to latest
Published: Oct 21, 2019 License: Apache-2.0 Imports: 7 Imported by: 0




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


This section is empty.


func Hash

func Hash(ip []byte) uint64

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


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

------------------------ ------------------------

  1. Sorted dict startIPStr endIPStr

------------------------ ------------------------

  1. Merged sorted dict startIPStr endIPStr

------------------------ ------------------------

  1. Dict after resliced startIPStr endIPStr

------------------------ ------------------------

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)


Path Synopsis

Jump to

Keyboard shortcuts

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