twelve

package module
v0.0.0-...-b592234 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 23 Imported by: 1

README

twelve

Judge of the hotu network. Through multiple nodes and time rotation to switch the identity of the judge, the execution of distributed trial.

Documentation

Index

Constants

View Source
const (
	DefaultExpectVoteCount   = 12
	DefaultExpectVoteCountRd = 12
	DefaultExpectTimeout     = 3600 * time.Second
)
View Source
const (
	LetterType    kt.Type = "HOTU.12.LETTER"
	LetterVersion         = kt.DefaultVersion
)
View Source
const (
	ErrInvalidLetter = "Invalid Letter"
)
View Source
const (
	FirstHash = "#"
)
View Source
const (
	HeadTxHash = "$"
)
View Source
const (
	NotifierMsgBufSize = 102400
)
View Source
const TxCangCount = 100

Variables

This section is empty.

Functions

func ArrowVerify

func ArrowVerify(t Arrow) *errors.Error

func ExpectID

func ExpectID(peerID string, hash string, forArrow Arrow) string

func IsHead

func IsHead(hash string) bool

func TypeVerify

func TypeVerify(t Type) *errors.Error

Types

type Arrow

type Arrow int32
const (
	RequestArrow    Arrow = 1
	PrepareArrow    Arrow = 2
	CommittedArrow  Arrow = 3
	ConfirmedArrow  Arrow = 4
	InvariableArrow Arrow = 999999999
)

func (Arrow) S

func (a Arrow) S() string

type ConsensusPayload

type ConsensusPayload struct {
	Tx         kt.Hash `json:"tx"`
	Invariable bid.BID `json:"i"`
	Pre        kt.KID  `json:"pre"`
}

type Expect

type Expect struct {
	ID     string `json:"id"`
	Expect uint32 `json:"expect"`
	// contains filtered or unexported fields
}

func NewExpect

func NewExpect(id string, expect int) *Expect

func (*Expect) IsEnd

func (e *Expect) IsEnd() bool

func (*Expect) Reply

func (e *Expect) Reply(peerID string)

func (*Expect) SetState

func (e *Expect) SetState(s ExpectState)

func (*Expect) Waiting

func (e *Expect) Waiting(doFunc func() *errors.Error, onFunc func()) bool

type ExpectFactory

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

func NewExpectFactory

func NewExpectFactory() *ExpectFactory

func (*ExpectFactory) Build

func (ef *ExpectFactory) Build(peerID string, hash string, forArrow Arrow, expect int) *Expect

func (*ExpectFactory) GetOrBuild

func (ef *ExpectFactory) GetOrBuild(peerID string, hash string, forArrow Arrow, expect int) (*Expect, bool, *errors.Error)

func (*ExpectFactory) MustGet

func (ef *ExpectFactory) MustGet(peerID string, hash string, forArrow Arrow) (*Expect, *errors.Error)

func (*ExpectFactory) StartGC

func (ef *ExpectFactory) StartGC()

type ExpectState

type ExpectState int
const (
	ExpectInit     ExpectState = 0
	ExpectWaiting  ExpectState = 1
	ExpectFinished ExpectState = 2
	ExpectTimeout  ExpectState = -1
	ExpectCanceled ExpectState = -2
)

type IListener

type IListener interface {
	OnRequest(msg *Letter) *errors.Error
	OnPrepare(msg *Letter) *errors.Error
	OnCommitted(msg *Letter) *errors.Error
	OnConfirmed(msg *Letter) *errors.Error
	OnInvariable(msg *Letter) *errors.Error
}

type ITwelveListener

type ITwelveListener interface {
	On(letter *Letter) *errors.Error
}

type ITwelveNode

type ITwelveNode interface {
	Register(listener ITwelveListener)
	Notify(letter *Letter) *errors.Error
	Node() *nd.Node
}

type ImmutableTx

type ImmutableTx struct {
	Hash   string
	Letter *Letter
	Pre    string
	Height int64
}

type Job

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

type JobDict

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

func NewJobDict

func NewJobDict() *JobDict

