utils

package
v0.0.0-...-811d2bd Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VIDEO_CODEC = 0x72 // VIDEO_CODEC is separate from SDS_CODEC in order to identify the videos
	SDS_CODEC   = 0x66 // codec of legacy file hash is cid.RAW. New file hash uses SDS_CODEC.

	VALID_CID_VERSION = 1
	VALID_MH_TYPE     = 27
	VALID_MH_LENGTH   = 20
)
View Source
const (
	SIZE_OF_INT8   = 1
	SIZE_OF_UINT8  = 1
	SIZE_OF_INT16  = 2 // in byte
	SIZE_OF_UINT16 = 2 // in byte
	SIZE_OF_INT32  = 4 // in byte
	SIZE_OF_UINT32 = 4 // in byte
	SIZE_OF_INT64  = 8 // in byte
	SIZE_OF_UINT64 = 8 // in byte
)

Variables

View Source
var (
	ErrNotFoundCallBack = errors.New("not found callBack function")
	ErrServerClosed     = errors.New("server has been closed")
	ErrWouldBlock       = errors.New("would block")
)

Functions

func Absolute

func Absolute(path string) (string, error)

func AddRpcLogger

func AddRpcLogger(w io.Writer, id string)

func ByteToString

func ByteToString(p []byte) string

func BytesToInt16

func BytesToInt16(b []byte) int16

func BytesToInt64

func BytesToInt64(b []byte) int64

func BytesToUInt32

func BytesToUInt32(b []byte) uint32

func BytesToUInt64

func BytesToUInt64(b []byte) uint64

func BytesToUint16

func BytesToUint16(b []byte) uint16

func CalcCRC32

func CalcCRC32(data []byte) uint32

func CalcCRC32OfSlices

func CalcCRC32OfSlices(data [][]byte) uint32

func CalcFileCRC32

func CalcFileCRC32(filePath string) uint32

func CalcFileHash

func CalcFileHash(filePath, encryptionTag string, codec byte) string

func CalcFileHashFromSlices

func CalcFileHashFromSlices(files []string, encryptionTag string) string

func CalcFileKeccak

func CalcFileKeccak(filePath string) mh.Multihash

func CalcFileMD5

func CalcFileMD5(filePath string) []byte

func CalcHash

func CalcHash(data []byte) string

func CalcHashBytes

func CalcHashBytes(data []byte) []byte

func CalcKeccakOfSplitFiles

func CalcKeccakOfSplitFiles(files []string) []byte

func CalcMD5OfSplitFiles

func CalcMD5OfSplitFiles(filePath []string) []byte

func CalcSliceHash

func CalcSliceHash(data []byte, fileHash string, sliceNumber uint64) string

func ChangePassword

func ChangePassword(walletAddress, dir, auth string, key *AccountKey) error

ChangePassword

func CheckError

func CheckError(err error) bool

CheckError TODO This is a bad way to call error log, as you cannot know where this method is called in your error log This give log line like this : [ERROR]2021/04/13 22:39:11 log.go:150: Fatal error: address 127.0.0.1: missing port in address it always refer to this file and this line If time allows, a better logging tool like "zerolog" can be used to replace these methods.

func Crc32IEEE

func Crc32IEEE(data []byte) uint32

func CreateP2PKey

func CreateP2PKey(dir, nickname, password, hrp string) (types.Address, error)

CreateP2PKey creates a P2P key to be used by one of the SDS nodes, and saves the key data into the dir folder

func DebugLog

func DebugLog(v ...interface{})

DebugLog calls default logger and output debug log

func DebugLogf

func DebugLogf(template string, v ...interface{})

DebugLog calls default logger and output debug log

func DebugLogfWithCalldepth

func DebugLogfWithCalldepth(calldepth int, template string, v ...interface{})

DebugLog calls default logger and output debug log

func DetailLog

func DetailLog(v ...interface{})

DetailLog calls default logger and output detail log

func DetailLogf

func DetailLogf(template string, v ...interface{})

DetailLog calls default logger and output detail log

func DisableRpcLogger

func DisableRpcLogger(id string)

func DumpTraffic

func DumpTraffic(v ...interface{})

DumpTraffic Log calls default logger and output info log

func ECCSign

