network

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMultipleAddresses is returned when the mirror has more than one address
	ErrMultipleAddresses = errors.New("the mirror has more than one IP address")
)

Functions

func ExtractRemoteIP

func ExtractRemoteIP(XForwardedFor string) string

ExtractRemoteIP extracts the remote IP from an X-Forwarded-For header

func LookupMirrorIP

func LookupMirrorIP(host string) (string, error)

LookupMirrorIP returns the IP address of a mirror and returns an error if the DNS has more than one address

func RemoteIPFromAddr

func RemoteIPFromAddr(remoteAddr string) string

RemoteIPFromAddr removes the port from a remote address (x.x.x.x:yyyy)

Types

type ClusterLock

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

ClusterLock holds the internal structure of a ClusterLock

func NewClusterLock

func NewClusterLock(redis *database.Redis, key, identifier string) *ClusterLock

NewClusterLock returns a new instance of a ClusterLock. A ClucterLock is used to maitain a lock on a mirror that is being scanned. The lock is renewed every lockRefresh seconds and is automatically released by the redis database every lockTTL seconds allowing the lock to be released even if the application is killed.

func (*ClusterLock) Get

func (n *ClusterLock) Get() (<-chan struct{}, error)

Get tries to obtain an exclusive lock, cluster wide, for the given mirror

func (*ClusterLock) Release

func (n *ClusterLock) Release()

Release releases the exclusive lock on the mirror

type GeoIP

type GeoIP struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

GeoIP contains methods to query the GeoIP database

func NewGeoIP

func NewGeoIP() *GeoIP

NewGeoIP instanciates a new instance of GeoIP

func (*GeoIP) GetRecord

func (g *GeoIP) GetRecord(ip string) (ret GeoIPRecord)

GetRecord return informations about the given ip address (works in IPv4 and v6)

func (*GeoIP) IsIPv6

func (g *GeoIP) IsIPv6(ip string) bool

IsIPv6 returns true if the given address is of version 6

func (*GeoIP) LoadGeoIP

func (g *GeoIP) LoadGeoIP() error

LoadGeoIP loads the GeoIP databases into memory

type GeoIPError

type GeoIPError struct {
	Errors []error
	// contains filtered or unexported fields
}

GeoIPError holds errors while loading the different databases

func (GeoIPError) Error

func (e GeoIPError) Error() string

func (GeoIPError) IsFatal

func (e GeoIPError) IsFatal() bool

IsFatal returns true if the error is fatal

type GeoIPRecord

type GeoIPRecord struct {
	// City DB
	CountryCode   string
	ContinentCode string
	City          string
	Country       string
	Latitude      float32
	Longitude     float32

	// ASN DB
	ASName string
	ASNum  uint
}

GeoIPRecord defines a GeoIP record for a given IP address

func (*GeoIPRecord) IsValid

func (g *GeoIPRecord) IsValid() bool

IsValid returns true if the given address is valid

type Geolocalizer

type Geolocalizer interface {
	Lookup(ipAddress net.IP, result interface{}) error
}

Geolocalizer is an interface representing a GeoIP library

Jump to

Keyboard shortcuts

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