common

package module
v0.0.0-...-70bd2a0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 13 Imported by: 0

README

mainline-dht-common

GoReportCard example Build

This is a collection of utility functions used by the different Mainline DHT projects.

It is intended for use as a library across the various MLDHT projects, i.e.

Installation

The library can be installed using

go get github.com/wiberlin/mainline-dht-common

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskYesNo

func AskYesNo() bool

AskYesNo asks the user to enter "y" or "n". Also recognizes "yes" and "no" in all capitalizations. Anything unrecognized will is equivalent to "n".

func CrawlReportToFile

func CrawlReportToFile(report *CrawlOutput, onlineOnly bool, path string)

func CreateDirIfNotExists

func CreateDirIfNotExists(path string) error

CreateDirIfNotExists creates the directory described in path if it does not exist yet.

func IsIPAddressLocal

func IsIPAddressLocal(addr net.IP) bool

IsIPAddressLocal determines whether an IP address is local. Local addresses should(?) not be routed on the open internet and are probably not connectable.

func IsNullSlice

func IsNullSlice(arr [20]byte) bool

IsNullSlice checks if the bytes of given slice are all null

func MonitorReportToFile

func MonitorReportToFile(report *Output, path string)

MonitorReportToFile writes the report to the file in path. report is a pointer to an output data structure, currently only generated by the monitor.

func NodeInfoToID

func NodeInfoToID(addrs []*krpc.NodeInfo) []krpc.ID

NodeInfoToID extracts each ID from an arry of krpc.NodeInfo and returns the krpc.IDs

func NodeinfoToUdpAddr

func NodeinfoToUdpAddr(nodeInfo *krpc.NodeInfo) net.UDPAddr

NodeinfoToUdpAddr converts a krpc.NodeInfo to a net.UDPAddr

func ParseAddrString

func ParseAddrString(text string) (*krpc.NodeInfo, error)

ParseAddrString parses an IP:port address into anacrolix/dht krpc.NodeInfo. This is very useful when connecting to bootstrap nodes.

func ReadBootstrapListFromFile

func ReadBootstrapListFromFile(path string) ([]*krpc.NodeInfo, error)

ReadBootstrapListFromFile parses a file containing bootstrap peers. It assumes a text file with an IP:Port address on each line. It will ignore lines starting with a comment "//"

func TargetIsInZone

func TargetIsInZone(sourceID [20]byte, targetID [20]byte, zone int) bool

TargetIsInZone returns true is targetID has zone many bits in common with sourceID

func UDPToNodeAddr

func UDPToNodeAddr(udp net.UDPAddr) krpc.NodeAddr

UDPToNodeAddr converts the net.UDPAddr to a krpc.NodeAddr

Types

type CrawlOutput

type CrawlOutput struct {
	StartDate string
	EndDate   string
	Nodes     map[krpc.ID]*CrawledNode
}

CrawlOutput summarises the crawl, i.e. timestamp + collection of nodes we learned

type CrawlOutputJSON

type CrawlOutputJSON struct {
	StartDate string             `json:"start_timestamp"`
	EndDate   string             `json:"end_timestamp"`
	Nodes     []*CrawledNodeJSON `json:"found_nodes"`
}

CrawledOutputJSON is a collection of CrawledNodeJSON along with a timestamp

type CrawlResult

type CrawlResult struct {
	Node *NodeKnows
	Err  error
}

CrawlResult is a container struct for crawl results... because of go...

type CrawledNode

type CrawledNode struct {
	NID        krpc.ID
	UDPAddrs   net.UDPAddr
	Reachable  bool
	IPVersion  IPVersion
	Neighbours []krpc.ID
	Timestamp  string
}

CrawledNode stores everything we know about a node we have contacted

type CrawledNodeJSON

type CrawledNodeJSON struct {
	NID       krpc.ID     `json:"NodeID"`
	UDPAddrs  net.UDPAddr `json:"udpaddrs"`
	Reachable bool        `json:"reachable"`
	IPVersion string      `json:"ip_version"`
}

CrawledNodeJSON encodes a node found by the crawler as a JSON string

type IPVersion

type IPVersion uint

IPVersion is the version of an IP address, or unknown for invalid addresses.

const (
	UnknownVersion IPVersion = iota
	IPv4
	IPv6
)

Enum describing possible types of IP addresses

func DetermineIPVersion

func DetermineIPVersion(address net.IP) IPVersion

DetermineIPVersion determines whether the given address is v4, v6, or invalid. This essentially duplicates the logic in (net.IP).To4() and (net.IP).To16() without the special-casing of IPv4-in-IPv6 addresses.

func (IPVersion) String

func (v IPVersion) String() string

type InfoHash

type InfoHash = int160.T

InfoHash is a 20 byte ID

type KRPCNilResponseError

type KRPCNilResponseError struct {
	Msg  string
	Peer krpc.NodeInfo
}

KRPCNilResponseError signals that the KRPC Query returned an error. These could be: 1. A nil pointer in the message 2. Maybe a anacrolix/dht's rate limit error (TBD)

func (*KRPCNilResponseError) Error

func (e *KRPCNilResponseError) Error() string

type MonitorOutputJSON

type MonitorOutputJSON struct {
	StartDate string               `json:"start_timestamp"`
	EndDate   string               `json:"end_timestamp"`
	Nodes     []*MonitoredNodeJSON `json:"found_nodes"`
}

MonitoredNodeJSON is a collection of MonitoredNodeJSON

type MonitoredNodeJSON

type MonitoredNodeJSON struct {
	UDPAddrs  net.UDPAddr `json:"udpaddrs"`
	Reachable bool        `json:"reachable"`
	IPVersion string      `json:"ip_version"`
}

MonitoredNodeJSON holds a DHT Node described by its UDP address, its connectivity status and IP Version encoded as JSON strings

type NodeKnows

type NodeKnows struct {
	Id    krpc.ID
	Knows []*krpc.NodeInfo
	Info  map[string]interface{}
}

NodeKnows stores the collected addresses for a given ID

type ObservedNode

type ObservedNode struct {
	UDPAddr   net.UDPAddr
	Reachable bool
	IPVersion IPVersion
}

ObservedNode contains all the information about a single node during observation

type Output

type Output struct {
	StartDate string
	EndDate   string
	Nodes     map[string]*ObservedNode
}

Output is an object that contains the results of the monitoring period, i.e. start and end time, and a map of ObservedNodes

Jump to

Keyboard shortcuts

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