type Letter

type Letter struct {
	Hash      kt.Hash       `json:"h"`
	Arrow     Arrow         `json:"a"`
	Type      kt.Type       `json:"t"`
	Version   kt.Version    `json:"v"`
	Chain     *kt.Chain     `json:"c"`
	Payload   []byte        `json:"p"`
	From      nd.ID         `json:"f"`
	Signature *kt.Signature `json:"s"`
}

func NewLetter

func NewLetter(chain *kt.Chain, arrow Arrow) *Letter

func (*Letter) GetConsensus

func (l *Letter) GetConsensus() (*ConsensusPayload, *errors.Error)

func (*Letter) GetTx

func (l *Letter) GetTx() (*kt.Tx, *errors.Error)

func (*Letter) Sign

func (l *Letter) Sign(pri ki.PRI) *errors.Error

func (*Letter) ToBytes

func (l *Letter) ToBytes() ([]byte, *errors.Error)

func (*Letter) Verify

func (l *Letter) Verify() *errors.Error

func (*Letter) WithConsensus

func (l *Letter) WithConsensus(cp *ConsensusPayload) *errors.Error

func (*Letter) WithTx

func (l *Letter) WithTx(tx *kt.Tx) *errors.Error

type Line

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

func NewLine

func NewLine(letter *Letter) *Line

func (*Line) RunOrRegister

func (line *Line) RunOrRegister(letter *Letter, runFunc func(letter *Letter) *errors.Error) *errors.Error

type LineFactory

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

func NewLineFactory

func NewLineFactory() *LineFactory

func (*LineFactory) Exists

func (lf *LineFactory) Exists(inv bid.BID) bool

func (*LineFactory) MustGet

func (lf *LineFactory) MustGet(letter *Letter) *Line

type Lock

type Lock = kt.KID
const (
	UnLock Lock = "?"
)

type MemTwelveListenerBus

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

type MemTwelveNode

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

func NewMemTwelveNode

func NewMemTwelveNode(bus *MemTwelveListenerBus, node *nd.Node) *MemTwelveNode

func (*MemTwelveNode) Node

func (m *MemTwelveNode) Node() *nd.Node

func (*MemTwelveNode) Notify

func (m *MemTwelveNode) Notify(letter *Letter) *errors.Error

func (*MemTwelveNode) Register

func (m *MemTwelveNode) Register(listener ITwelveListener)

type Message

type Message struct {
	Type      Type    `json:"t"`
	Version   Version `json:"v"`
	ID        string  `json:"i"`
	Nonce     int64   `json:"n"`
	Timestamp int64   `json:"tp"`
	Payload   []byte  `json:"pd"`
	Signature string  `json:"s"`
	Peer      *Peer   `json:"pr"`
	// contains filtered or unexported fields
}

func MessageOf

func MessageOf(byteData []byte) (*Message, *errors.Error)

func NewMessage

func NewMessage(t Type, payload Payload, peer *Peer, pri ki.PRI) (*Message, *errors.Error)

func (*Message) GetReplyPayload

func (msg *Message) GetReplyPayload() (*ReplyPayload, *errors.Error)

func (*Message) GetRequestPayload

func (msg *Message) GetRequestPayload() (*RequestPayload, *errors.Error)

func (*Message) SignVerify

func (msg *Message) SignVerify() (bool, *errors.Error)

func (*Message) ToBytes

func (msg *Message) ToBytes() ([]byte, *errors.Error)

type Notifier

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

func NewNotifier

func NewNotifier(node ITwelveNode) *Notifier

func (*Notifier) BindListener

func (n *Notifier) BindListener(listener IListener)

func (*Notifier) Listening

func (n *Notifier) Listening()

func (*Notifier) Notify

func (n *Notifier) Notify(letter *Letter) *errors.Error

func (*Notifier) On

func (n *Notifier) On(letter *Letter) *errors.Error

type Option

type Option struct {
	Expect int `json:"expect"`
}

type Payload

type Payload interface {
	ToBytes() ([]byte, *errors.Error)
}

