本文整理汇总了Golang中github.com/dedis/onet/log.Lvl3函数的典型用法代码示例。如果您正苦于以下问题:Golang Lvl3函数的具体用法?Golang Lvl3怎么用?Golang Lvl3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Lvl3函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewPropagationFunc
// NewPropagationFunc registers a new protocol name with the context c and will
// set f as handler for every new instance of that protocol.
func NewPropagationFunc(c propagationContext, name string, f PropagationStore) (PropagationFunc, error) {
pid, err := c.ProtocolRegister(name, func(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error) {
p := &Propagate{
sd: &PropagateSendData{[]byte{}, 1000},
TreeNodeInstance: n,
received: 0,
subtreeCount: n.TreeNode().SubtreeCount(),
onData: f,
}
for _, h := range []interface{}{&p.ChannelSD, &p.ChannelReply} {
if err := p.RegisterChannel(h); err != nil {
return nil, err
}
}
return p, nil
})
log.Lvl3("Registering new propagation for", c.ServerIdentity(),
name, pid)
return func(el *onet.Roster, msg network.Body, msec int) (int, error) {
tree := el.GenerateNaryTreeWithRoot(8, c.ServerIdentity())
log.Lvl3(el.List[0].Address, "Starting to propagate", reflect.TypeOf(msg))
pi, err := c.CreateProtocolOnet(name, tree)
if err != nil {
return -1, err
}
return propagateStartAndWait(pi, msg, msec, f)
}, err
}
示例2: Dispatch
// Dispatch listens for all channels and waits for a timeout in case nothing
// happens for a certain duration
func (p *ProtocolCount) Dispatch() error {
running := true
for running {
log.Lvl3(p.Info(), "waiting for message during", p.Timeout())
select {
case pc := <-p.PrepareCountChan:
log.Lvl3(p.Info(), "received from", pc.TreeNode.ServerIdentity.Address,
pc.Timeout)
p.SetTimeout(pc.Timeout)
p.FuncPC()
case c := <-p.CountChan:
p.FuncC(c)
running = false
case _ = <-p.NodeIsUpChan:
if p.Parent() != nil {
err := p.SendTo(p.Parent(), &NodeIsUp{})
if err != nil {
log.Error(p.Info(), "couldn't send to parent",
p.Parent().Name(), err)
}
} else {
p.Replies++
}
case <-time.After(time.Duration(p.Timeout()) * time.Millisecond):
log.Lvl3(p.Info(), "timed out while waiting for", p.Timeout())
if p.IsRoot() {
log.Lvl2("Didn't get all children in time:", p.Replies)
p.Count <- p.Replies
running = false
}
}
}
p.Done()
return nil
}
示例3: handleCommit
// handleCommit receives commit messages and signal the end if it received
// enough of it.
func (p *Protocol) handleCommit(com *Commit) {
if p.state != stateCommit {
// log.Lvl3(p.Name(), "STORE handle commit packet")
p.tempCommitMsg = append(p.tempCommitMsg, com)
return
}
// finish after threshold of Commit msgs
p.commitMsgCount++
log.Lvl4(p.Name(), "----------------\nWe got", p.commitMsgCount,
"COMMIT msgs and threshold is", p.threshold)
if p.IsRoot() {
log.Lvl4("Leader got ", p.commitMsgCount)
}
if p.commitMsgCount >= p.threshold {
p.state = stateFinished
// reset counter
p.commitMsgCount = 0
log.Lvl3(p.Name(), "Threshold reached: We are done... CONSENSUS")
if p.IsRoot() && p.onDoneCB != nil {
log.Lvl3(p.Name(), "We are root and threshold reached: return to the simulation.")
p.onDoneCB()
p.finish()
}
return
}
}
示例4: runProtocolOnceGo
func runProtocolOnceGo(nbrHosts int, name string, refuseCount int,
succeed bool) error {
log.Lvl2("Running BFTCoSi with", nbrHosts, "hosts")
local := onet.NewLocalTest()
defer local.CloseAll()
_, _, tree := local.GenBigTree(nbrHosts, nbrHosts, 2, true)
log.Lvl3("Tree is:", tree.Dump())
done := make(chan bool)
// create the message we want to sign for this round
msg := []byte("Hello BFTCoSi")
// Start the protocol
node, err := local.CreateProtocol(name, tree)
if err != nil {
return errors.New("Couldn't create new node: " + err.Error())
}
// Register the function generating the protocol instance
var root *ProtocolBFTCoSi
root = node.(*ProtocolBFTCoSi)
root.Msg = msg
cMux.Lock()
counter := &Counter{refuseCount: refuseCount}
counters.add(counter)
root.Data = []byte(strconv.Itoa(counters.size() - 1))
log.Lvl3("Added counter", counters.size()-1, refuseCount)
cMux.Unlock()
log.ErrFatal(err)
// function that will be called when protocol is finished by the root
root.RegisterOnDone(func() {
done <- true
})
go node.Start()
log.Lvl1("Launched protocol")
// are we done yet?
wait := time.Second * 60
select {
case <-done:
counter.Lock()
if counter.veriCount != nbrHosts {
return errors.New("Each host should have called verification.")
}
// if assert refuses we don't care for unlocking (t.Refuse)
counter.Unlock()
sig := root.Signature()
err := sig.Verify(root.Suite(), root.Roster().Publics())
if succeed && err != nil {
return fmt.Errorf("%s Verification of the signature refused: %s - %+v", root.Name(), err.Error(), sig.Sig)
}
if !succeed && err == nil {
return fmt.Errorf("%s: Shouldn't have succeeded for %d hosts, but signed for count: %d",
root.Name(), nbrHosts, refuseCount)
}
case <-time.After(wait):
log.Lvl1("Going to break because of timeout")
return errors.New("Waited " + wait.String() + " for BFTCoSi to finish ...")
}
return nil
}
示例5: handleContactNodes
// handleAnnounce receive the announcement from another node
// it reply with an ACK.
func (b *Broadcast) handleContactNodes(msg struct {
*onet.TreeNode
ContactNodes
}) error {
log.Lvl3(b.Info(), "Received message from", msg.TreeNode.String())
if msg.TreeNode.ID == b.Root().ID {
b.repliesLeft = len(b.Tree().List()) - b.tnIndex - 1
if b.repliesLeft == 0 {
log.Lvl3("Won't contact anybody - finishing")
b.SendTo(b.Root(), &Done{})
return nil
}
log.Lvl3(b.Info(), "Contacting nodes:", b.repliesLeft)
// Connect to all nodes that are later in the TreeNodeList, but only if
// the message comes from root
for _, tn := range b.Tree().List()[b.tnIndex+1:] {
log.Lvl3("Connecting to", tn.String())
err := b.SendTo(tn, &ContactNodes{})
if err != nil {
return nil
}
}
} else {
// Tell the caller we're done
log.Lvl3("Sending back to", msg.TreeNode.ServerIdentity.String())
b.SendTo(msg.TreeNode, &Done{})
}
return nil
}
示例6: waitResponseVerification
// waitResponseVerification waits till the end of the verification and returns
// the BFTCoSiResponse along with the flag:
// true => no exception, the verification is correct
// false => exception, the verification failed
func (bft *ProtocolBFTCoSi) waitResponseVerification() (*Response, bool) {
log.Lvl3(bft.Name(), "Waiting for response verification:")
// wait the verification
verified := <-bft.verifyChan
resp, err := bft.prepare.Response(bft.tempPrepareResponse)
if err != nil {
return nil, false
}
if !verified {
// Add our exception
bft.tempExceptions = append(bft.tempExceptions, Exception{
Index: bft.index,
Commitment: bft.prepare.GetCommitment(),
})
// Don't include our response!
resp = bft.Suite().Scalar().Set(resp).Sub(resp, bft.prepare.GetResponse())
log.Lvl3(bft.Name(), "Response verification: failed")
}
r := &Response{
TYPE: RoundPrepare,
Exceptions: bft.tempExceptions,
Response: resp,
}
log.Lvl3(bft.Name(), "Response verification:", verified)
return r, verified
}
示例7: TestThreshold
func TestThreshold(t *testing.T) {
const TestProtocolName = "DummyBFTCoSiThr"
// Register test protocol using BFTCoSi
onet.GlobalProtocolRegister(TestProtocolName, func(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error) {
return NewBFTCoSiProtocol(n, verify)
})
local := onet.NewLocalTest()
defer local.CloseAll()
tests := []struct{ h, t int }{
{1, 1},
{2, 2},
{3, 2},
{4, 3},
{5, 4},
{6, 4},
}
for _, s := range tests {
hosts, thr := s.h, s.t
log.Lvl3("Hosts is", hosts)
_, _, tree := local.GenBigTree(hosts, hosts, 2, true)
log.Lvl3("Tree is:", tree.Dump())
// Start the protocol
node, err := local.CreateProtocol(TestProtocolName, tree)
log.ErrFatal(err)
bc := node.(*ProtocolBFTCoSi)
assert.Equal(t, thr, bc.threshold, "hosts was %d", hosts)
local.CloseAll()
}
}
示例8: CreateIdentity
// CreateIdentity will register a new SkipChain and add it to our list of
// managed identities.
func (s *Service) CreateIdentity(ai *CreateIdentity) (network.Body, onet.ClientError) {
log.Lvlf3("%s Creating new identity with config %+v", s, ai.Config)
ids := &Storage{
Latest: ai.Config,
}
log.Lvl3("Creating Root-skipchain")
var cerr onet.ClientError
ids.Root, cerr = s.skipchain.CreateRoster(ai.Roster, 2, 10,
skipchain.VerifyNone, nil)
if cerr != nil {
return nil, cerr
}
log.Lvl3("Creating Data-skipchain")
ids.Root, ids.Data, cerr = s.skipchain.CreateData(ids.Root, 2, 10,
skipchain.VerifyNone, ai.Config)
if cerr != nil {
return nil, cerr
}
roster := ids.Root.Roster
replies, err := s.propagateIdentity(roster, &PropagateIdentity{ids}, propagateTimeout)
if err != nil {
return nil, onet.NewClientErrorCode(ErrorOnet, err.Error())
}
if replies != len(roster.List) {
log.Warn("Did only get", replies, "out of", len(roster.List))
}
log.Lvlf2("New chain is\n%x", []byte(ids.Data.Hash))
s.save()
return &CreateIdentityReply{
Root: ids.Root,
Data: ids.Data,
}, nil
}
示例9: nodeDone
// nodeDone is either called by the end of EndProtocol or by the end of the
// response phase of the commit round.
func (bz *ByzCoin) nodeDone() bool {
log.Lvl3(bz.Name(), "nodeDone() ----- ")
bz.doneProcessing <- true
log.Lvl3(bz.Name(), "nodeDone() +++++ ", bz.onDoneCallback)
if bz.onDoneCallback != nil {
bz.onDoneCallback()
}
return true
}
示例10: FuncPrepareClose
// FuncPrepareClose sends a `PrepareClose`-message down the tree.
func (p *ProtocolCloseAll) FuncPrepareClose(pc PrepareCloseMsg) error {
log.Lvl3(pc.ServerIdentity.Address, "sent PrepClose to", p.ServerIdentity().Address)
if !p.IsLeaf() {
for _, c := range p.Children() {
err := p.SendTo(c, &PrepareClose{})
log.Lvl3(p.ServerIdentity().Address, "sends to", c.ServerIdentity.Address, "(err=", err, ")")
}
} else {
p.FuncClose(nil)
}
return nil
}
示例11: Dispatch
// Dispatch can handle timeouts
func (p *Propagate) Dispatch() error {
process := true
log.Lvl4(p.ServerIdentity())
for process {
p.Lock()
timeout := time.Millisecond * time.Duration(p.sd.Msec)
p.Unlock()
select {
case msg := <-p.ChannelSD:
log.Lvl3(p.ServerIdentity(), "Got data from", msg.ServerIdentity, "and setting timeout to", msg.Msec)
p.sd.Msec = msg.Msec
if p.onData != nil {
_, netMsg, err := network.UnmarshalRegistered(msg.Data)
if err == nil {
p.onData(netMsg)
}
}
if !p.IsRoot() {
log.Lvl3(p.ServerIdentity(), "Sending to parent")
p.SendToParent(&PropagateReply{})
}
if p.IsLeaf() {
process = false
} else {
log.Lvl3(p.ServerIdentity(), "Sending to children")
p.SendToChildren(&msg.PropagateSendData)
}
case <-p.ChannelReply:
p.received++
log.Lvl4(p.ServerIdentity(), "received:", p.received, p.subtreeCount)
if !p.IsRoot() {
p.SendToParent(&PropagateReply{})
}
if p.received == p.subtreeCount {
process = false
}
case <-time.After(timeout):
_, a, err := network.UnmarshalRegistered(p.sd.Data)
log.Fatalf("Timeout of %s reached. %v %s", timeout, a, err)
process = false
}
}
if p.IsRoot() {
if p.onDoneCb != nil {
p.onDoneCb(p.received + 1)
}
}
p.Done()
return nil
}
示例12: network
// network will contact all cothorities in the group-file and print
// the status-report of each one.
func network(c *cli.Context) error {
groupToml := c.GlobalString("g")
el, err := readGroup(groupToml)
log.ErrFatal(err, "Couldn't Read File")
log.Lvl3(el)
cl := status.NewClient()
for i := 0; i < len(el.List); i++ {
log.Lvl3(el.List[i])
sr, _ := cl.Request(el.List[i])
printConn(sr)
log.Lvl3(cl)
}
return nil
}
示例13: HandleReply
// HandleReply is the message going up the tree and holding a counter
// to verify the number of nodes.
func (p *ProtocolExampleHandlers) HandleReply(reply []StructReply) error {
children := 1
for _, c := range reply {
children += c.ChildrenCount
}
log.Lvl3(p.ServerIdentity().Address, "is done with total of", children)
if !p.IsRoot() {
log.Lvl3("Sending to parent")
return p.SendTo(p.Parent(), &Reply{children})
}
log.Lvl3("Root-node is done - nbr of children found:", children)
p.ChildCount <- children
return nil
}
示例14: listen
// listen will select on the differents channels
func (nt *Ntree) listen() {
for {
select {
// Dispatch the block through the whole tree
case msg := <-nt.announceChan:
log.Lvl3(nt.Name(), "Received Block announcement")
nt.block = msg.BlockAnnounce.Block
// verify the block
go byzcoin.VerifyBlock(nt.block, "", "", nt.verifyBlockChan)
if nt.IsLeaf() {
nt.startBlockSignature()
continue
}
for _, tn := range nt.Children() {
err := nt.SendTo(tn, &msg.BlockAnnounce)
if err != nil {
log.Error(nt.Name(),
"couldn't send to", tn.Name(),
err)
}
}
// generate your own signature / exception and pass that up to the
// root
case msg := <-nt.blockSignatureChan:
nt.handleBlockSignature(&msg.NaiveBlockSignature)
// Dispatch the signature + expcetion made before through the whole
// tree
case msg := <-nt.roundSignatureRequestChan:
log.Lvl3(nt.Name(), " Signature Request Received")
go nt.verifySignatureRequest(&msg.RoundSignatureRequest)
if nt.IsLeaf() {
nt.startSignatureResponse()
continue
}
for _, tn := range nt.Children() {
err := nt.SendTo(tn, &msg.RoundSignatureRequest)
if err != nil {
log.Error(nt.Name(), "couldn't sent to",
tn.Name(), err)
}
}
// Decide if we want to sign this or not
case msg := <-nt.roundSignatureResponseChan:
nt.handleRoundSignatureResponse(&msg.RoundSignatureResponse)
}
}
}
示例15: startSignatureResponse
// Start the last phase : send up the final signature
func (nt *Ntree) startSignatureResponse() {
log.Lvl3(nt.Name(), "Start Signature Response phase")
nt.computeSignatureResponse()
if err := nt.SendTo(nt.Parent(), nt.tempSignatureResponse); err != nil {
log.Error(err)
}
}