func ECCSign(text []byte, prk *ecdsa.PrivateKey) ([]byte, error)

ECCSign signs the given text

func ECCSignBytes

func ECCSignBytes(text, privateKey []byte) ([]byte, error)

ECCSignBytes converts the private key bytes to an ecdsa.PrivateKey and then signs the given text

func ECCVerify

func ECCVerify(text []byte, signature []byte, key *ecdsa.PublicKey) bool

ECCVerify verifies the given signature

func ECCVerifyBytes

func ECCVerifyBytes(text, signature, publicKey []byte) bool

ECCVerifyBytes converts the public key bytes to an ecdsa.PublicKey and then verifies the given signature

func EncryptKey

func EncryptKey(key *AccountKey, auth string) ([]byte, error)

EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.

func ErrorLog

func ErrorLog(v ...interface{})

ErrorLog call default logger and output error log

func ErrorLogf

func ErrorLogf(template string, v ...interface{})

ErrorLogf call default logger and output error log

func FatalLogfAndExit

func FatalLogfAndExit(exitCode int, template string, v ...interface{})

func FormatError

func FormatError(err error) string

func GetCodecFromFileHash

func GetCodecFromFileHash(hash string) (uint64, error)

func GetLastLinesFromTrafficLog

func GetLastLinesFromTrafficLog(path string, n uint64) []string

func Int16ToBytes

func Int16ToBytes(n int16) []byte

func Int64ToByte

func Int64ToByte(n int64) []byte

func IntToString

func IntToString(i int) string

func IsVideoStream

func IsVideoStream(hash string) bool

func LoadTomlConfig

func LoadTomlConfig(s interface{}, path string) error

func LoadYamlConfig

func LoadYamlConfig(s interface{}, path string) error

func Log

func Log(v ...interface{})

Log calls default logger and output info log

func Logf

func Logf(template string, v ...interface{})

func MergeByte

func MergeByte(b ...[]byte) []byte

func MergeBytes

func MergeBytes(a, b []byte) []byte

func NewMnemonic

func NewMnemonic() (string, error)

func ParseTomlValue

func ParseTomlValue(data string) (interface{}, error)

func RegisterReqToLogger

func RegisterReqToLogger(reqId int64, terminalId string) bool

func RegisterReqToParentReq

func RegisterReqToParentReq(reqId, parentId int64) bool

func StringToInt

func StringToInt(s string) (int, error)

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

func Uint16ToBytes

func Uint16ToBytes(n uint16) []byte

func Uint32ToBytes

func Uint32ToBytes(n uint32) []byte

func Uint64ToBytes

func Uint64ToBytes(n uint64) []byte

func Uint8ToBytes

func Uint8ToBytes(n uint8) []byte

func ValidateHash

func ValidateHash(hash string) bool

ValidateHash only validate the hash format, does NOT verify if the hash is created by certain content

func WarnLog

func WarnLog(v ...interface{})

func WriteKeyFile

func WriteKeyFile(file string, content []byte) error

func WriteTomlConfig

func WriteTomlConfig(data interface{}, filePath string) error

Types

type AccountKey

type AccountKey struct {
	Id uuid.UUID // Version 4 "random" for unique id not derived from key data
	// to simplify lookups we also store the address
	Address types.Address
	// The HD path to use to derive this key
	HdPath string
	// The mnemonic for the underlying HD wallet
	Mnemonic string
	// a nickname
	Name string
	// The bip39 passphrase for the underlying HD wallet
	Passphrase string
	// we only store privkey as pubkey/address can be derived from it
	// privkey in this struct is always in plaintext
	PrivateKey []byte
}

func DecryptKey