type Peer

type Peer struct {
	ID  string `json:"i"`
	PUB ki.PUB `json:"p"`
}

func PeerOf

func PeerOf(p *pr.Peer) *Peer

func (*Peer) S

func (peer *Peer) S() string

func (*Peer) Verify

func (peer *Peer) Verify() *errors.Error

type Queue

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

func NewQueue

func NewQueue(vnID vn.ID, chain kt.Chain) (*Queue, *errors.Error)

func (*Queue) Append

func (q *Queue) Append(letter *Letter) (*Tx, *errors.Error)

func (*Queue) Confirm

func (q *Queue) Confirm(hash string) (*ImmutableTx, *errors.Error)

func (*Queue) Exists

func (q *Queue) Exists(hash string) (bool, *errors.Error)

func (*Queue) ImmutableList

func (q *Queue) ImmutableList(lstHash string, limit pagination.Limit) ([]*ImmutableTx, string, *errors.Error)

func (*Queue) ImmutableMustGet

func (q *Queue) ImmutableMustGet(hash string) (*ImmutableTx, *errors.Error)

func (*Queue) List

func (q *Queue) List(lstHash string, limit pagination.Limit) ([]*Tx, string, *errors.Error)

func (*Queue) MustGet

func (q *Queue) MustGet(hash string) (*Tx, *errors.Error)

func (*Queue) Tail

func (q *Queue) Tail() (*Tx, *errors.Error)

type ReplyPayload

type ReplyPayload struct {
	ID string `json:"i"` // Request ID
}

func ReplyPayloadOf

func ReplyPayloadOf(byteData []byte) (*ReplyPayload, *errors.Error)

func (*ReplyPayload) ToBytes

func (p *ReplyPayload) ToBytes() ([]byte, *errors.Error)

func (*ReplyPayload) Verify

func (p *ReplyPayload) Verify() *errors.Error

type Request

type Request struct {
	ID        string `json:"i"`
	Signature string `json:"s"`
}

func (*Request) Verify

func (req *Request) Verify() *errors.Error

type RequestPayload

type RequestPayload struct {
	Action    string `json:"a"`
	Parameter []byte `json:"p"`
	// contains filtered or unexported fields
}

func RequestPayloadOf

func RequestPayloadOf(byteData []byte) (*RequestPayload, *errors.Error)

func (*RequestPayload) GetHash

func (p *RequestPayload) GetHash() string

func (*RequestPayload) ToBytes

func (p *RequestPayload) ToBytes() ([]byte, *errors.Error)

func (*RequestPayload) Verify

func (p *RequestPayload) Verify() *errors.Error

type Rope

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

func NewRope

func NewRope(chain *kt.Chain) (*Rope, *errors.Error)

func (*Rope) BufExists

func (r *Rope) BufExists(hash kt.Hash, callback func(exists bool)) *errors.Error

func (*Rope) BufMustGet

func (r *Rope) BufMustGet(hash kt.Hash, callback func(txM *Tx)) *errors.Error

func (*Rope) Confirm

func (r *Rope) Confirm(hash kt.Hash, callback func(knot *kt.Knot)) *errors.Error

func (*Rope) PostTie

func (r *Rope) PostTie(letter *Letter, callback func(txM *Tx)) *errors.Error

func (*Rope) Tail

func (r *Rope) Tail(callback func(tail *kt.Knot))

type State

type State int8
const (
	Committed State = 1
	Pending   State = 2
	Confirmed State = 9
)

func (State) IsConfirmed

func (s State) IsConfirmed() bool

type SyncDoCheckFunc

type SyncDoCheckFunc func(letter *Letter) bool

type SyncDoNotifyFunc

type SyncDoNotifyFunc func() *errors.Error

type SyncDoSyncFunc

type SyncDoSyncFunc func(letter *Letter) *errors.Error

type Syncer

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

func NewSyncer

func NewSyncer(
	vnID vn.ID,
	chain kt.Chain,
	doCheckFunc SyncDoCheckFunc,
	doSyncFunc SyncDoSyncFunc,
	doNotifyFunc SyncDoNotifyFunc,
) *Syncer

