예제 #1
0
파일: bftcosi.go 프로젝트: dedis/cothority
// NewBFTCoSiProtocol returns a new bftcosi struct
func NewBFTCoSiProtocol(n *onet.TreeNodeInstance, verify VerificationFunction) (*ProtocolBFTCoSi, error) {
	// initialize the bftcosi node/protocol-instance
	bft := &ProtocolBFTCoSi{
		TreeNodeInstance: n,
		collectStructs: collectStructs{
			prepare: cosi.NewCosi(n.Suite(), n.Private(), n.Roster().Publics()),
			commit:  cosi.NewCosi(n.Suite(), n.Private(), n.Roster().Publics()),
		},
		verifyChan:           make(chan bool),
		VerificationFunction: verify,
		threshold:            (len(n.Tree().List()) + 1) * 2 / 3,
		Msg:                  make([]byte, 0),
		Data:                 make([]byte, 0),
	}

	idx, _ := n.Roster().Search(bft.ServerIdentity().ID)
	bft.index = idx

	// Registering channels.
	err := bft.RegisterChannels(&bft.announceChan,
		&bft.challengePrepareChan, &bft.challengeCommitChan,
		&bft.commitChan, &bft.responseChan)
	if err != nil {
		return nil, err
	}

	n.OnDoneCallback(bft.nodeDone)

	return bft, nil
}
예제 #2
0
// NewBroadcastProtocol returns a new Broadcast protocol
func NewBroadcastProtocol(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error) {
	b := &Broadcast{
		TreeNodeInstance: n,
		tnIndex:          -1,
	}
	for i, tn := range n.Tree().List() {
		if tn.ID == n.TreeNode().ID {
			b.tnIndex = i
		}
	}
	if b.tnIndex == -1 {
		return nil, errors.New("Didn't find my TreeNode in the Tree")
	}
	err := n.RegisterHandler(b.handleContactNodes)
	if err != nil {
		return nil, err
	}
	err = n.RegisterHandler(b.handleDone)
	if err != nil {
		return nil, err
	}
	return b, nil
}
예제 #3
0
파일: pbft.go 프로젝트: dedis/cothority
// NewProtocol returns a new pbft protocol
func NewProtocol(n *onet.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
}