geo

package
v0.11.2770-beta Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2015 License: MIT Imports: 12 Imported by: 4

Documentation

Overview

*

  • A minimalistic, memory size-savvy and fairly fast radix tree (AKA Patricia trie)
  • implementation that uses IPv4 addresses with netmasks as keys and 32-bit signed
  • integers as values. *
  • This tree is generally uses in read-only manner: there are no key removal operation
  • and the whole thing works best in pre-allocated fashion.

Index

Constants

View Source
const (
	GEO2_LOC_FILE  = "GeoLite2-Country-Locations-en.csv"
	GEO2_IPV4_FILE = "GeoLite2-Country-Blocks-IPv4.csv"
)
View Source
const (
	NOPRE   int32  = -1 /* an empty prefix pointer */
	ADRSIZE        = 32
	U32ZERO uint32 = 0
	MASK32  uint32 = 0xffffffff
)
View Source
const UseNexthopCompression = false

Variables

View Source
var (
	ROOTBRANCH uint32  = 16   // The branching factor at the root
	FILLFACT   float64 = 0.50 // The trie fill factor
)

Functions

func AtoU16

func AtoU16(a []byte) uint16

func EXTRACT

func EXTRACT(p, n, str uint32) uint32

extract n bits from str starting at position p

func EXTRACT8

func EXTRACT8(p uint32, n uint8, str uint32) uint32

func GETADR

func GETADR(node uint32) uint32

func GETBRANCH

func GETBRANCH(node uint32) uint32

func GETSKIP

func GETSKIP(node uint32) uint32

macro

func IPv4Itoa

func IPv4Itoa(i uint32) string

func ParseCIDR

func ParseCIDR(s string) (ip, m uint32)
CIDR utils

parse 10-bit cidr literal to binary ip/mask

func REMOVE

func REMOVE(p, str uint32) uint32

remove the first p bits from string

func RangeCIDR

func RangeCIDR(s string) (uint32, uint32)

func SETBRANCH

func SETBRANCH(branch uint32) uint32

func SETSKIP

func SETSKIP(skip uint32) uint32

func Serialize

func Serialize(r *routingTable) (t, b, p []byte)

Serialize routingTable{trie,base,pre} to 3-[]byte directly without copying then could make persistent data

func StoU16

func StoU16(a string) uint16

func U16toS

func U16toS(u uint16) string

Types

type GeoIPFilter

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

func NewGeoIPFilter

func NewGeoIPFilter(keyword string) (f *GeoIPFilter, e error)

func (*GeoIPFilter) Filter

func (f *GeoIPFilter) Filter(host string) bool

type GeoLite2Reader

type GeoLite2Reader struct {
	CountryCode  map[int]string
	Count        int
	RelativePath string
}

func (*GeoLite2Reader) Iter

func (r *GeoLite2Reader) Iter(callback func(fields []string)) (e error)

func (*GeoLite2Reader) ReadEntries

func (r *GeoLite2Reader) ReadEntries() (entries entrySet, e error)

for testing, update-geodb

func (*GeoLite2Reader) ReadToRoutingTable

func (r *GeoLite2Reader) ReadToRoutingTable() *routingTable

for update-geodb

Jump to

Keyboard shortcuts

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