util

package
v0.0.0-...-1c9500d Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FIN = 1  // 00 0001
	SYN = 2  // 00 0010
	RST = 4  // 00 0100
	PSH = 8  // 00 1000
	ACK = 16 // 01 0000
	URG = 32 // 10 0000
)
View Source
const (
	// MaxVarIntPayload is the maximum payload size for a variable length integer.
	MaxVarIntPayload = 9
)

Variables

This section is empty.

Functions

func Csum

func Csum(data []byte, srcip, dstip [4]byte) uint16

TCP Checksum

func DecodeStratumHash

func DecodeStratumHash(hash []byte) (*chainhash.Hash, error)

func DeserializeJsonMap

func DeserializeJsonMap(jsonMap map[string]interface{}, target interface{}) error

func GetLoglevelFromEnv

func GetLoglevelFromEnv() int

func HashToString

func HashToString(h []byte) string

func MeasureTcpLatency

func MeasureTcpLatency(remoteHost string, remotePort int) (int64, error)

func NewClientID

func NewClientID() string

NewClientID returns a new ID for internal references to client connections

func NewJobID

func NewJobID() string

NewJobID Returns a new stratum job id for internal use

func ReadElement

func ReadElement(r io.Reader, element interface{}) error

readElement reads the next sequence of bytes from r using little endian depending on the concrete type of element pointed to.

func ReadElements

func ReadElements(r io.Reader, elements ...interface{}) error

readElements reads multiple items from r. It is equivalent to multiple calls to readElement.

func ReadOutPoint

func ReadOutPoint(r io.Reader, op *wire.OutPoint) error

ReadOutPoint reads the next sequence of bytes from r as an OutPoint.

func ReadScript

func ReadScript(r io.Reader, fieldName string) ([]byte, error)

ReadScript reads a variable length byte array that represents a transaction script. It is encoded as a varInt containing the length of the array followed by the bytes themselves. An error is returned if the length is greater than the passed maxAllowed parameter which helps protect against memory exhaustion attacks and forced panics through malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error.

func ReadTxIn

func ReadTxIn(r io.Reader, ti *wire.TxIn) error

ReadTxIn reads the next sequence of bytes from r as a transaction input (TxIn).

func ReadTxOut

func ReadTxOut(r io.Reader, to *wire.TxOut) error

ReadTxOut reads the next sequence of bytes from r as a transaction output (TxOut).

func ReadVarBytes

func ReadVarBytes(r io.Reader, pver uint32, maxAllowed uint32,
	fieldName string) ([]byte, error)

ReadVarBytes reads a variable length byte array. A byte array is encoded as a varInt containing the length of the array followed by the bytes themselves. An error is returned if the length is greater than the passed maxAllowed parameter which helps protect against memory exhaustion attacks and forced panics through malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error.

func ReadVarInt

func ReadVarInt(r io.Reader, pver uint32) (uint64, error)

ReadVarInt reads a variable length integer from r and returns it as a uint64.

func RevHash

func RevHash(hash string) string

func RevHashBytes

func RevHashBytes(hash []byte) []byte

func ReverseByteArray

func ReverseByteArray(b []byte) []byte

Types

type BlockHeader

type BlockHeader struct {
	Bits           string `json:"bits" bson:"bits"`
	Hash           string `json:"hash" bson:"hash"`
	Height         int64  `json:"height" bson:"height"`
	PrevHash       string `json:"previousblockhash" bson:"previousblockhash"`
	MedianTime     uint64 `json:"medianTime" bson:"medianTime"`
	Time           uint64 `json:"time" bson:"time"`
	Coin           string `json:"coin" bson:"coin"`
	TimeDiscovered uint64 `json:"timeDiscovered" bson:"timeDiscovered"`
}

type HubMessage

type HubMessage struct {
	Type    string                 `json:"type"`
	Content map[string]interface{} `json:"content"`
}

type Int64Time

type Int64Time time.Time

Int64Time represents a unix timestamp encoded with an int64. It is used as a way to signal the readElement function how to decode a timestamp into a Go time.Time since it is otherwise ambiguous.

type StratumClientIdentity

type StratumClientIdentity struct {
	User             string
	Host             string
	Algorithm        string
	PoolName         string
	PoolCoin         string
	ObserverLocation string
}

type StratumJob

type StratumJob struct {
	ID              string
	Difficulty      float64
	ExtraNonce1     string
	ExtraNonce2Size int
	JobData         []interface{}
}

func NewStratumJobFromJsonProperty

func NewStratumJobFromJsonProperty(i interface{}) StratumJob

func (StratumJob) AsJobData

func (job StratumJob) AsJobData() []interface{}

func (StratumJob) AsJobDataWithNewTimestamp

func (job StratumJob) AsJobDataWithNewTimestamp() []interface{}

type StratumServerIdentity

type StratumServerIdentity struct {
	Algorithm string
}

type TCPHeader

type TCPHeader struct {
	Source      uint16
	Destination uint16
	SeqNum      uint32
	AckNum      uint32
	DataOffset  uint8 // 4 bits
	Reserved    uint8 // 3 bits
	ECN         uint8 // 3 bits
	Ctrl        uint8 // 6 bits
	Window      uint16
	Checksum    uint16 // Kernel will set this if it's 0
	Urgent      uint16
	Options     []TCPOption
}

func NewTCPHeader

func NewTCPHeader(data []byte) *TCPHeader

Parse packet into TCPHeader structure

func (*TCPHeader) HasFlag

func (tcp *TCPHeader) HasFlag(flagBit byte) bool

func (*TCPHeader) Marshal

func (tcp *TCPHeader) Marshal() []byte

type TCPOption

type TCPOption struct {
	Kind   uint8
	Length uint8
	Data   []byte
}

type Uint32Time

type Uint32Time time.Time

Uint32Time represents a unix timestamp encoded with a uint32. It is used as a way to signal the readElement function how to decode a timestamp into a Go time.Time since it is otherwise ambiguous.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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