types

package
v0.0.0-...-516970c Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Account1 uint
	Me1
	Friend1
)

protocol-versions

View Source
const (
	SizeTimestamp = 12 // uint64 + uint32 (Sizeof may align with 64bit)
	SizePostfix   = common.AddressLength
	SizePttID     = common.AddressLength + SizePostfix // address-length (integrate with user-id)

	SizeSalt   = 32
	OffsetHash = 12
)
View Source
const (
	HRSeconds  = 3600
	DaySeconds = 86400
)
View Source
const (
	MaxImageWidth  = 10000
	MaxImageHeight = 10000
)

Variables

View Source
var (
	ErrInvalidID        = errors.New("invalid id")
	ErrInvalidTimestamp = errors.New("invalid timestamp")
	ErrInvalidBitVector = errors.New("invalid bit vector")

	ErrLock        = errors.New("unable to lock")
	ErrUnlock      = errors.New("unable to unlock")
	ErrClose       = errors.New("unable to close")
	ErrLockClosed  = errors.New("lock closed")
	ErrBusy        = errors.New("busy")
	ErrInvalidLock = errors.New("invalid lock")

	ErrInvalidURL = errors.New("invalid url")

	ErrAlreadyExists = errors.New("already exists")

	ErrAlreadyDeleted = errors.New("already deleted")

	ErrAlreadyPending = errors.New("already pending")

	ErrAlreadyPendingDelete = errors.New("already pending delete")

	ErrInvalidNode = errors.New("invalid node")

	ErrNotImplemented = errors.New("not implemented")

	ErrNotBool = errors.New("not bool")

	ErrNotBoolDAry = errors.New("not bool double array")

	ErrInvalidStatus = errors.New("invalid status")
)
View Source
var (
	EmptyID = PttID{}
	MaxID   = PttID{
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	}
	EmptyIDBytes = EmptyID[:]

	ZeroTimestamp = Timestamp{0, 0}

	//                       12345678901234567  123456789
	MaxTimestamp = Timestamp{99999999999999999, 999999999}

	NIterLock = 100

	OffsetSecond int64 = 0
)

id / timestamp

View Source
var GetTimestamp = func() (Timestamp, error) {
	now := time.Now().UTC()

	return TimeToTimestamp(now), nil
}
View Source
var NewSalt = func() (*Salt, error) {
	salt := &Salt{}
	rand.Read(salt[:])

	return salt, nil
}
View Source
var RandRead = func(b []byte) (int, error) {
	return rand.Read(b)
}

Functions

func Addr

func Addr(theBytes ...[]byte) []byte

func GetBoolFromInterface

func GetBoolFromInterface(v interface{}, name string) bool

func Hash

func Hash(theBytes ...[]byte) []byte

func HashToAddr

func HashToAddr(theBytes []byte) []byte

Types

type BitVector

type BitVector []uint64

func NewBitVector

func NewBitVector(L uint64) BitVector

NewBitVector returns a new BitVector of length L

func UnmarshalBitVector

func UnmarshalBitVector(theBytes []byte) (BitVector, error)

func (BitVector) Clear

func (b BitVector) Clear(N uint64)

Clear clears the bit at position N for N >= L this will access memory out of bounds of the backing array and panic

func (BitVector) Get

func (b BitVector) Get(N uint64) uint64

Get returns the bit at position N as a uint64 for N >= L this will access memory out of bounds of the backing array and panic

func (BitVector) Marshal

func (b BitVector) Marshal() ([]byte, error)

func (BitVector) PopCount

func (b BitVector) PopCount() uint64

PopCount returns the nubmer of set bits in the bit vector the algorithm for PopCount on a single 64-bit word is from 1957 due to Donald B. Gillies and Jeffrey C. P. Miller and referenced by Donald Knuth

func (BitVector) Set

func (b BitVector) Set(N uint64)

Set sets the bit at position N for N >= L this will access memory out of bounds of the backing array and panic

func (BitVector) SetWithIsNew

func (b BitVector) SetWithIsNew(N uint64) bool

Set sets the bit at position N for N >= L this will access memory out of bounds of the backing array and panic

func (BitVector) String

func (b BitVector) String() string

String outputs a string representation of the binary string with the first bit at the left note that any padding zeros are present on the right hand side

type Bool

type Bool bool

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(theByte []byte) error

type BoolDoubleArray

type BoolDoubleArray [][]Bool

func (BoolDoubleArray) MarshalJSON

func (bdary BoolDoubleArray) MarshalJSON() ([]byte, error)

func (*BoolDoubleArray) UnmarshalJSON

func (bdary *BoolDoubleArray) UnmarshalJSON(theBytes []byte) error

type Chan

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

Chan implements non-panic chan. Chan checks isClose first before passing to the channel.

func NewChan

