本文整理汇总了Golang中github.com/dedis/cothority/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ProcessClientRequest
func (s *simpleService) ProcessClientRequest(e *network.ServerIdentity, r *sda.ClientRequest) {
msgT, pm, err := network.UnmarshalRegisteredType(r.Data, network.DefaultConstructors(network.Suite))
log.ErrFatal(err)
if msgT != simpleRequestType {
return
}
req := pm.(simpleRequest)
tree := req.ServerIdentities.GenerateBinaryTree()
tni := s.ctx.NewTreeNodeInstance(tree, tree.Root, "BackForth")
proto, err := newBackForthProtocolRoot(tni, req.Val, func(n int) {
if err := s.ctx.SendRaw(e, &simpleResponse{
Val: n,
}); err != nil {
log.Error(err)
}
})
if err != nil {
log.Error(err)
return
}
if err := s.ctx.RegisterProtocolInstance(proto); err != nil {
log.Error(err)
}
go proto.Start()
}
示例2: handleChallengeCommit
// handleCommitChallenge will verify the signature + check if no more than 1/3
// of participants refused to sign.
func (bft *ProtocolBFTCoSi) handleChallengeCommit(ch *ChallengeCommit) error {
ch.Challenge = bft.commit.Challenge(ch.Challenge)
hash := bft.Suite().Hash()
hash.Write(bft.Msg)
h := hash.Sum(nil)
// verify if the signature is correct
if err := cosi.VerifyCosiSignatureWithException(bft.suite,
bft.AggregatedPublic, h, ch.Signature,
ch.Exceptions); err != nil {
log.Error(bft.Name(), "Verification of the signature failed:", err)
bft.signRefusal = true
}
// Check if we have no more than 1/3 failed nodes
if len(ch.Exceptions) > int(bft.threshold) {
log.Errorf("More than 1/3 (%d/%d) refused to sign ! ABORT",
len(ch.Exceptions), len(bft.Roster().List))
bft.signRefusal = true
}
// store the exceptions for later usage
bft.tempExceptions = ch.Exceptions
log.Lvl4("BFTCoSi handle Challenge COMMIT")
if bft.IsLeaf() {
return bft.startResponseCommit()
}
if err := bft.SendToChildrenInParallel(ch); err != nil {
log.Error(err)
}
return nil
}
示例3: EndAndCleanup
// EndAndCleanup sends a message to end the logging and closes the connection
func EndAndCleanup() {
if err := send(NewSingleMeasure("end", 0)); err != nil {
log.Error("Error while sending 'end' message:", err)
}
if err := connection.Close(); err != nil {
// at least tell that we could not close the connection:
log.Error("Could not close connecttion:", err)
}
encoder = nil
}
示例4: RunTest
// RunTest a single test - takes a test-file as a string that will be copied
// to the deterlab-server
func RunTest(rc platform.RunConfig) (*monitor.Stats, error) {
done := make(chan struct{})
CheckHosts(rc)
rc.Delete("simulation")
rs := monitor.NewStats(rc.Map(), "hosts", "bf")
monitor := monitor.NewMonitor(rs)
if err := deployP.Deploy(rc); err != nil {
log.Error(err)
return rs, err
}
monitor.SinkPort = monitorPort
if err := deployP.Cleanup(); err != nil {
log.Error(err)
return rs, err
}
monitor.SinkPort = monitorPort
go func() {
if err := monitor.Listen(); err != nil {
log.Fatal("Could not monitor.Listen():", err)
}
}()
// Start monitor before so ssh tunnel can connect to the monitor
// in case of deterlab.
err := deployP.Start()
if err != nil {
log.Error(err)
return rs, err
}
go func() {
var err error
if err = deployP.Wait(); err != nil {
log.Lvl3("Test failed:", err)
if err := deployP.Cleanup(); err != nil {
log.Lvl3("Couldn't cleanup platform:", err)
}
done <- struct{}{}
}
log.Lvl3("Test complete:", rs)
done <- struct{}{}
}()
timeOut := getRunWait(rc)
// can timeout the command if it takes too long
select {
case <-done:
monitor.Stop()
return rs, nil
case <-time.After(time.Second * time.Duration(timeOut)):
monitor.Stop()
return rs, errors.New("Simulation timeout")
}
}
示例5: 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
}
示例6: 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)
}
}
}
示例7: Start
func (dm *DummyProtocol) Start() error {
dm.link <- true
if dm.config.Send {
if err := dm.SendTo(dm.TreeNode(), &DummyMsg{}); err != nil {
log.Error(err)
}
// also send to the children if any
if !dm.IsLeaf() {
if err := dm.SendTo(dm.Children()[0], &DummyMsg{}); err != nil {
log.Error(err)
}
}
}
return nil
}
示例8: 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)
}
示例9: HashSum
// HashSum returns a hash representation of the header
func (h *Header) HashSum() []byte {
ha := sha256.New()
if _, err := ha.Write([]byte(h.MerkleRoot)); err != nil {
log.Error("Couldn't hash header", err)
}
if _, err := ha.Write([]byte(h.Parent)); err != nil {
log.Error("Couldn't hash header", err)
}
if _, err := ha.Write([]byte(h.ParentKey)); err != nil {
log.Error("Couldn't hash header", err)
}
if _, err := ha.Write([]byte(h.PublicKey)); err != nil {
log.Error("Couldn't hash header", err)
}
return ha.Sum(nil)
}
示例10: handleResponsePrepare
func (bft *ProtocolBFTCoSi) handleResponsePrepare(r *Response) error {
// check if we have enough
bft.tprMut.Lock()
defer bft.tprMut.Unlock()
bft.tempPrepareResponse = append(bft.tempPrepareResponse, r.Response)
if len(bft.tempPrepareResponse) < len(bft.Children()) {
return nil
}
// wait for verification
bzrReturn, ok := bft.waitResponseVerification()
if ok {
// append response
resp, err := bft.prepare.Response(bft.tempPrepareResponse)
if err != nil {
return err
}
bzrReturn.Response = resp
}
log.Lvl4("BFTCoSi Handle Response PREPARE")
if bft.IsRoot() {
// Notify 'commit'-round as we're root
if err := bft.startChallengeCommit(); err != nil {
log.Error(err)
}
return nil
}
return bft.SendTo(bft.Parent(), bzrReturn)
}
示例11: dispatchMsgReader
func (n *TreeNodeInstance) dispatchMsgReader() {
for {
n.msgDispatchQueueMutex.Lock()
if n.closing == true {
log.Lvl3("Closing reader")
n.msgDispatchQueueMutex.Unlock()
return
}
if len(n.msgDispatchQueue) > 0 {
log.Lvl4(n.Info(), "Read message and dispatching it",
len(n.msgDispatchQueue))
msg := n.msgDispatchQueue[0]
n.msgDispatchQueue = n.msgDispatchQueue[1:]
n.msgDispatchQueueMutex.Unlock()
err := n.dispatchMsgToProtocol(msg)
if err != nil {
log.Error("Error while dispatching message:", err)
}
} else {
n.msgDispatchQueueMutex.Unlock()
log.Lvl4(n.Info(), "Waiting for message")
<-n.msgDispatchQueueWait
}
}
}
示例12: proxyConnection
// The core of the file: read any input from the connection and outputs it into
// the server connection
func proxyConnection(conn net.Conn, done chan bool) {
dec := json.NewDecoder(conn)
nerr := 0
for {
m := SingleMeasure{}
// Receive data
if err := dec.Decode(&m); err != nil {
if err == io.EOF {
break
}
log.Lvl1("Error receiving data from", conn.RemoteAddr().String(), ":", err)
nerr++
if nerr > 1 {
log.Lvl1("Too many errors from", conn.RemoteAddr().String(), ": Abort connection")
break
}
}
log.Lvl3("Proxy received", m)
// Proxy data back to monitor
if err := serverEnc.Encode(m); err != nil {
log.Lvl2("Error proxying data :", err)
break
}
if m.Name == "end" {
// the end
log.Lvl2("Proxy detected end of measurement. Closing connection.")
break
}
}
if err := conn.Close(); err != nil {
log.Error("Couldn't close connection:", err)
}
done <- true
}
示例13: ProcessClientRequest
// ProcessClientRequest takes a request from a client, calculates the reply
// and sends it back.
func (p *ServiceProcessor) ProcessClientRequest(e *network.ServerIdentity,
cr *ClientRequest) {
reply := p.GetReply(e, cr.Data)
if err := p.SendRaw(e, reply); err != nil {
log.Error(err)
}
}
示例14: Start
// Start will execute one cothority-binary for each server
// configured
func (d *Localhost) Start(args ...string) error {
if err := os.Chdir(d.runDir); err != nil {
return err
}
log.Lvl4("Localhost: chdir into", d.runDir)
ex := d.runDir + "/" + d.Simulation
d.running = true
log.Lvl1("Starting", d.servers, "applications of", ex)
for index := 0; index < d.servers; index++ {
d.wgRun.Add(1)
log.Lvl3("Starting", index)
host := "localhost" + strconv.Itoa(index)
cmdArgs := []string{"-address", host, "-monitor",
"localhost:" + strconv.Itoa(d.monitorPort),
"-simul", d.Simulation,
"-debug", strconv.Itoa(log.DebugVisible()),
}
cmdArgs = append(args, cmdArgs...)
log.Lvl3("CmdArgs are", cmdArgs)
cmd := exec.Command(ex, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
go func(i int, h string) {
log.Lvl3("Localhost: will start host", h)
err := cmd.Run()
if err != nil {
log.Error("Error running localhost", h, ":", err)
d.errChan <- err
}
d.wgRun.Done()
log.Lvl3("host (index", i, ")", h, "done")
}(index, host)
}
return nil
}
示例15: dispatch
func (sp *BackForthProtocol) dispatch() {
for {
select {
// dispatch the first msg down
case m := <-sp.forthChan:
msg := &m.SimpleMessageForth
for _, ch := range sp.Children() {
sp.SendTo(ch, msg)
}
if sp.IsLeaf() {
if err := sp.SendTo(sp.Parent(), &SimpleMessageBack{msg.Val}); err != nil {
log.Error(err)
}
return
}
// pass the message up
case m := <-sp.backChan:
msg := m.SimpleMessageBack
// call the handler if we are the root
sp.counter++
if sp.counter == len(sp.Children()) {
if sp.IsRoot() {
sp.handler(msg.Val)
} else {
sp.SendTo(sp.Parent(), &msg)
}
sp.Done()
return
}
}
}
}