analysis

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HEIGHT   = 512
	WIDTH    = 1024
	Y_MIN    = -130.0
	Y_MAX    = -70.0
	DOT_SIZE = 3
	SNR_MIN  = -20.0
	SNR_MAX  = 16.0
)
View Source
const (
	/*
		HOTSPOT_URL    = "https://helium-api.stakejoy.com/v1/hotspots/%s"
		HOTSPOTS_URL   = "https://helium-api.stakejoy.com/v1/hotspots"
		HEIGHT_URL     = "https://helium-api.stakejoy.com/v1/blocks/height"
		CHALLENGE_URL  = "https://helium-api.stakejoy.com/v1/hotspots/%s/challenges"
	*/
	HOTSPOT_URL    = "https://api.helium.io/v1/hotspots/%s"
	HOTSPOTS_URL   = "https://api.helium.io/v1/hotspots"
	HEIGHT_URL     = "https://api.helium.io/v1/blocks/height"
	CHALLENGE_URL  = "https://api.helium.io/v1/hotspots/%s/challenges"
	RETRY_ATTEMPTS = 10
)
View Source
const (
	HOTSPOT_CACHE_TIMEOUT = 86400 // one day
	HOTSPOT_CACHE_FILE    = "hotspots.json"
)
View Source
const TIME_FORMAT = "2006-01-02 15:04:05 MST"

Variables

View Source
var CHALLENGES_BUCKET []byte = []byte("challenges")
View Source
var DB_VERSION []byte = []byte("v1")
View Source
var HOTSPOTS_BUCKET []byte = []byte("hotspots")

"constants" in go are awesome

View Source
var HOTSPOTS_CACHE_KEY []byte = []byte("hotspotcache")
View Source
var HOTSPOT_CACHE map[string]Hotspot = map[string]Hotspot{}
View Source
var HOTSPOT_NAMES_BUCKET []byte = []byte("hotspot_names")
View Source
var META_BUCKET []byte = []byte("metadata")
View Source
var SnrTable = map[int]int{
	16:  -90,
	14:  -90,
	13:  -90,
	15:  -90,
	12:  -90,
	11:  -90,
	10:  -90,
	9:   -95,
	8:   -105,
	7:   -108,
	6:   -113,
	5:   -115,
	4:   -115,
	3:   -115,
	2:   -117,
	1:   -120,
	0:   -125,
	-1:  -125,
	-2:  -125,
	-3:  -125,
	-4:  -125,
	-5:  -125,
	-6:  -124,
	-7:  -123,
	-8:  -125,
	-9:  -125,
	-10: -125,
	-11: -125,
	-12: -125,
	-13: -125,
	-14: -125,
	-15: -124,
	-16: -123,
	-17: -123,
	-18: -123,
	-19: -123,
	-20: -123,
}

Table is map[SNR] = minimum valid RSSI Stolen from: https://github.com/Carniverous19/helium_analysis_tools.git

View Source
var VERSION_KEY []byte = []byte("version")

Functions

func ChallengeBucket added in v0.9.0

func ChallengeBucket(tx *bolt.Tx, address string) (*bolt.Bucket, error)

returns the challenge bucket for a hotspot address

func GetCurrentHeight added in v0.9.0

func GetCurrentHeight() (int64, error)

Gets the current height of the blockchain

func GetHotspotAddress

func GetHotspotAddress(name string) (string, error)

func GetHotspotName

func GetHotspotName(address string) (string, error)

func GetListOfAddresses

func GetListOfAddresses(challenges []Challenges) ([]string, error)

get a unique list of addresses in all the challenges

func MergeTwoSeries

func MergeTwoSeries(ax, ay, bx, by []float64) ([]float64, []float64)

used to merge the valid & invalid RX/TX data into a single series

func NewRestyClient added in v0.9.2

func NewRestyClient() *resty.Client

func XValueFormatter

func XValueFormatter(v interface{}) string

Format time (X values)

func XValueFormatterUnix

func XValueFormatterUnix(v interface{}) string

Types

type BoltDB added in v0.9.0

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

func OpenDB added in v0.9.0

func OpenDB(filename string, init bool) (*BoltDB, error)

func (*BoltDB) AutoRefreshHotspots added in v0.9.0

func (b *BoltDB) AutoRefreshHotspots(limit int64) error