func NewChan(n int) *Chan

NewChan initialize the chan, the default of n should be 1.

func (*Chan) Close

func (c *Chan) Close()

Close closes the chan.

Instead of really closing the channel and may cause panic, we just setup the flag.

func (*Chan) GetChan

func (c *Chan) GetChan() chan interface{}

func (*Chan) IsBusy

func (c *Chan) IsBusy() bool

func (*Chan) IsClosed

func (c *Chan) IsClosed() bool

func (*Chan) Lock

func (c *Chan) Lock()

func (*Chan) PassChan

func (c *Chan) PassChan(d interface{}) error

func (*Chan) Unlock

func (c *Chan) Unlock()

type ImgType

type ImgType uint8

image-type

const (
	ImgTypeJPEG ImgType = iota
	ImgTypeGIF
	ImgTypePNG
)

type Lock

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

func NewLock

func NewLock() *Lock

func (*Lock) Close

func (l *Lock) Close() error

func (*Lock) IsLocked

func (l *Lock) IsLocked() bool

XXX possibly unable to get accurate information

func (*Lock) TimedUnlock

func (l *Lock) TimedUnlock(nMillisecond time.Duration) error

func (*Lock) TryLock

func (l *Lock) TryLock() error

func (*Lock) TryTimedLock

func (l *Lock) TryTimedLock(nMillisecond time.Duration) error

func (*Lock) Unlock

func (l *Lock) Unlock() error

type LockMap

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

LockMap implements per-ptt-id lock

func NewLockMap

func NewLockMap(sleepTime int) (*LockMap, error)

func (*LockMap) Lock

func (l *LockMap) Lock(id *PttID) error

func (*LockMap) MustLock

func (l *LockMap) MustLock(id *PttID) (err error)

func (*LockMap) RLock

func (l *LockMap) RLock(id *PttID) error

func (*LockMap) RUnlock

func (l *LockMap) RUnlock(id *PttID) error

func (*LockMap) TryLock

func (l *LockMap) TryLock(id *PttID) error

func (*LockMap) TryRLock

func (l *LockMap) TryRLock(id *PttID) error

func (*LockMap) Unlock

func (l *LockMap) Unlock(id *PttID) error

type PttID

type PttID [SizePttID]byte

PttID is the id-representation of all applications.

PttID is constructed from PKI-framework, with priv-key and pub-key. PttID is the address-representation of pub-key.

func NewPttID

func NewPttID() (*PttID, error)

NewPttID generates new PttID.

func NewPttIDFromAddrPostfix

func NewPttIDFromAddrPostfix(addr *common.Address, postfix []byte) (*PttID, error)

NewPttIDFromAddrPostfix generates new PttID with the 1st part as the key-address and the 2nd part as postfix.

func NewPttIDFromKey

func NewPttIDFromKey(key *ecdsa.PrivateKey) (*PttID, error)

NewPttIDFromKey generates new PttID with the 1st part as the key-address and the 2nd part as random.

func NewPttIDFromKeyPostfix

func NewPttIDFromKeyPostfix(key *ecdsa.PrivateKey, postfix []byte) (*PttID, error)

NewPttIDFromKey generates new PttID with the 1st part as the key-address and the 2nd part as postfix.

func NewPttIDFromPubkeyPostfix

func NewPttIDFromPubkeyPostfix(key *ecdsa.PublicKey, postfix []byte) (*PttID, error)

NewPttIDFromPubkeyPostfix generates new PttID with the 1st part as the key-address and the 2nd part as postfix.

func NewPttIDWithPostifx

func NewPttIDWithPostifx(postfix []byte) (*PttID, error)

NewPttID generates new PttID.

func NewPttIDWithPubkeyAndRefID

func NewPttIDWithPubkeyAndRefID(key *ecdsa.PublicKey, refID *PttID) (*PttID, error)

NewPttIDWithRefID generates new PttID with the 1st part as the key-address and the 2nd part as the addr-part of refID.

func NewPttIDWithRefID

func NewPttIDWithRefID(key *ecdsa.PrivateKey, refID *PttID) (*PttID, error)

NewPttIDWithRefID generates new PttID with the 1st part as the key-address and the 2nd part as the addr-part of refID.

func UnmarshalTextPttID

func UnmarshalTextPttID(b []byte, isAllowNil bool) (*PttID, error)

func (*PttID) Clone

func (p *PttID) Clone() *PttID

func (*PttID) IsSameKey

func (p *PttID) IsSameKey(key *ecdsa.PrivateKey) bool

func (*PttID) IsSameKeyWithNodeID

func (p *PttID) IsSameKeyWithNodeID(n *discover.NodeID) bool

func (*PttID) IsSameKeyWithPttID

func (p *PttID) IsSameKeyWithPttID(p2 *PttID) bool

