Documentation ¶
Index ¶
- Constants
- Variables
- func Blake2b256(v []byte) []byte
- func BytesToObject(bs []byte, dest interface{}) error
- func DecodeNumber(encNum []byte) uint64
- func Decrypt(ciphertext []byte, key []byte) ([]byte, error)
- func EncodeForJS(obj interface{}, fieldToIgnore ...string) interface{}
- func EncodeNumber(n uint64) []byte
- func Encrypt(plaintext []byte, key []byte) ([]byte, error)
- func FromHex(hexValue string) ([]byte, error)
- func GenerateKeyPair(r io.Reader) (crypto.PrivKey, crypto.PubKey, error)
- func GetIPFromAddr(addr string) net.IP
- func GetPtrAddr(ptrAddr interface{}) *big.Int
- func HexToInt64(hexVal string) (int64, error)
- func HexToStr(hexStr string) (string, error)
- func IDFromAddr(addr ma.Multiaddr) peer.ID
- func IDFromAddrString(addr string) peer.ID
- func Int64ToHex(intVal int64) string
- func IsDevAddr(ip net.IP) bool
- func IsFileOk(path string) bool
- func IsPathOk(path string) bool
- func IsRoutable(ip net.IP) bool
- func IsRoutableAddr(addr string) bool
- func IsValidAddr(addr string) bool
- func IsValidConnectionString(str string) bool
- func IsValidHostPortAddress(address string) bool
- func LogAlert(format string, args ...interface{})
- func MapDecode(m interface{}, rawVal interface{}) error
- func MayDecodeNumber(encNum []byte) (r uint64, err error)
- func MustFromHex(hexValue string) []byte
- func NonZeroOrDefIn64(v int64, def int64) int64
- func ObjectToBytes(s interface{}) []byte
- func ParseAddr(addr string) map[string]string
- func RandBytes(n int) []byte
- func RandString(n int) string
- func SerializeMsg(o interface{}) []byte
- func ShortID(id peer.ID) string
- func StrToDec(val string) decimal.Decimal
- func StrToHex(str string) string
- func StructToMap(s interface{}) map[string]interface{}
- func ToHex(value []byte) string
- func ValidateAndResolveConnString(connStr string) (string, error)
- type BlockNonce
- type ConnStringData
- type Hash
- type NodeAddr
- func (a NodeAddr) ConnectionString() string
- func (a NodeAddr) DecapIPFS() ma.Multiaddr
- func (a NodeAddr) Equal(b NodeAddr) bool
- func (a NodeAddr) GetMultiaddr() ma.Multiaddr
- func (a NodeAddr) ID() peer.ID
- func (a NodeAddr) IP() net.IP
- func (a NodeAddr) IsRoutable() bool
- func (a NodeAddr) IsValid() bool
- func (a NodeAddr) String() string
- func (a NodeAddr) StringID() string
- type String
Constants ¶
const (
// HashLength is the standard size of hash values
HashLength = 32
)
Variables ¶
var Big0 = new(big.Int).SetInt64(0)
Big0 represents a zero value big.Int
var EmptyBlockNonce = BlockNonce([8]byte{})
EmptyBlockNonce is a BlockNonce with no values
var EmptyHash = Hash([HashLength]byte{})
EmptyHash is an empty Hash
Functions ¶
func BytesToObject ¶
BytesToObject decodes bytes produced by BytesToObject to the given dest object
func DecodeNumber ¶
DecodeNumber deserialize a number from BigEndian
func EncodeForJS ¶
func EncodeForJS(obj interface{}, fieldToIgnore ...string) interface{}
EncodeForJS takes a struct and converts selected types to values that are compatible in the JS environment. It returns a map and will panic if obj is not a map/struct. Set fieldToIgnore to ignore matching fields
func EncodeNumber ¶
EncodeNumber serializes a number to BigEndian
func FromHex ¶
FromHex decodes hex value to bytes. If hex value is prefixed with '0x' it is trimmed before the decode operation.
func GenerateKeyPair ¶
GenerateKeyPair generates private and public keys
func GetIPFromAddr ¶
GetIPFromAddr get the IP4/6 ip of the address. Expects the caller to have validate the addr
func GetPtrAddr ¶
GetPtrAddr takes a pointer and returns the address
func HexToInt64 ¶
HexToInt64 attempts to convert an hex string to Int64. Expects the hex string to begin with '0x'.
func IDFromAddr ¶
IDFromAddr extracts and returns the peer ID
func IDFromAddrString ¶
IDFromAddrString is like IDFromAddr but accepts a string. Returns empty string if addr is not a valid multiaddr. Expects the caller to have validated addr before calling the function.
func Int64ToHex ¶
Int64ToHex converts an Int64 value to hex string. The resulting hex is prefixed by '0x'
func IsRoutable ¶
IsRoutable returns whether or not the passed address is routable over the public internet. This is true as long as the address is valid and is not in any reserved ranges.
func IsRoutableAddr ¶
IsRoutableAddr checks if an addr is valid and routable
func IsValidAddr ¶
IsValidAddr checks if an address is a valid multi address with ip4/ip6, tcp, and ipfs protocols
func IsValidConnectionString ¶
IsValidConnectionString checks whether a connection string is valid
func IsValidHostPortAddress ¶
IsValidHostPortAddress checks if an address is a valid address matching the format `host:port`
func LogAlert ¶
func LogAlert(format string, args ...interface{})
LogAlert wraps pp.Println with a read [Alert] prefix.
func MapDecode ¶
func MapDecode(m interface{}, rawVal interface{}) error
MapDecode decodes a map to a struct. It uses mapstructure.Decode internally but with 'json' TagName.
func MayDecodeNumber ¶
MayDecodeNumber is like DecodeNumber but returns an error instead of panicking
func MustFromHex ¶
MustFromHex is like FromHex except it panics if an error occurs
func NonZeroOrDefIn64 ¶
NonZeroOrDefIn64 checks if v is 0 so it returns def, otherwise returns v
func ObjectToBytes ¶
func ObjectToBytes(s interface{}) []byte
ObjectToBytes returns msgpack encoded representation of an object
func ParseAddr ¶
ParseAddr returns the protocol and value present in a multiaddr. Expects the caller to have validate the address before calling the function.
func SerializeMsg ¶
func SerializeMsg(o interface{}) []byte
SerializeMsg serializes an object using msgpack. Panics if an error is encountered
func StrToDec ¶
StrToDec converts a numeric string to decimal. Panics if val could not be converted to decimal.
func StructToMap ¶
func StructToMap(s interface{}) map[string]interface{}
StructToMap returns a map containing fields from the s. Map fields are named after their json tags on the struct
func ValidateAndResolveConnString ¶
ValidateAndResolveConnString validates a connection string and attempts to resolve the address of a connection string to an IP if it is a domain name.
Types ¶
type BlockNonce ¶
type BlockNonce [8]byte
BlockNonce is a 64-bit hash which proves (combined with the mix-hash) that a sufficient amount of computation has been carried out on a block.
func EncodeNonce ¶
func EncodeNonce(i uint64) BlockNonce
EncodeNonce converts the given integer to a block nonce.
func (BlockNonce) MarshalText ¶
func (n BlockNonce) MarshalText() string
MarshalText encodes n as a hex string with 0x prefix.
func (BlockNonce) Uint64 ¶
func (n BlockNonce) Uint64() uint64
Uint64 returns the integer value of a block nonce.
type ConnStringData ¶
ConnStringData represents
func ParseConnString ¶
func ParseConnString(str string) *ConnStringData
ParseConnString breaksdown a connection string
func (*ConnStringData) ConnString ¶
func (cs *ConnStringData) ConnString() string
ConnString returns a valid connection string
type Hash ¶
type Hash [HashLength]byte
Hash represents a hash value
type NodeAddr ¶
type NodeAddr string
NodeAddr represents address that points to a node on a network. The address are represented as Multiaddr.
func AddressFromConnString ¶
AddressFromConnString creates a NodeAddress from a given connection string
func AddressFromHost ¶
AddressFromHost gets address of an host
func RemoteAddrFromConn ¶
RemoteAddrFromConn gets the remote address from the given connection
func RemoteAddrFromStream ¶
RemoteAddrFromStream gets the remote address from the given stream
func (NodeAddr) ConnectionString ¶
ConnectionString returns an address similar to database connection string with a branded schema
func (NodeAddr) GetMultiaddr ¶
GetMultiaddr gets the address. It will panic if the address is not a valid Multiaddr
func (NodeAddr) IsRoutable ¶
IsRoutable checks whether the address is routable
type String ¶
type String string
String represents a custom string
func (String) Decimal ¶
Decimal returns the decimal representation of the string. Panics if string failed to be converted to decimal.