func (*BoltDB) Close added in v0.9.0

func (b *BoltDB) Close()

func (*BoltDB) GenerateBeaconsGraph added in v0.9.0

func (b *BoltDB) GenerateBeaconsGraph(address string, results []Challenges, settings GraphSettings) error

Creates the PNG for the the beacons sent

func (*BoltDB) GeneratePeerGraphs added in v0.9.0

func (b *BoltDB) GeneratePeerGraphs(address string, challenges []Challenges, settings GraphSettings) error

Generate all the peer graphs for a given address

func (*BoltDB) GenerateWitnessesGraph added in v0.9.0

func (b *BoltDB) GenerateWitnessesGraph(address string, results []Challenges, settings GraphSettings) error

Creates the PNG for the the witnesses

func (*BoltDB) GetChallenges added in v0.9.0

func (b *BoltDB) GetChallenges(address string, first time.Time, last time.Time) ([]Challenges, error)

returns a list of challenges for the given hotspot

func (*BoltDB) GetDb added in v0.9.0

func (b *BoltDB) GetDb() *bolt.DB

func (*BoltDB) GetHotspot added in v0.9.0

func (b *BoltDB) GetHotspot(address string) (Hotspot, error)

Get the Hotspot metadata for a given address

func (*BoltDB) GetHotspotAddress added in v0.9.0

func (b *BoltDB) GetHotspotAddress(name string) (string, error)

Lookup the hotspot address by name

func (*BoltDB) GetHotspotByUnknown added in v0.9.0

func (b *BoltDB) GetHotspotByUnknown(addressOrName string) (string, error)

Returns the address of the hotspot given an address or name

func (*BoltDB) GetHotspotName added in v0.9.0

func (b *BoltDB) GetHotspotName(address string) (string, error)

Lookup the hotspot name by address

func (*BoltDB) GetHotspots added in v0.9.0

func (b *BoltDB) GetHotspots() ([]Hotspot, error)

Get all the hotspots in the DB

func (*BoltDB) GetHotspotsCacheHeight added in v0.9.0

func (b *BoltDB) GetHotspotsCacheHeight() (int64, error)

returns the height of the block chain when we cached the hotspots

func (*BoltDB) LoadChallenges added in v0.9.0

func (b *BoltDB) LoadChallenges(address string, first, last time.Time, holddown time.Duration) error

Load all the challenges as old as first if last <= time.UTC()

func (*BoltDB) LoadHotspots added in v0.9.0

func (b *BoltDB) LoadHotspots(last time.Time) error

Loads all the current hotspots into the database, if we are too old

func (*BoltDB) SetAllHotspots added in v0.9.0

func (b *BoltDB) SetAllHotspots(hotspots []Hotspot) error

Write a list of hotspots to the database under the address

func (*BoltDB) SetHotspots added in v0.9.0

func (b *BoltDB) SetHotspots(hotspots []Hotspot) error

Write a list of hotspots to the database under the address and name

type ChallengeCache

type ChallengeCache struct {
	CacheTime  int64        `json:"cache_time"`
	Address    string       `json:"address"`
	StartDate  int64        `json:"start_date"`
	Challenges []Challenges `json:"challenges"`
}

type ChallengeResponse

type ChallengeResponse struct {
	Data   []Challenges `json:"data"`
	Cursor string       `json:"cursor"`
}

type ChallengeResult

type ChallengeResult struct {
	Timestamp int64
	Address   string
	Signal    int
	Location  string
}

type Challenges

type Challenges struct {
	Type               string      `json:"type"`
	Time               int64       `json:"time"`
	Secret             string      `json:"secret"`
	Path               *[]PathType `json:"path"`
	OnionKeyHash       string      `json:"onion_key_hash"`
	Height             int64       `json:"height"`
	Hash               string      `json:"hash"`
	Fee                int         `json:"fee"`
	ChallengerOwner    string      `json:"challenger_owner"`
	ChallengerLon      float64     `json:"challenger_lon"`
	ChallengerLat      float64     `json:"challenger_lat"`
	ChallengerLocation string      `json:"challenger_location"`
	Challenger         string      `json:"challenger"`
}

func FetchChallenges

func FetchChallenges(address string, start time.Time) ([]Challenges, error)

Download all the challenges from the API. Returns newest first (LIFO)

func (*Challenges) GetTime

