当前位置: 首页>>代码示例>>Golang>>正文


Golang sda.TreeNodeInstance类代码示例

本文整理汇总了Golang中github.com/dedis/cothority/sda.TreeNodeInstance的典型用法代码示例。如果您正苦于以下问题:Golang TreeNodeInstance类的具体用法?Golang TreeNodeInstance怎么用?Golang TreeNodeInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TreeNodeInstance类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewRandHound

// NewRandHound generates a new RandHound instance.
func NewRandHound(node *sda.TreeNodeInstance) (sda.ProtocolInstance, error) {

	// Setup RandHound protocol struct
	rh := &RandHound{
		TreeNodeInstance: node,
	}

	// Setup leader or peer depending on the node's location in the tree
	if node.IsRoot() {
		leader, err := rh.newLeader()
		if err != nil {
			return nil, err
		}
		rh.Leader = leader
	} else {
		peer, err := rh.newPeer()
		if err != nil {
			return nil, err
		}
		rh.Peer = peer
	}

	// Setup message handlers
	h := []interface{}{
		rh.handleI1, rh.handleR1,
		rh.handleI2, rh.handleR2,
		rh.handleI3, rh.handleR3,
		rh.handleI4, rh.handleR4,
	}
	err := rh.RegisterHandlers(h...)

	return rh, err
}
开发者ID:nikirill,项目名称:cothority,代码行数:34,代码来源:randhound.go

示例2: NewJVSS

// NewJVSS creates a new JVSS protocol instance and returns it.
func NewJVSS(node *sda.TreeNodeInstance) (sda.ProtocolInstance, error) {

	kp := &config.KeyPair{Suite: node.Suite(), Public: node.Public(), Secret: node.Private()}
	n := len(node.List())
	pk := make([]abstract.Point, n)
	for i, tn := range node.List() {
		pk[i] = tn.ServerIdentity.Public
	}
	// NOTE: T <= R <= N (for simplicity we use T = R = N; might change later)
	info := poly.Threshold{T: n, R: n, N: n}

	jv := &JVSS{
		TreeNodeInstance: node,
		keyPair:          kp,
		pubKeys:          pk,
		info:             info,
		schnorr:          new(poly.Schnorr),
		secrets:          make(map[SID]*Secret),
		ltssInit:         false,
		secretsDone:      make(chan bool, 1),
		sigChan:          make(chan *poly.SchnorrSig),
	}

	// Setup message handlers
	h := []interface{}{
		jv.handleSecInit,
		jv.handleSecConf,
		jv.handleSigReq,
		jv.handleSigResp,
	}
	err := jv.RegisterHandlers(h...)

	return jv, err
}
开发者ID:nikirill,项目名称:cothority,代码行数:35,代码来源:jvss.go

示例3: NewProtocolBlocking

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
}
开发者ID:nikirill,项目名称:cothority,代码行数:10,代码来源:node_test.go

示例4: NewNtreeProtocol

// 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
}
开发者ID:nikirill,项目名称:cothority,代码行数:26,代码来源:ntree.go

示例5: NewPropagateProtocol

// NewPropagateProtocol returns a new Propagate protocol
func NewPropagateProtocol(n *sda.TreeNodeInstance) (sda.ProtocolInstance, error) {
	p := &Propagate{
		sd:               &PropagateSendData{[]byte{}, 1000},
		TreeNodeInstance: n,
		received:         0,
		subtree:          n.TreeNode().SubtreeCount(),
	}
	for _, h := range []interface{}{&p.ChannelSD, &p.ChannelReply} {
		if err := p.RegisterChannel(h); err != nil {
			return nil, err
		}
	}
	return p, nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:15,代码来源:propagate.go

示例6: NewBroadcastProtocol

// NewBroadcastProtocol returns a new Broadcast protocol
func NewBroadcastProtocol(n *sda.TreeNodeInstance) (sda.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
}
开发者ID:nikirill,项目名称:cothority,代码行数:24,代码来源:broadcast.go

示例7: NewProtocol

// 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
}
开发者ID:nikirill,项目名称:cothority,代码行数:37,代码来源:pbft.go

示例8: NewBFTCoSiProtocol

// 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
}
开发者ID:nikirill,项目名称:cothority,代码行数:37,代码来源:bftcosi.go


注:本文中的github.com/dedis/cothority/sda.TreeNodeInstance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。