common

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: LGPL-3.0 Imports: 26 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// AddressLength - max addr length
	AddressLength = 20

	// HashLength - max hash length
	HashLength = 32
)

Variables

View Source
var (
	// ErrNilInput - error definition describing input of 0 char length
	ErrNilInput = errors.New("nil input")

	// ErrVerboseNotAllowed - error definition describing config preventing print call
	ErrVerboseNotAllowed = errors.New("verbose output not allowed")

	// DataDir - global data directory definition
	DataDir = getDataDir()

	// ConfigDir - global config directory definition
	ConfigDir = filepath.FromSlash(fmt.Sprintf("%s/config", DataDir))

	// PeerToPeerDir - global p2p directory definition.
	PeerToPeerDir = filepath.FromSlash(fmt.Sprintf("%s/p2p", DataDir))

	// DbDir - global db directory definition.
	DbDir = filepath.FromSlash(fmt.Sprintf("%s/db", DataDir))

	// DagDir - global dag directory definition.
	DagDir = filepath.FromSlash(fmt.Sprintf("%s/dag", DbDir))

	// DisableTimestamps - global declaration for timestamp format config
	DisableTimestamps = false

	// GeneralTLSConfig - general global GoP2P TLS Config
	GeneralTLSConfig = &tls.Config{
		Certificates:       []tls.Certificate{getTLSCerts("general")},
		InsecureSkipVerify: true,
		ServerName:         "localhost",
	}

	// BootstrapNodes - global definition for set of bootstrap nodes
	BootstrapNodes = []string{
		"108.41.124.60:3000",
	}

	// Silent - silent config
	Silent = false

	// NodePort - global port definition
	NodePort = 3000

	// VMConfig - global virtual machine config
	VMConfig = vm.Environment{
		EnableJIT:          false,
		DefaultMemoryPages: 128,
		DefaultTableSize:   65536,
	}

	// GasPolicy - global gas policy
	GasPolicy = &compiler.SimpleGasPolicy{
		GasPerInstruction: 1,
	}
)
View Source
var (
	// MemPrefix - "0x" memory address  prefixbyte array representation
	MemPrefix = []byte{48, 120}

	// ErrNoMem - error definition describing input < 2 chars long (< len(0x))
	ErrNoMem = errors.New("insufficient length for memory address char")
)
View Source
var ErrDuplicateAddress = errors.New("duplicate address")

ErrDuplicateAddress - error definition describing two addresses of equal value

View Source
var ExtIPProviders = []string{
	"http://checkip.amazonaws.com/",
	"http://icanhazip.com/",
	"http://www.trackip.net/ip",
	"http://bot.whatismyipaddress.com/",
	"https://ipecho.net/plain",
	"http://myexternalip.com/raw",
}

ExtIPProviders - preset macro defining list of available external IP checking services

Functions

func Connected

func Connected() (connected bool)

Connected - check if connected to internet

func CreateDirIfDoesNotExist added in v0.6.1

func CreateDirIfDoesNotExist(dir string) error

CreateDirIfDoesNotExist - create given directory if does not exist

func Decode

func Decode(b []byte) ([]byte, error)

Decode - decode given hex-formatted, MemPrefix-compliant byte array to standard byte array

func DecodeString

func DecodeString(s string) ([]byte, error)

DecodeString - decode given hex-formatted, MemPrefix-compliant string to standard byte array

func Encode

func Encode(b []byte) ([]byte, error)

Encode - encode given byte array to hex-formatted, MemPrefix-compliant byte array

func EncodeString

func EncodeString(b []byte) (string, error)

EncodeString - encode given byte array to hex-formatted, MemPrefix-compliant string

func Forever

func Forever()

Forever - prevent thread from closing

func GenerateTLSCertificates

func GenerateTLSCertificates(namePrefix string) error

GenerateTLSCertificates - generate necessary TLS certificates, keys

func GetExtIPAddrWithoutUPnP

