本文整理匯總了Golang中github.com/dedis/cothority/sda.TreeNodeInstance.TreeNode方法的典型用法代碼示例。如果您正苦於以下問題:Golang TreeNodeInstance.TreeNode方法的具體用法?Golang TreeNodeInstance.TreeNode怎麽用?Golang TreeNodeInstance.TreeNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dedis/cothority/sda.TreeNodeInstance
的用法示例。
在下文中一共展示了TreeNodeInstance.TreeNode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}