pbft

package
v0.0.0-...-215cb89 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockInterval      = 5
	NullRequestTime    = 2
	ViewChangeInterval = 60
)

Variables

View Source
var (
	CandidateLack = errors.New("the parameter candidate must be needed")
	NotCandidate  = errors.New("the address of server is not a candidate")
)

Functions

func BroadcastPostInfo

func BroadcastPostInfo(message []byte, infos []*NodeInfo, url string, self bool)

func ChangeView

func ChangeView()

some error occurs from current primary, try to change view to next candidate

func NewBlock

func NewBlock()

Types

type NodeInfo

type NodeInfo struct {
	Ip   string
	Addr cryptoType.Address
}

type Pbft

type Pbft struct {
	// config of current code
	NodeID        uint64            `json:"node_id"`
	CandidateInfo []*NodeInfo       `json:"candidate_info"`
	Sk            *ecdsa.PrivateKey `json:"-"`
	Host          string            `json:"host"`
	Port          string            `json:"port"`

	// pbft consensus status
	N          uint64 `json:"n"`           // the number of total nodes
	F          uint64 `json:"f"`           // the limit number of malicious nodes
	ViewID     uint64 `json:"view_id"`     // view id
	NewViewID  uint64 `json:"new_view_id"` // next view id
	ResendTime uint64 `json:"resend_time"` // resend time

	// pools used to store received messages in pbft
	ViewChangePool map[uint64]*commonType.Uint64Set          `json:"-"`
	ResponsePool   map[cryptoType.Hash]*commonType.Uint64Set `json:"-"`
	CommitPool     map[cryptoType.Hash]*commonType.Uint64Set `json:"-"`
	BlockPool      map[cryptoType.Hash]*types.Block          `json:"-"`

	// timers used for control process of pbft
	NullRequestTimer      *commonType.MyTimer `json:"-"` // change view when null request received in an interval
	NewBlockTimer         *commonType.MyTimer `json:"-"` // create/wait for new block every 1 min
	ViewChangeTimer       *commonType.MyTimer `json:"-"` // view change timer used to change the primary each minute
	ViewChangeResendTimer *commonType.MyTimer `json:"-"` // resend view change
	BlockPassTimer        *commonType.MyTimer `json:"-"` // change view when time out for a new block

	ViewMu sync.Mutex `json:"-"` // mutex for view id
	// contains filtered or unexported fields
}

func InitPbftConfig

func InitPbftConfig(cfgPath string, bc *blockchain.Blockchain, logger *log.Logger) (*Pbft, error)

func (*Pbft) CheckCommit

func (pt *Pbft) CheckCommit(commit *pbftTypes.Commit) bool

func (*Pbft) CheckRequest

func (pt *Pbft) CheckRequest(req *pbftTypes.Request) bool

check the request received

func (*Pbft) CheckResponse

func (pt *Pbft) CheckResponse(resp *pbftTypes.Response) bool

check response response received

func (*Pbft) CheckViewChange

func (pt *Pbft) CheckViewChange(vc *pbftTypes.ViewChange) bool

func (*Pbft) ReceiveCommit

func (pt *Pbft) ReceiveCommit(commit *pbftTypes.Commit)

func (*Pbft) ReceiveRequest

func (pt *Pbft) ReceiveRequest(req *pbftTypes.Request)

func (*Pbft) ReceiveResponse

func (pt *Pbft) ReceiveResponse(resp *pbftTypes.Response)

process response received

func (*Pbft) ReceiveViewChange

func (pt *Pbft) ReceiveViewChange(vc *pbftTypes.ViewChange)

func (*Pbft) Start

func (pt *Pbft) Start()

func (*Pbft) StopAllTimer

func (pt *Pbft) StopAllTimer()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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