func GetExtIPAddrWithoutUPnP() (string, error)

GetExtIPAddrWithoutUPnP - retrieve the external IP address of the current machine w/o upnp

func Log

func Log(a ...interface{}) (int, error)

Log - fmt.Println wrapper

func Logf

func Logf(format string, a ...interface{}) (int, error)

Logf - fmt.Printf wrapper

func ParseStringMethodCall

func ParseStringMethodCall(input string) (string, string, []string, error)

ParseStringMethodCall - attempt to parse string as method call, returning receiver, method name and params

func ParseStringMethodCallNoReceiver added in v0.5.1

func ParseStringMethodCallNoReceiver(input string) (string, []string, error)

ParseStringMethodCallNoReceiver - attempt to parse string as method call, returning method name and params

func ParseStringParams

func ParseStringParams(input string) ([]string, error)

ParseStringParams - attempt to fetch string parameters from (..., ..., ...) style call

func ReadConnectionWaitAsyncNoTLS

func ReadConnectionWaitAsyncNoTLS(conn net.Conn) ([]byte, error)

ReadConnectionWaitAsyncNoTLS - attempt to read from connection in an asynchronous fashion, after waiting for peer to write

func ReadGob

func ReadGob(filePath string, object interface{}) error

ReadGob - read gob specified at path

func SendBytes

func SendBytes(b []byte, address string) error

SendBytes - attempt to send specified bytes to given address

func SendBytesResult added in v0.5.0

func SendBytesResult(b []byte, address string) ([]byte, error)

SendBytesResult - gop2pCommon.SendBytesResult performance-optimized wrapper

func StringFetchCallReceiver

func StringFetchCallReceiver(input string) string

StringFetchCallReceiver - attempt to fetch receiver from string, as if it were an x.y(..., ..., ...) style method call

func StringStripParentheses

func StringStripParentheses(input string) string

StringStripParentheses - strip parantheses from string

func StringStripReceiverCall

func StringStripReceiverCall(input string) string

StringStripReceiverCall - strip receiver from string method call

func WriteGob

func WriteGob(filePath string, object interface{}) error

WriteGob - create gob from specified object, at filePath

Types

type Address

type Address [AddressLength]byte

Address - []byte wrapper for addresses

func NewAddress

func NewAddress(privateKey *ecdsa.PrivateKey) (Address, error)

NewAddress - initialize new address

func PublicKeyToAddress

func PublicKeyToAddress(publicKey *ecdsa.PublicKey) Address

PublicKeyToAddress - initialize new address with given public key

func StringToAddress

func StringToAddress(s string) (Address, error)

StringToAddress - convert string to address

func (Address) Bytes

func (address Address) Bytes() []byte

Bytes - convert given address to bytes

func (Address) String

func (address Address) String() string

String - convert given address to string

type AddressSpace

type AddressSpace struct {
	Addresses []Address `json:"addresses"` // Addresses in address space
	ID        Hash      `json:"ID"`        // AddressSpace identifier
}

AddressSpace - given address-space (e.g. 0x000-0x123)

func NewAddressSpace

func NewAddressSpace(originAddresses []Address) (*AddressSpace, error)

NewAddressSpace - initialize address space

func (*AddressSpace) Bytes

func (addressSpace *AddressSpace) Bytes() []byte

Bytes - convert given address-space to bytes

func (*AddressSpace) String

func (addressSpace *AddressSpace) String() string

String - convert given address-space to string

type Hash

type Hash [HashLength]byte

Hash - []byte wrapper for hashes

func NewHash

func NewHash(b []byte) Hash

NewHash - initialize hash from byte array

func StringToHash

func StringToHash(s string) (Hash, error)

StringToHash - convert string to hash

func (Hash) Bytes

func (hash Hash) Bytes() []byte

Bytes - convert given hash to bytes

func (Hash) String

func (hash Hash) String() string

String - convert given hash to string

Jump to

Keyboard shortcuts

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