func (*PttID) IsSamePubKey

func (p *PttID) IsSamePubKey(key *ecdsa.PublicKey) bool

func (*PttID) Marshal

func (p *PttID) Marshal() ([]byte, error)

Serialize is used for direct request/response

func (*PttID) MarshalJSON

func (p *PttID) MarshalJSON() ([]byte, error)

func (*PttID) MarshalText

func (p *PttID) MarshalText() ([]byte, error)

func (*PttID) String

func (p *PttID) String() string

func (*PttID) Unmarshal

func (p *PttID) Unmarshal(theIDStr []byte) error

Deserialize is used for direct request/response

func (*PttID) UnmarshalJSON

func (p *PttID) UnmarshalJSON(b []byte) error

func (*PttID) UnmarshalText

func (p *PttID) UnmarshalText(b []byte) error

type RaftState

type RaftState int

RaftStatus

const (
	RaftStateFollower RaftState
	RaftStateCandidate
	RaftStateLeader
)

type Salt

type Salt [SizeSalt]byte

func (*Salt) MarshalJSON

func (s *Salt) MarshalJSON() ([]byte, error)

func (*Salt) UnmarshalJSON

func (s *Salt) UnmarshalJSON(b []byte) error

type Sig

type Sig []byte

Sig

type Status

type Status int

Status

const (
	StatusInvalid Status = iota

	StatusInit

	StatusInternalSync

	StatusInternalPending

	StatusPending

	StatusSync

	StatusToBeSynced

	StatusAlive

	StatusFailed

	// Putting intenal-deleted after alive.
	// Because it's the competition between update-object and pending-delete, which does not affect the new-object, and no dead-lock for pending-delete (referring to new-object).
	StatusInternalDeleted

	StatusInternalRevoke

	StatusInternalTransfer

	StatusInternalMigrate

	StatusInternalTerminal

	StatusPendingDeleted

	StatusPendingRevoke

	StatusPendingTransfer

	StatusPendingMigrate

	StatusPendingTerminal

	StatusDeleted

	StatusRevoked

	StatusTransferred

	StatusMigrated

	StatusTerminal
)

func StatusToDeleteStatus

func StatusToDeleteStatus(status Status, internalPendingStatus Status, pendingStatus Status, aliveStatus Status) Status

func (Status) String

func (s Status) String() string

type StatusClass

type StatusClass int
const (
	StatusClassInvalid StatusClass = iota
	StatusClassInternalPendingAlive
	StatusClassPendingAlive
	StatusClassAlive
	StatusClassFailed
	StatusClassInternalDelete
	StatusClassPendingDelete
	StatusClassInternalTerminal
	StatusClassPendingTerminal
	StatusClassDeleted
	StatusClassTerminal
)

func StatusToStatusClass

func StatusToStatusClass(status Status) StatusClass

func (StatusClass) String

func (s StatusClass) String() string

type Timestamp

type Timestamp struct {
	Ts     int64  `json:"T"` // uint64 is only for
	NanoTs uint32 `json:"NT"`
}

func MinTimestamp

func MinTimestamp(a Timestamp, b Timestamp) Timestamp

func TimeToTimestamp

func TimeToTimestamp(t time.Time) Timestamp

func UnmarshalTimestamp

func UnmarshalTimestamp(theBytes []byte) (Timestamp, error)

func (*Timestamp) IsEqMilli

func (t *Timestamp) IsEqMilli(t2 Timestamp) bool

func (*Timestamp) IsEqual

func (t *Timestamp) IsEqual(t2 Timestamp) bool

func (*Timestamp) IsLess

func (t *Timestamp) IsLess(t2 Timestamp) bool

func (*Timestamp) IsLessEqual

func (t *Timestamp) IsLessEqual(t2 Timestamp) bool

func (*Timestamp) Marshal

func (t *Timestamp) Marshal() ([]byte, error)

func (*Timestamp) NextHourTS

func (t *Timestamp) NextHourTS() Timestamp

func (*Timestamp) ToDayTimestamp

func (t *Timestamp) ToDayTimestamp() (Timestamp, Timestamp)

func (*Timestamp) ToHRTimestamp

func (t *Timestamp) ToHRTimestamp() (Timestamp, Timestamp)

func (*Timestamp) ToMilli

func (t *Timestamp) ToMilli() Timestamp

func (*Timestamp) ToMonthTimestamp

func (t *Timestamp) ToMonthTimestamp() (Timestamp, Timestamp)

func (*Timestamp) ToYearTimestamp

func (t *Timestamp) ToYearTimestamp() (Timestamp, Timestamp)

type Version

type Version uint8
const (
	InvalidVersion Version = 0
	CurrentVersion Version = 2
)

Jump to

Keyboard shortcuts

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