func DecryptKey(keyjson []byte, auth string) (*AccountKey, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

type AutoCleanMap

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

func NewAutoCleanMap

func NewAutoCleanMap(delay time.Duration) *AutoCleanMap

func (*AutoCleanMap) Delete

func (m *AutoCleanMap) Delete(key interface{})

func (*AutoCleanMap) HashKey

func (m *AutoCleanMap) HashKey(key interface{}) bool

func (*AutoCleanMap) Load

func (m *AutoCleanMap) Load(key interface{}) (interface{}, bool)

func (*AutoCleanMap) Store

func (m *AutoCleanMap) Store(key, value interface{})

type AutoCleanUnsafeMap

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

func NewAutoCleanUnsafeMap

func NewAutoCleanUnsafeMap(delay time.Duration) *AutoCleanUnsafeMap

func (*AutoCleanUnsafeMap) Delete

func (m *AutoCleanUnsafeMap) Delete(key interface{})

func (*AutoCleanUnsafeMap) HashKey

func (m *AutoCleanUnsafeMap) HashKey(key interface{}) bool

func (*AutoCleanUnsafeMap) Len

func (m *AutoCleanUnsafeMap) Len() int

func (*AutoCleanUnsafeMap) Load

func (m *AutoCleanUnsafeMap) Load(key interface{}) (interface{}, bool)

func (*AutoCleanUnsafeMap) Store

func (m *AutoCleanUnsafeMap) Store(key, value interface{})

type CombinedLogger

type CombinedLogger struct {
	// contains filtered or unexported fields
}
var MyLogger *CombinedLogger
var TrafficLogger *CombinedLogger

func NewDefaultLogger

func NewDefaultLogger(filepath string, enableStd, enableFile bool) *CombinedLogger

func NewLogger

func NewLogger(filepath string, enableStd, enableFile bool) *CombinedLogger

func NewTrafficLogger

func NewTrafficLogger(filePath string, enableStd, enableFile bool) *CombinedLogger

func (*CombinedLogger) ErrorLog

func (l *CombinedLogger) ErrorLog(v ...interface{})

func (*CombinedLogger) Log

func (l *CombinedLogger) Log(level LogLevel, v ...interface{})

func (*CombinedLogger) LogDepth

func (l *CombinedLogger) LogDepth(level LogLevel, calldepth int, v ...interface{})

func (*CombinedLogger) SetEnablefile

func (l *CombinedLogger) SetEnablefile(b bool)

func (*CombinedLogger) SetEnablestd

func (l *CombinedLogger) SetEnablestd(b bool)

func (*CombinedLogger) SetLogLevel

func (l *CombinedLogger) SetLogLevel(lv LogLevel)

SetLogLevel

type ErrUndefined

type ErrUndefined int32

ErrUndefined

func (ErrUndefined) Error

func (e ErrUndefined) Error() string

type KeyStorePassphrase

type KeyStorePassphrase struct {
	KeysDirPath string
	ScryptN     int
	ScryptP     int
}

func GetKeyStorePassphrase

func GetKeyStorePassphrase(keysDirPath string) KeyStorePassphrase

func (KeyStorePassphrase) StoreKey

func (ks KeyStorePassphrase) StoreKey(filename string, key *AccountKey, auth string) error

type LogLevel

type LogLevel int
const (
	Detail LogLevel = 1
	Debug  LogLevel = 10
	Info   LogLevel = 20
	Warn   LogLevel = 30
	Error  LogLevel = 40
	Fatal  LogLevel = 50
)

log level

type LogMsg

type LogMsg struct {
	Msg string `json:"msg"`
}

type Logger

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

func GetRpcLoggerByReqId

func GetRpcLoggerByReqId(id int64) *Logger

func GetRpcLoggerByTerminalId

func GetRpcLoggerByTerminalId(id string) *Logger

func (*Logger) GetLevelString

func (l *Logger) GetLevelString(lv LogLevel) string

GetLevelString

func (*Logger) Log

func (l *Logger) Log(level LogLevel, v ...interface{})

func (*Logger) LogDepth

func (l *Logger) LogDepth(level LogLevel, calldepth int, v ...interface{})

func (*Logger) SetEnabled

func (l *Logger) SetEnabled(b bool)

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(lv LogLevel)

SetLogLevel

type MyUnsafeValue

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

type MyValue

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

type Url

type Url struct {
	Scheme   string
	Host     string
	Port     string
	Path     string
	RawQuery string
}

func ParseUrl

func ParseUrl(url string) (*Url, error)

func (*Url) String

func (url *Url) String(withScheme, withPort, withPath, withRawQuery bool) string

Directories

Path Synopsis
math
Package math provides integer math utilities.
Package math provides integer math utilities.
rlp
Package rlp implements the RLP serialization format.
Package rlp implements the RLP serialization format.
sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

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