func (*Syncer) On

func (sync *Syncer) On(letter *Letter) *errors.Error

func (*Syncer) Startup

func (sync *Syncer) Startup()

type Twelve

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

func NewTwelve

func NewTwelve(
	vnID vn.ID,
	chain kt.Chain,
	twelveNode ITwelveNode,
	option *Option,
) (*Twelve, *errors.Error)

func (*Twelve) ImmutableList

func (tw *Twelve) ImmutableList(lstHash string, limit pagination.Limit) ([]*ImmutableTx, string, *errors.Error)

func (*Twelve) List

func (tw *Twelve) List(lstHash string, limit pagination.Limit) ([]*Tx, string, *errors.Error)

func (*Twelve) OnCommitted

func (tw *Twelve) OnCommitted(letter *Letter) *errors.Error

func (*Twelve) OnConfirmed

func (tw *Twelve) OnConfirmed(letter *Letter) *errors.Error

func (*Twelve) OnInvariable

func (tw *Twelve) OnInvariable(letter *Letter) *errors.Error

func (*Twelve) OnPrepare

func (tw *Twelve) OnPrepare(letter *Letter) *errors.Error

func (*Twelve) OnRequest

func (tw *Twelve) OnRequest(letter *Letter) *errors.Error

func (*Twelve) Start

func (tw *Twelve) Start()

func (*Twelve) Tail

func (tw *Twelve) Tail() (*Tx, *errors.Error)

type Tx

type Tx struct {
	Hash       kt.Hash      `json:"hx"`
	State      State        `json:"s"`
	Chain      *kt.Chain    `json:"c"`
	Invariable bid.BID      `json:"i"`
	Timestamp  kt.Timestamp `json:"t"`
	Signer     ki.ADR       `json:"signer"`
	Signature  []byte       `json:"signature"`
	Pre        kt.KID       `json:"p"`
	Height     kt.Height    `json:"h"`
	// contains filtered or unexported fields
}

func HeadTx

func HeadTx() *Tx

func TxOf

func TxOf(byteData []byte) (*Tx, *errors.Error)

func (*Tx) Before

func (tx *Tx) Before(t kt.Timestamp) bool

func (*Tx) Confirm

func (tx *Tx) Confirm()

func (*Tx) Immutable

func (tx *Tx) Immutable() *ImmutableTx

func (*Tx) ImmutableHash

func (tx *Tx) ImmutableHash() string

func (*Tx) IsHead

func (tx *Tx) IsHead() bool
func (tx *Tx) Link(letter *Letter) (*Tx, *errors.Error)

func (*Tx) Nxt

func (tx *Tx) Nxt(letter *Letter) *Tx

type TxCang

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

func NewTxCang

func NewTxCang(name string, path string) (*TxCang, *errors.Error)

func (*TxCang) CCollection

func (tc *TxCang) CCollection(hash string) *cang.Collection

CCollection Get Chain Collection

func (*TxCang) QCollection

func (tc *TxCang) QCollection(hash string) *cang.Collection

QCollection Get Queue Collection

type TxLink struct {
	// contains filtered or unexported fields
}
func NewTxLink(chain *kt.Chain) (*TxLink, *errors.Error)

func (*TxLink) Get

func (link *TxLink) Get(hx kt.Hash, callback func(tn *TxNode)) *errors.Error

func (*TxLink) Inject

func (link *TxLink) Inject(tx *kt.Tx) (TxNode, *errors.Error)

type TxNode

type TxNode struct {
	Tx    *kt.Tx  `json:"tx"`
	Pre   kt.Hash `json:"pre"`
	Nxt   kt.Hash `json:"nxt"`
	State State   `json:"state"`
}

type Type

type Type int32
const (
	RequestMessage   Type = 1
	PrepareMessage   Type = 2
	CommittedMessage Type = 3
	ConfirmedMessage Type = 4
)

type Version

type Version int32
const (
	DefaultVersion Version = 1
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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