本文整理汇总了Golang中github.com/dedis/onet/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: propagateSkipBlockHandler
// propagateSkipBlock saves a new skipblock to the identity
func (s *Service) propagateSkipBlockHandler(msg network.Body) {
log.Lvlf4("Got msg %+v %v", msg, reflect.TypeOf(msg).String())
usb, ok := msg.(*UpdateSkipBlock)
if !ok {
log.Error("Wrong message-type")
return
}
sid := s.getIdentityStorage(usb.ID)
if sid == nil {
log.Error("Didn't find entity in", s)
return
}
sid.Lock()
defer sid.Unlock()
skipblock := msg.(*UpdateSkipBlock).Latest
_, msgLatest, err := network.UnmarshalRegistered(skipblock.Data)
if err != nil {
log.Error(err)
return
}
al, ok := msgLatest.(*Config)
if !ok {
log.Error(err)
return
}
sid.Data = skipblock
sid.Latest = al
sid.Proposed = nil
}
示例2: Run
// Run starts the simulation on the simulation-side
func (e *Simulation) Run(config *onet.SimulationConfig) error {
msg := []byte(e.Message)
size := config.Tree.Size()
log.Lvl2("Size is:", size, "rounds:", e.Rounds)
for round := 0; round < e.Rounds; round++ {
log.Lvl1("Starting round", round, "with message", string(msg))
round := monitor.NewTimeMeasure("round")
p, err := config.Overlay.CreateProtocolOnet("NaiveTree", config.Tree)
if err != nil {
log.Error("Quitting the simulation....", err)
return err
}
pi := p.(*Protocol)
pi.Message = msg
pi.verifySignature = e.Checking
done := make(chan bool)
pi.TreeNodeInstance.OnDoneCallback(func() bool {
done <- true
return true
})
err = pi.Start()
if err != nil {
log.Error("Quitting the simulation....", err)
return err
}
<-done
round.Record()
}
return nil
}
示例3: handleResponsePrepare
// If 'r' is nil, it will starts the response process.
func (bft *ProtocolBFTCoSi) handleResponsePrepare(r *Response) error {
if r != nil {
// check if we have enough responses
bft.tmpMutex.Lock()
bft.tempPrepareResponse = append(bft.tempPrepareResponse, r.Response)
bft.tempExceptions = append(bft.tempExceptions, r.Exceptions...)
if len(bft.tempPrepareResponse) < len(bft.Children()) {
bft.tmpMutex.Unlock()
return nil
}
bft.tmpMutex.Unlock()
}
// wait for verification
bzrReturn, ok := bft.waitResponseVerification()
// append response
if !ok {
log.Lvl2(bft.Roster(), "Refused to sign")
}
// Return if we're not root
if !bft.IsRoot() {
return bft.SendTo(bft.Parent(), bzrReturn)
}
// Since cosi does not support exceptions yet, we have to remove
// the responses that are not supposed to be there,i.e. exceptions.
cosiSig := bft.prepare.Signature()
correctResponseBuff, err := bzrReturn.Response.MarshalBinary()
if err != nil {
return err
}
// replace the old one with the corrected one
copy(cosiSig[32:64], correctResponseBuff)
bft.prepareSignature = cosiSig
// Verify the signature is correct
data := sha512.Sum512(bft.Msg)
sig := &BFTSignature{
Msg: data[:],
Sig: cosiSig,
Exceptions: bft.tempExceptions,
}
aggCommit := bft.Suite().Point().Null()
for _, c := range bft.tempPrepareCommit {
aggCommit.Add(aggCommit, c)
}
if err := sig.Verify(bft.Suite(), bft.Roster().Publics()); err != nil {
log.Error(bft.Name(), "Verification of the signature failed:", err)
bft.signRefusal = true
}
log.Lvl3(bft.Name(), "Verification of signature successful")
// Start the challenge of the 'commit'-round
if err := bft.startChallenge(RoundCommit); err != nil {
log.Error(bft.Name(), err)
return err
}
return nil
}
示例4: finaliseSecret
func (jv *JVSS) finaliseSecret(sid SID) error {
secret, err := jv.secrets.secret(sid)
if err != nil {
return err
}
log.Lvlf4("Node %d: %s deals %d/%d", jv.Index(), sid, len(secret.deals),
len(jv.List()))
if len(secret.deals) == jv.info.T {
for _, deal := range secret.deals {
if _, err := secret.receiver.AddDeal(jv.Index(), deal); err != nil {
log.Error(jv.Index(), err)
return err
}
}
sec, err := secret.receiver.ProduceSharedSecret()
if err != nil {
return err
}
secret.secret = sec
isShortTermSecret := strings.HasPrefix(string(sid), string(STSS))
if isShortTermSecret {
secret.nShortConfirmsMtx.Lock()
defer secret.nShortConfirmsMtx.Unlock()
secret.numShortConfs++
} else {
secret.nLongConfirmsMtx.Lock()
defer secret.nLongConfirmsMtx.Unlock()
secret.numLongtermConfs++
}
log.Lvlf4("Node %d: %v created", jv.Index(), sid)
// Initialise Schnorr struct for long-term shared secret if not done so before
if sid.IsLTSS() && !jv.ltssInit {
jv.ltssInit = true
jv.schnorr.Init(jv.keyPair.Suite, jv.info, secret.secret)
log.Lvlf4("Node %d: %v Schnorr struct initialised",
jv.Index(), sid)
}
// Broadcast that we have finished setting up our shared secret
msg := &SecConfMsg{
Src: jv.Index(),
SID: sid,
}
if err := jv.Broadcast(msg); err != nil {
log.Error(err)
return err
}
}
return nil
}
示例5: save
// saves the actual identity
func (s *Service) save() {
log.Lvl3("Saving service")
b, err := network.MarshalRegisteredType(s.StorageMap)
if err != nil {
log.Error("Couldn't marshal service:", err)
} else {
err = ioutil.WriteFile(s.path+"/identity.bin", b, 0660)
if err != nil {
log.Error("Couldn't save file:", err)
}
}
}
示例6: PropagateSkipBlock
// PropagateSkipBlock will save a new SkipBlock
func (s *Service) PropagateSkipBlock(msg network.Body) {
sb, ok := msg.(*SkipBlock)
if !ok {
log.Error("Couldn't convert to SkipBlock")
return
}
if err := sb.VerifySignatures(); err != nil {
log.Error(err)
return
}
s.storeSkipBlock(sb)
log.Lvlf3("Stored skip block %+v in %x", *sb, s.Context.ServerIdentity().ID[0:8])
}
示例7: GetShaString
func GetShaString(data []byte) (res string) {
sha := sha256.New()
if _, err := sha.Write(data[:]); err != nil {
log.Error("Failed to hash data", err)
}
tmp := sha.Sum(nil)
sha.Reset()
if _, err := sha.Write(tmp); err != nil {
log.Error("Failed to hash data", err)
}
hash := sha.Sum(nil)
res = HashString(hash)
return
}
示例8: 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)
}
}
}
示例9: HashSum
func (tl *TransactionList) HashSum() []byte {
h := sha256.New()
for _, tx := range tl.Txs {
if _, err := h.Write([]byte(tx.Hash)); err != nil {
log.Error("Couldn't hash TX list", err)
}
}
if err := binary.Write(h, binary.LittleEndian, tl.TxCnt); err != nil {
log.Error("Couldn't hash TX list", err)
}
if err := binary.Write(h, binary.LittleEndian, tl.Fees); err != nil {
log.Error("Couldn't hash TX list", err)
}
return h.Sum(nil)
}
示例10: getResponse
func (c *CoSimul) getResponse(in []abstract.Scalar) {
if c.IsLeaf() {
// This is the leaf-node and we can't verify it
return
}
verify := false
switch VerifyResponse {
case NoCheck:
log.Lvl3("Not checking at all")
case RootCheck:
verify = c.IsRoot()
case AllCheck:
verify = !c.IsLeaf()
}
if verify {
err := c.VerifyResponses(c.TreeNode().AggregatePublic())
if err != nil {
log.Error("Couldn't verify responses at our level", c.Name(), err.Error())
} else {
log.Lvl2("Successfully verified responses at", c.Name())
}
}
}
示例11: handleSecInit
func (jv *JVSS) handleSecInit(m WSecInitMsg) error {
msg := m.SecInitMsg
log.Lvl4(jv.Name(), jv.Index(), "Received SecInit from", m.TreeNode.Name())
// Initialise shared secret
if err := jv.initSecret(msg.SID); err != nil {
return err
}
// Unmarshal received deal
deal := new(poly.Deal).UnmarshalInit(jv.info.T, jv.info.R, jv.info.N, jv.keyPair.Suite)
if err := deal.UnmarshalBinary(msg.Deal); err != nil {
return err
}
// Buffer received deal for later
secret, err := jv.secrets.secret(msg.SID)
if err != nil {
return err
}
secret.deals[msg.Src] = deal
// Finalise shared secret
if err := jv.finaliseSecret(msg.SID); err != nil {
log.Error(jv.Index(), err)
return err
}
log.Lvl4("Finished handleSecInit", jv.Name(), msg.SID)
return nil
}
示例12: newIdentityService
func newIdentityService(c *onet.Context, path string) onet.Service {
s := &Service{
ServiceProcessor: onet.NewServiceProcessor(c),
StorageMap: &StorageMap{make(map[string]*Storage)},
skipchain: skipchain.NewClient(),
path: path,
}
var err error
s.propagateIdentity, err =
manage.NewPropagationFunc(c, "IdentityPropagateID", s.propagateIdentityHandler)
if err != nil {
return nil
}
s.propagateSkipBlock, err =
manage.NewPropagationFunc(c, "IdentityPropagateSB", s.propagateSkipBlockHandler)
if err != nil {
return nil
}
s.propagateConfig, err =
manage.NewPropagationFunc(c, "IdentityPropagateConf", s.propagateConfigHandler)
if err != nil {
return nil
}
if err := s.tryLoad(); err != nil {
log.Error(err)
}
for _, f := range []interface{}{s.ProposeSend, s.ProposeVote,
s.CreateIdentity, s.ProposeUpdate, s.ConfigUpdate} {
if err := s.RegisterHandler(f); err != nil {
log.Fatal("Registration error:", err)
}
}
return s
}
示例13: propagateIdentityHandler
// propagateIdentity stores a new identity in all nodes.
func (s *Service) propagateIdentityHandler(msg network.Body) {
log.Lvlf4("Got msg %+v %v", msg, reflect.TypeOf(msg).String())
pi, ok := msg.(*PropagateIdentity)
if !ok {
log.Error("Got a wrong message for propagation")
return
}
id := ID(pi.Data.Hash)
if s.getIdentityStorage(id) != nil {
log.Error("Couldn't store new identity")
return
}
log.Lvl3("Storing identity in", s)
s.setIdentityStorage(id, pi.Storage)
return
}
示例14: propagateConfigHandler
// propagateConfig handles propagation of all configuration-proposals in the identity-service.
func (s *Service) propagateConfigHandler(msg network.Body) {
log.Lvlf4("Got msg %+v %v", msg, reflect.TypeOf(msg).String())
id := ID(nil)
switch msg.(type) {
case *ProposeSend:
id = msg.(*ProposeSend).ID
case *ProposeVote:
id = msg.(*ProposeVote).ID
default:
log.Errorf("Got an unidentified propagation-request: %v", msg)
return
}
if id != nil {
sid := s.getIdentityStorage(id)
if sid == nil {
log.Error("Didn't find entity in", s)
return
}
sid.Lock()
defer sid.Unlock()
switch msg.(type) {
case *ProposeSend:
p := msg.(*ProposeSend)
sid.Proposed = p.Config
sid.Votes = make(map[string]*crypto.SchnorrSig)
case *ProposeVote:
v := msg.(*ProposeVote)
sid.Votes[v.Signer] = v.Signature
}
}
}
示例15: newSkipchainService
func newSkipchainService(c *onet.Context, path string) onet.Service {
s := &Service{
ServiceProcessor: onet.NewServiceProcessor(c),
path: path,
SkipBlockMap: &SkipBlockMap{make(map[string]*SkipBlock)},
verifiers: map[VerifierID]SkipBlockVerifier{},
}
var err error
s.Propagate, err = manage.NewPropagationFunc(c, "SkipchainPropagate", s.PropagateSkipBlock)
log.ErrFatal(err)
c.ProtocolRegister(skipchainBFT, func(n *onet.TreeNodeInstance) (onet.ProtocolInstance, error) {
return bftcosi.NewBFTCoSiProtocol(n, s.bftVerify)
})
if err := s.tryLoad(); err != nil {
log.Error(err)
}
log.ErrFatal(s.RegisterHandlers(s.ProposeSkipBlock, s.SetChildrenSkipBlock,
s.GetUpdateChain))
if err := s.RegisterVerification(VerifyShard, s.VerifyShardFunc); err != nil {
log.Panic(err)
}
if err := s.RegisterVerification(VerifyNone, s.VerifyNoneFunc); err != nil {
log.Panic(err)
}
return s
}