network

package
v0.0.0-...-6a0d59a Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

TODO: secure connection such as HTTPS, or manual implementation from Section 5.2.2 Key Exchanges on TOCS.

Index

Constants

View Source
const ConsensusDeadline = time.Millisecond * 100

Deadline for the consensus state.

View Source
const CoolingTime = time.Millisecond * 2

Cooling time to escape frequent error, or message sending retry.

View Source
const CoolingTotalErrMsg = 5

Number of error messages to start cooling.

View Source
const MaxOutboundConnection = 1000

Number of outbound connection for a node.

View Source
const NumResolveMsgGo = 6

Number of parallel goroutines for resolving messages.

Variables

This section is empty.

Functions

func GetPrePrepareForNewview

func GetPrePrepareForNewview(nextviewID int64, sequenceid int64, digest string) *consensus.PrePrepareMsg

func LogMsg

func LogMsg(msg interface{})

func LogStage

func LogStage(stage string, isDone bool)

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)

serveWs handles websocket requests from the peer.

Types

type Client

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

Client is a middleman between the websocket connection and the hub.

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub() *Hub

type MsgOut

type MsgOut struct {
	Path string
	Msg  []byte
}

Outbound message

type MsgPair

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

type Node

type Node struct {
	MyInfo         *NodeInfo
	PrivKey        *ecdsa.PrivateKey
	NodeTable      []*NodeInfo
	View           *View
	States         map[int64]consensus.PBFT // key: sequenceID, value: state
	VCStates       map[int64]*consensus.VCState
	CommittedMsgs  []*consensus.RequestMsg // kinda block.
	TotalConsensus int64                   // atomic. number of consensus started so far.
	IsViewChanging bool

	// Channels
	MsgEntrance     chan interface{}
	MsgDelivery     chan interface{}
	MsgExecution    chan *MsgPair
	MsgOutbound     chan *MsgOut
	MsgError        chan []error
	ViewMsgEntrance chan interface{}

	// Mutexes for preventing from concurrent access
	StatesMutex   sync.RWMutex
	VCStatesMutex sync.RWMutex

	// Saved checkpoint messages on this node
	// key: sequenceID, value: map(key: nodeID, value: checkpointMsg)
	CheckPointMutex   sync.RWMutex
	CheckPointMsgsLog map[int64]map[string]*consensus.CheckPointMsg

	// The stable checkpoint that 2f + 1 nodes agreed
	StableCheckPoint int64
}

func NewNode

func NewNode(myInfo *NodeInfo, nodeTable []*NodeInfo, viewID int64, decodePrivKey *ecdsa.PrivateKey) *Node

func (*Node) Broadcast

func (node *Node) Broadcast(msg interface{}, path string)

Broadcast marshalled message.

func (*Node) CheckPoint

func (node *Node) CheckPoint(msg *consensus.CheckPointMsg)

func (*Node) CheckPointMissCheck

func (node *Node) CheckPointMissCheck(sequenceID int64) bool

Check the COMMIT messages, for given `periodCheckPoint` consecutive sequence numbers, are enough including the messages for the current node.

func (*Node) Checkpointchk

func (node *Node) Checkpointchk(state consensus.PBFT) bool

Check the CHECKPOINT messages for given sequence number are enough including the message for the current node.

func (*Node) CreateSetP

func (node *Node) CreateSetP() map[int64]*consensus.SetPm

Create a set of PreprepareMsg and PrepareMsgs for each sequence number.

func (*Node) CreateViewChangeMsg

func (node *Node) CreateViewChangeMsg(setp map[int64]*consensus.SetPm) *consensus.ViewChangeMsg

func (*Node) FillHole

func (node *Node) FillHole(newviewMsg *consensus.NewViewMsg)

func (*Node) GetCheckPoint

func (node *Node) GetCheckPoint(CheckPointMsg *consensus.CheckPointMsg) error

func (*Node) GetCommit

func (node *Node) GetCommit(state consensus.PBFT, commitMsg *consensus.VoteMsg)

func (*Node) GetNewView

func (node *Node) GetNewView(newviewMsg *consensus.NewViewMsg) error

func (*Node) GetPrePrepare

func (node *Node) GetPrePrepare(state consensus.PBFT, prePrepareMsg *consensus.PrePrepareMsg)

func (*Node) GetPrepare

func (node *Node) GetPrepare(state consensus.PBFT, prepareMsg *consensus.VoteMsg)

func (*Node) GetReply

func (node *Node) GetReply(msg *consensus.ReplyMsg)

func (*Node) GetReq

func (node *Node) GetReq(reqMsg *consensus.RequestMsg)

When REQUEST message is broadcasted, start consensus.

func (*Node) GetViewChange

func (node *Node) GetViewChange(viewchangeMsg *consensus.ViewChangeMsg)

func (*Node) StartViewChange

func (node *Node) StartViewChange()

type NodeInfo

type NodeInfo struct {
	NodeID string `json:"nodeID"`
	Url    string `json:"url"`
	PubKey *ecdsa.PublicKey
}

type Server

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

func NewServer

func NewServer(nodeID string, nodeTable []*NodeInfo, viewID int64, decodePrivKey *ecdsa.PrivateKey) *Server

func (*Server) DialOtherNodes

func (server *Server) DialOtherNodes()

func (*Server) Start

func (server *Server) Start()

type View

type View struct {
	ID      int64
	Primary *NodeInfo
}

Jump to

Keyboard shortcuts

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