Example #1
0
func NewProtocolBlocking(node *sda.TreeNodeInstance) (sda.ProtocolInstance, error) {
	bp := &BlockingProtocol{
		TreeNodeInstance: node,
		doneChan:         make(chan bool),
		stopBlockChan:    make(chan bool),
	}

	node.RegisterChannel(&bp.Incoming)
	return bp, nil
}
Example #2
0
// NewNtreeProtocol returns the NtreeProtocol  initialized
func NewNtreeProtocol(node *sda.TreeNodeInstance) (*Ntree, error) {
	nt := &Ntree{
		TreeNodeInstance:           node,
		verifyBlockChan:            make(chan bool),
		verifySignatureRequestChan: make(chan bool),
		tempBlockSig:               new(NaiveBlockSignature),
		tempSignatureResponse:      &RoundSignatureResponse{new(NaiveBlockSignature)},
	}

	if err := node.RegisterChannel(&nt.announceChan); err != nil {
		return nt, err
	}
	if err := node.RegisterChannel(&nt.blockSignatureChan); err != nil {
		return nt, err
	}
	if err := node.RegisterChannel(&nt.roundSignatureRequestChan); err != nil {
		return nt, err
	}
	if err := node.RegisterChannel(&nt.roundSignatureResponseChan); err != nil {
		return nt, err
	}

	go nt.listen()
	return nt, nil
}
Example #3
0
// NewBFTCoSiProtocol returns a new bftcosi struct
func NewBFTCoSiProtocol(n *sda.TreeNodeInstance, verify VerificationFunction) (*ProtocolBFTCoSi, error) {
	// initialize the bftcosi node/protocol-instance
	bft := &ProtocolBFTCoSi{
		TreeNodeInstance: n,
		suite:            n.Suite(),
		prepare:          cosi.NewCosi(n.Suite(), n.Private()),
		commit:           cosi.NewCosi(n.Suite(), n.Private()),
		verifyChan:       make(chan bool),
		doneProcessing:   make(chan bool, 2),
		doneSigning:      make(chan bool, 1),
		verificationFun:  verify,
		AggregatedPublic: n.Roster().Aggregate,
		threshold:        int(2.0 * math.Ceil(float64(len(n.Tree().List()))/3.0)),
	}

	// register channels
	if err := n.RegisterChannel(&bft.announceChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.commitChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.challengePrepareChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.challengeCommitChan); err != nil {
		return nil, err
	}
	if err := n.RegisterChannel(&bft.responseChan); err != nil {
		return nil, err
	}

	n.OnDoneCallback(bft.nodeDone)

	return bft, nil
}
Example #4
0
// NewProtocol returns a new pbft protocol
func NewProtocol(n *sda.TreeNodeInstance) (*Protocol, error) {
	pbft := new(Protocol)
	pbft.state = statePrePrepare
	tree := n.Tree()
	pbft.TreeNodeInstance = n
	pbft.nodeList = tree.List()
	idx := notFound
	for i, tn := range pbft.nodeList {
		if tn.ID.Equal(n.TreeNode().ID) {
			idx = i
		}
	}
	if idx == notFound {
		panic(fmt.Sprintf("Could not find ourselves %+v in the list of nodes %+v", n, pbft.nodeList))
	}
	pbft.index = idx
	// 2/3 * #participants == threshold FIXME the threshold is actually XXX
	pbft.threshold = int(math.Ceil(float64(len(pbft.nodeList)) * 2.0 / 3.0))
	pbft.prepMsgCount = 0
	pbft.commitMsgCount = 0

	if err := n.RegisterChannel(&pbft.prePrepareChan); err != nil {
		return pbft, err
	}
	if err := n.RegisterChannel(&pbft.prepareChan); err != nil {
		return pbft, err
	}
	if err := n.RegisterChannel(&pbft.commitChan); err != nil {
		return pbft, err
	}
	if err := n.RegisterChannel(&pbft.finishChan); err != nil {
		return pbft, err
	}

	return pbft, nil
}