func (c *Challenges) GetTime() (time.Time, error)

Tries to figure out the Time for the given challenge

func (*Challenges) GetTimestamp

func (c *Challenges) GetTimestamp() (int64, error)

Tries to figure out the Timestamp for the given challenge

type GeocodeType

type GeocodeType struct {
	ShortStreet  string `json:"short_street"`
	ShortState   string `json:"short_state"`
	ShortCountry string `json:"short_country"`
	ShortCity    string `json:"short_city"`
	Street       string `json:"long_street"`
	State        string `json:"long_state"`
	Country      string `json:"long_country"`
	City         string `json:"long_city"`
}

type GraphSettings added in v0.9.0

type GraphSettings struct {
	Min  int  // minimum challenges
	Zoom bool // zoom in
	Json bool // generate json for each pair
}

type HeightResponse added in v0.9.0

type HeightResponse struct {
	Data map[string]int64 `json:"data"`
}

type Hotspot

type Hotspot struct {
	Address     string       `json:"address"`
	Block       int64        `json:"block"`
	BlockAdded  int64        `json:"block_added"`
	Geocode     *GeocodeType `json:"geocode"`
	Lat         float64      `json:"lat"`
	Lng         float64      `json:"lng"`
	Location    string       `json:"location"`
	Name        string       `json:"name"`
	Nonce       int64        `json:"nonce"`
	Owner       string       `json:"owner"`
	RewardScale float64      `json:"reward_scale"`
	Status      *StatusType  `json:"status"`
}

func FetchHotspots added in v0.9.0

func FetchHotspots() ([]Hotspot, error)

Download hotspot data from helium.api servers

func GetHotspot

func GetHotspot(address string) (Hotspot, error)

Looks up a hotspot by address in the cache. If not, it queries the API

type HotspotCache

type HotspotCache struct {
	Time     int64     `json:"time"`
	Hotspots []Hotspot `json:"hotspots"`
}

type HotspotResponse

type HotspotResponse struct {
	Data Hotspot `json:"data"`
}

type HotspotsResponse

type HotspotsResponse struct {
	Data   []Hotspot `json:"data"`
	Cursor string    `json:"cursor"`
}

type PathType

type PathType struct {
	Witnesses          *[]WitnessType `json:"witnesses"`
	Receipt            *ReceiptType   `json:"receipt"`
	Geocode            *GeocodeType   `json:"geocode"`
	ChallengeeOwner    string         `json:"challengee_owner"`
	ChallengeeLon      float64        `json:"challengee_lon"`
	ChallengeeLat      float64        `json:"challengee_lat"`
	ChallengeeLocation string         `json:"challengee_location"`
	Challengee         string         `json:"challengee"`
}

type RXTX

type RXTX int
const (
	RX RXTX = iota
	TX
)

type ReceiptType

type ReceiptType struct {
	Timestamp int64  `json:"timestamp"`
	Signal    int    `json:"signal"`
	Origin    string `json:"origin"`
	Gateway   string `json:"gateway"`
	Data      string `json:"data"`
}

type StatusType

type StatusType struct {
	Height int64  `json:"height"`
	Online string `json:"online"`
}

type TooBusyError added in v0.9.2

type TooBusyError struct {
	Error    string        `json:"error"`
	ComeBack time.Duration `json:"come_back_in_ms"`
}

type WitnessResult

type WitnessResult struct {
	Timestamp      int64   `json:"timestamp"`
	Address        string  `json:"address"`
	Witness        string  `json:"witness"`
	Type           RXTX    `json:"type"`
	Signal         int     `json:"signal"`
	Valid          bool    `json:"valid"`
	Km             float64 `json:"km"`
	Mi             float64 `json:"mi"`
	Location       string  `json:"location"`
	Snr            float64 `json:"snr"`
	ValidThreshold float64 `json:"valid_threshold"`
	Hash           string  `json:"hash"`
}

type WitnessType

type WitnessType struct {
	Timestamp  int64   `json:"timestamp"`
	Signal     int     `json:"signal"`
	PacketHash string  `json:"packet_hash"`
	Owner      string  `json:"owner"`
	Location   string  `json:"location"`
	Gateway    string  `json:"gateway"`
	Snr        float64 `json:"snr"`
	IsValid    bool    `json:"is_valid"`
}

Jump to

Keyboard shortcuts

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