コード例 #1
0
ファイル: ntree.go プロジェクト: dedis/cothority
// NewNtreeProtocol returns the NtreeProtocol  initialized
func NewNtreeProtocol(node *onet.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
}
コード例 #2
0
ファイル: cosi.go プロジェクト: dedis/cothority
// NewProtocol returns a ProtocolCosi with the node set with the right channels.
// Use this function like this:
// ```
// round := NewRound****()
// fn := func(n *onet.Node) onet.ProtocolInstance {
//      pc := NewProtocolCosi(round,n)
//		return pc
// }
// onet.RegisterNewProtocolName("cothority",fn)
// ```
func NewProtocol(node *onet.TreeNodeInstance) (onet.ProtocolInstance, error) {
	var err error
	// XXX just need to take care to take the global list of cosigners once we
	// do the exception stuff
	publics := make([]abstract.Point, len(node.Roster().List))
	for i, e := range node.Roster().List {
		publics[i] = e.Public
	}

	c := &CoSi{
		cosi:             cosi.NewCosi(node.Suite(), node.Private(), publics),
		TreeNodeInstance: node,
		done:             make(chan bool),
		tempCommitLock:   new(sync.Mutex),
		tempResponseLock: new(sync.Mutex),
	}
	// Register the channels we want to register and listens on

	if err := node.RegisterChannel(&c.announce); err != nil {
		return c, err
	}
	if err := node.RegisterChannel(&c.commit); err != nil {
		return c, err
	}
	if err := node.RegisterChannel(&c.challenge); err != nil {
		return c, err
	}
	if err := node.RegisterChannel(&c.response); err != nil {
		return c, err
	}

	return c, err
}
コード例 #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
}
コード例 #4
0
ファイル: byzcoin.go プロジェクト: dedis/cothority
// NewByzCoinProtocol returns a new byzcoin struct
func NewByzCoinProtocol(n *onet.TreeNodeInstance) (*ByzCoin, error) {
	// create the byzcoin
	bz := new(ByzCoin)
	bz.TreeNodeInstance = n
	bz.suite = n.Suite()
	bz.prepare = cosi.NewCosi(n.Suite(), n.Private())
	bz.commit = cosi.NewCosi(n.Suite(), n.Private())
	bz.verifyBlockChan = make(chan bool)
	bz.doneProcessing = make(chan bool, 2)
	bz.doneSigning = make(chan bool, 1)
	bz.timeoutChan = make(chan uint64, 1)

	//bz.endProto, _ = end.NewEndProtocol(n)
	bz.aggregatedPublic = n.Roster().Aggregate
	bz.threshold = int(math.Ceil(float64(len(bz.Tree().List())) / 3.0))
	bz.viewChangeThreshold = int(math.Ceil(float64(len(bz.Tree().List())) * 2.0 / 3.0))

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

	n.OnDoneCallback(bz.nodeDone)

	go bz.listen()
	return bz, nil
}