types

package
v0.0.0-...-bc0e287 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IDByteLength   = 8
	TickIDByteLen  = 8
	TickIncByteLen = 1
	TickByteLen    = 9
	IndexShift     = 1
)
View Source
const (
	ErrDecodeByte32  = "decode of Byte32 failed"
	ErrDecodeByte8   = "decode of Byte8 failed"
	ErrDecodeByte    = "decode of ByteArray failed"
	ErrDecodeTime    = "decode of Time failed"
	ErrDecodeSign520 = "decode of Signature failed"
	ErrDecodePart    = "decode of Partition failed"
	ErrDecodeToken   = "decode of Token failed"

	ErrInvalidTime = "object Time is invalid"
	ErrSizeByte32  = "size of Byte32 is invalid"
	ErrSizeByte8   = "size of Byte8 is invalid"
	ErrSizeByte    = "size of ByteArray is invalid"
	ErrSizeSign520 = "size of Sign520 is invalid"

	ErrGetToken = "failed to get Token from request header"
	ErrGetTime  = "failed to get Time from request header"
	ErrGetID    = "failed to get ID from request header"
	ErrGetSign  = "failed to get Signature from request header"
)

Variables

This section is empty.

Functions

func CheckSignature

func CheckSignature(msg []byte, sign Sign520) (bool, error)

func CheckStringSignature

func CheckStringSignature(msg []byte, strSign string) (bool, error)

func Cpl

func Cpl(p1, p2 []byte) int

func DecodeDefaultPrivateKey

func DecodeDefaultPrivateKey() (*ecdsa.PrivateKey, error)

func DecodeDefaultPublicKey

func DecodeDefaultPublicKey() (*ecdsa.PublicKey, error)

func DecryptFromChunks

func DecryptFromChunks(data [][]byte) ([]byte, error)

func Distance

func Distance(p1, p2 []byte) *big.Int

func EncryptToParts

func EncryptToParts(message []byte, size int) ([][]byte, error)

func FromHex

func FromHex(s string, byteLen int) ([]byte, error)

func ID256ToHex

func ID256ToHex(s [32]byte) string

func Normalize

func Normalize(source uint64, bitSizePrefix uint8) float64

func OneCount

func OneCount(p1, p2 []byte) int

func Random

func Random() int

func XOR

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

func ZeroPrefixLen

func ZeroPrefixLen(id []byte) int

Types

type BaseMessage

type BaseMessage struct {
	ID   ID64
	Time Time
	Type string
	Data []byte
	Sign Sign520
}

func UnmarshalBaseMessage

func UnmarshalBaseMessage(data []byte) (bm BaseMessage, err error)

type Bitmap256

type Bitmap256 [8]byte

func (*Bitmap256) Clear

func (b *Bitmap256) Clear(i byte)

func (*Bitmap256) IsSet

func (b *Bitmap256) IsSet(i byte) bool

func (*Bitmap256) Set

func (b *Bitmap256) Set(i byte)

func (*Bitmap256) Sets

func (b *Bitmap256) Sets(xs ...byte)

type Block

type Block struct {
	ID      ID64
	ID256   ID256
	BitSize []uint8
	Status  BlockStatus
}

type BlockStatus

type BlockStatus byte
const (
	BlockStatusNew BlockStatus = iota
	BlockStatusHead
	BlockStatusTail
	BlockStatusOld
)

func (BlockStatus) IsActive

func (b BlockStatus) IsActive() bool

func (BlockStatus) String

func (b BlockStatus) String() string

type ECKey

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

func HexToECKey

func HexToECKey(hex string) (*ECKey, error)

func (*ECKey) Bytes

func (k *ECKey) Bytes() []byte

func (*ECKey) ECPrivateKey

func (k *ECKey) ECPrivateKey() *ecdsa.PrivateKey

func (*ECKey) Pub

func (k *ECKey) Pub() (pub PubKey)

type ID256

type ID256 [32]byte

func GenerateID256FromSource

func GenerateID256FromSource(source []byte) ID256

func GenerateSHA

func GenerateSHA() ID256

func ID256FromHex

func ID256FromHex(s string) (id ID256, err error)

func (ID256) Bytes

func (i ID256) Bytes() []byte

func (ID256) Hex

func (i ID256) Hex() string

func (ID256) ID64

func (i ID256) ID64() (id ID64)

func (ID256) IsEmpty

func (i ID256) IsEmpty() bool

