geoip

package
v0.0.0-...-c53eb01 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: Apache-2.0, MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_DISTANCE = 600

Variables

View Source
var CountryToContinentJSON []byte

Functions

func GetCurrentEpoch

func GetCurrentEpoch(ctx context.Context) (int64, error)

GetCurrentEpoch gets the current chain height from the Lotus API

func GetGeocodeClient

func GetGeocodeClient() (*maps.Client, error)

func LoadIPsBaidu

func LoadIPsBaidu(filepath string) (map[string]IPsBaiduRecord, error)

func LoadIPsGeolite2

func LoadIPsGeolite2(filepath string) (map[string]IPsGeolite2Record, error)

Types

type Address

type Address struct {
	StreetNumber string `json:"street_number"`
	Route        string `json:"route"`
	City         string `json:"city"`
	State        string `json:"state"`
	CityState    string `json:"city_state"`
	Country      string `json:"country"`
}

type BaiduDetail

type BaiduDetail map[string]interface{}

type FinalGeoData

type FinalGeoData struct {
	GeoData           *GeoData
	GeocodeLocations  []geodist.Coord
	GeoDataAddresses  []Address
	GoogleGeocodeData []maps.GeocodingResult
}

func GeoMatchExists

func GeoMatchExists(
	ctx context.Context,
	geodata *GeoData,
	geocodeClient *maps.Client,
	currentEpoch int64,
	miner MinerData,
) (bool, FinalGeoData, error)

GeoMatchExists checks if the miner has an IP address with a location close to the city/country

type GeoData

type GeoData struct {
	MultiaddrsIPs []MultiaddrsIPsRecord
	Ipinfo        *IPInfoResolver
	IPsGeolite2   map[string]IPsGeolite2Record
	IPsBaidu      map[string]IPsBaiduRecord
	IPsGeoIP2     map[string]geoip2.Response
}

func LoadGeoData

func LoadGeoData() (*GeoData, error)

type GeoIPCheck

type GeoIPCheck struct{}

func (*GeoIPCheck) DoCheck

type Geolite2Detail

type Geolite2Detail map[string]interface{}

type IPInfoResolver

type IPInfoResolver struct {
	Continents map[string]string
}

func NewIPInfoResolver

func NewIPInfoResolver() (*IPInfoResolver, error)

func (*IPInfoResolver) ResolveIP

func (i *IPInfoResolver) ResolveIP(ctx context.Context, ip net.IP) (map[string]IPInfoResponse, error)

func (*IPInfoResolver) ResolveIPStr

func (i *IPInfoResolver) ResolveIPStr(ctx context.Context, ip string) (string, error)

type IPInfoResponse

type IPInfoResponse struct {
	IP       string `json:"ip"`
	Hostname string `json:"hostname"`
	City     string `json:"city"`
	Region   string `json:"region"`
	Country  string `json:"country"`
	Location string `json:"loc"`
	Org      string `json:"org"`
	Postal   string `json:"postal"`
	Timezone string `json:"timezone"`
	ASN      struct {
		ASN    string `json:"asn"`
		Name   string `json:"name"`
		Domain string `json:"domain"`
		Route  string `json:"route"`
		Type   string `json:"type"`
	} `json:"asn"`
}

type IPsBaiduRecord

type IPsBaiduRecord struct {
	Epoch     uint64      `json:"epoch"`
	Timestamp string      `json:"timestamp"`
	City      string      `json:"city"`
	Long      float32     `json:"long"`
	Lat       float32     `json:"lat"`
	Baidu     BaiduDetail `json:"baidu"`
}

type IPsBaiduReport

type IPsBaiduReport struct {
	Date *string                   `json:"date"`
	IPs  map[string]IPsBaiduRecord `json:"ipsBaidu"`
}

type IPsGeolite2Record

type IPsGeolite2Record struct {
	Epoch     uint64  `json:"epoch"`
	Timestamp string  `json:"timestamp"`
	Continent string  `json:"continent"`
	Country   string  `json:"country"`
	Subdiv1   string  `json:"subdiv1"`
	City      string  `json:"city"`
	Long      float32 `json:"long"`
	Lat       float32 `json:"lat"`
	Geolite2  Geolite2Detail
}

type IPsGeolite2Report

type IPsGeolite2Report struct {
	Date *string                      `json:"date"`
	IPs  map[string]IPsGeolite2Record `json:"ipsGeolite2"`
}

type MinerData

type MinerData struct {
	MinerID     string `json:"miner_id"`
	City        string `json:"city"`
	CountryCode string `json:"country_code"`
}

type MultiaddrsIPsRecord

type MultiaddrsIPsRecord struct {
	Miner     string `json:"miner"`
	Maddr     string `json:"maddr"`
	PeerID    string `json:"peerId"`
	IP        string `json:"ip"`
	Epoch     uint   `json:"epoch"`
	Timestamp string `json:"timestamp"`
	DHT       bool   `json:"dht"`
	Chain     bool   `json:"chain"`
}

func LoadMultiAddrsIPs

func LoadMultiAddrsIPs(filepath string) ([]MultiaddrsIPsRecord, error)

type MultiaddrsIPsReport

type MultiaddrsIPsReport struct {
	Date          *string
	MultiaddrsIPs []MultiaddrsIPsRecord
}

Jump to

Keyboard shortcuts

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