utils

package
v0.0.0-...-5ecede5 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2018 License: LGPL-3.0-or-later Imports: 31 Imported by: 42

Documentation

Overview

Code generated by mockery v1.0.0

Code generated by mockery v1.0.0

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ReturnCh is chan for returns
	ReturnCh chan string
	// CancelFunc is represents cancel func
	CancelFunc context.CancelFunc
	// DaemonsCount is number of daemons
	DaemonsCount int

	ErrNodesUnavailable = errors.New("All nodes unvailabale")
)
View Source
var DuplicateBlockError = errors.New("block with that time interval already exists in db")
View Source
var TimeError = errors.New("current time before first block")

Functions

func CallMethod

func CallMethod(i interface{}, methodName string) interface{}

CallMethod calls the function by its name

func Caller

func Caller(steps int) string

Caller returns the name of the latest function

func CheckSign

func CheckSign(publicKeys [][]byte, forSign string, signs []byte, nodeKeyOrLogin bool) (bool, error)

CheckSign checks the signature

func ChooseBestHost

func ChooseBestHost(ctx context.Context, hosts []string, logger *log.Entry) (string, int64, error)

best host is a host with the biggest last block ID

func CopyFileContents

func CopyFileContents(src, dst string) error

CopyFileContents copy files

func CreateDirIfNotExists

func CreateDirIfNotExists(dir string, mode os.FileMode) error

func ErrInfo

func ErrInfo(verr interface{}, additionally ...string) error

ErrInfo formats the error message

func ErrInfoFmt

func ErrInfoFmt(err string, a ...interface{}) error

ErrInfoFmt fomats the error message

func GetBlocksBody

func GetBlocksBody(host string, blockID int64, blocksCount int32, dataTypeBlockBody int64, reverseOrder bool) (chan []byte, error)

GetBlocksBody is retrieving `blocksCount` blocks bodies starting with blockID and puts them in the channel

func GetCurrentDir

func GetCurrentDir() string

GetCurrentDir returns the current directory

func GetHTTPTextAnswer

func GetHTTPTextAnswer(url string) (string, error)

GetHTTPTextAnswer returns HTTP answer as a string

func GetHostBlockID

func GetHostBlockID(host string, logger *log.Entry) (int64, error)

func GetHostPort

func GetHostPort(h string) string

func GetNodeKeys

func GetNodeKeys() (string, string, error)

GetNodeKeys returns node private key and public key

func GetParent

func GetParent() string

GetParent returns the information where the call of function happened

func LockOrDie

func LockOrDie(dir string) *flock.Flock

func MakeDirectory

func MakeDirectory(dir string) error

MakeDirectory makes directory if is not exists

func MerkleTreeRoot

func MerkleTreeRoot(dataArray [][]byte) []byte

MerkleTreeRoot rertun Merkle value

func ShellExecute

func ShellExecute(cmdline string)

ShellExecute runs cmdline

func ShuffleSlice

func ShuffleSlice(slice []string)

func TCPConn

func TCPConn(Addr string) (net.Conn, error)

TCPConn connects to the address

func TypeInt

func TypeInt(txType string) int64

TypeInt returns the identifier of the embedded transaction

func UUID

func UUID() string

Types

type BlockData

type BlockData struct {
	BlockID      int64
	Time         int64
	EcosystemID  int64
	KeyID        int64
	NodePosition int64
	Sign         []byte
	Hash         []byte
	Version      int
}

BlockData is a structure of the block's header

func ParseBlockHeader

func ParseBlockHeader(binaryBlock *bytes.Buffer, checkMaxSize bool) (BlockData, error)

ParseBlockHeader is parses block header

func (BlockData) String

func (b BlockData) String() string

type BlockTimeCalculator

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

BlockTimeCalculator calculating block generation time

func BuildBlockTimeCalculator

func BuildBlockTimeCalculator(transaction *model.DbTransaction) (BlockTimeCalculator, error)

func NewBlockTimeCalculator

func NewBlockTimeCalculator(firstBlockTime time.Time,
	blockGenerationTime, blocksGap time.Duration,
	nodesCount int64,
) BlockTimeCalculator

func (*BlockTimeCalculator) SetClock

func (btc *BlockTimeCalculator) SetClock(clock Clock) *BlockTimeCalculator

func (*BlockTimeCalculator) TimeToGenerate

func (btc *BlockTimeCalculator) TimeToGenerate(nodePosition int64) (bool, error)

func (*BlockTimeCalculator) ValidateBlock

func (btc *BlockTimeCalculator) ValidateBlock(nodePosition int64, at time.Time) (bool, error)

type Cert

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

func ParseCert

func ParseCert(b []byte) (c *Cert, err error)

func (*Cert) EqualBytes

func (c *Cert) EqualBytes(bs ...[]byte) bool

func (*Cert) Validate

func (c *Cert) Validate(pem []byte) error

type Clock

type Clock interface {
	Now() time.Time
}

Clock represents interface of clock

type ClockWrapper

type ClockWrapper struct {
}

ClockWrapper represents wrapper of clock

func (*ClockWrapper) Now

func (cw *ClockWrapper) Now() time.Time

Now returns current time

type MockClock

type MockClock struct {
	mock.Mock
}

MockClock is an autogenerated mock type for the Clock type

func (*MockClock) Now

func (_m *MockClock) Now() time.Time

Now provides a mock function with given fields:

Directories

Path Synopsis
MIT License
MIT License

Jump to

Keyboard shortcuts

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