func (ID256) Uint64

func (i ID256) Uint64() uint64

type ID64

type ID64 [8]byte

func ID64FromHex

func ID64FromHex(s string) (id ID64, err error)

func (ID64) Bytes

func (i ID64) Bytes() []byte

func (ID64) Equal

func (i ID64) Equal(other ID64) bool

func (ID64) Hex

func (i ID64) Hex() string

func (ID64) Uint64

func (i ID64) Uint64() uint64

type KeySize

type KeySize int
const (
	Key256 KeySize = iota
	Key512
)

func (KeySize) Len

func (k KeySize) Len() int

type NetMessage

type NetMessage struct {
	ID    ID64
	Addr  ID64
	Time  Time
	Token Token
	Data  []byte
	Sign  []Sign520
}

func (*NetMessage) Encode

func (msg *NetMessage) Encode() []byte

type NetPartition

type NetPartition struct {
	Size byte
}

type Peer

type Peer struct {
	Pub   PubKey
	Token Token
}

func (Peer) Equal

func (p Peer) Equal(other Peer) bool

type Permission

type Permission []byte

type Precursor

type Precursor struct {
	Min uint8
	Exp uint8
}

type PubKey

type PubKey [65]byte

func (PubKey) Bytes

func (p PubKey) Bytes() []byte

func (PubKey) ID

func (p PubKey) ID() (id ID64)

func (PubKey) ID256

func (p PubKey) ID256() (id ID256)

func (*PubKey) Write

func (p *PubKey) Write(data []byte)

type Replica

type Replica struct {
	Min uint64
	Exp uint64
}

type Sign520

type Sign520 [65]byte

func SignFromHex

func SignFromHex(s string) (Sign520, error)

func (Sign520) CheckHashSignature

func (s Sign520) CheckHashSignature(hash []byte) (bool, error)

func (Sign520) CheckSignature

func (s Sign520) CheckSignature(msg []byte) (bool, error)

func (Sign520) Pub

func (s Sign520) Pub(hash []byte) (pk PubKey, err error)

func (Sign520) Sign512

func (s Sign520) Sign512() (sign [64]byte)

func (Sign520) SignWithPK

func (s Sign520) SignWithPK() (sign [65]byte)

type State

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

State should be immutable and represent single time state todo

func CreateState

func CreateState(time Time, block Block, ticks []Tick, peer Peer, key *ECKey, token Token) State

func (State) Block

func (s State) Block() Block

func (State) CommonLevel

func (s State) CommonLevel(target ID64) byte

func (State) ID

func (s State) ID() ID64

func (State) IsLocalTime

func (s State) IsLocalTime(time Time) bool

func (State) Key

func (s State) Key() *ECKey

func (State) NetPartition

func (s State) NetPartition() NetPartition

func (State) Now

func (s State) Now() Time

func (State) Peer

func (s State) Peer() Peer

func (State) TimeToHandlerID

func (s State) TimeToHandlerID(time Time) ID64

func (State) Token

func (s State) Token() Token

func (State) ValidateTime

func (s State) ValidateTime(time Time) bool

type Tick

type Tick struct {
	ID     ID64
	Inc    byte
	Level  byte
	Status TickStatus
}

type TickGlobal

type TickGlobal struct {
	ID    ID64
	Inc   byte
	Level byte
}

type TickStatus

type TickStatus byte
const (
	TickStatusNew TickStatus = iota
	TickStatusHead
	TickStatusTail
	TickStatusOld
)

func (TickStatus) IsActive

func (t TickStatus) IsActive() bool

type Time

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

func DecodeTime

func DecodeTime(src []byte) (time Time, err error)

DecodeTime src[--- addr[8] ---,--- blockId[8] ---,--- (tickId[8],tickInc[1])[9] ---, ... ]

func (Time) Addr

func (t Time) Addr() ID64

func (Time) BlockID

func (t Time) BlockID() ID64

func (Time) Encode

func (t Time) Encode() []byte

func (Time) Head

func (t Time) Head() TickGlobal

func (Time) IncHash

func (t Time) IncHash() string

func (Time) Ticks

func (t Time) Ticks() []TickGlobal

type Token

type Token [32]byte

func TokenFromHex

func TokenFromHex(s string) (token Token, err error)

func (Token) Hex

func (t Token) Hex() string

type UpdateState

type UpdateState interface {
	UpdateState(state State)
}

Jump to

Keyboard shortcuts

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