本文整理汇总了Golang中github.com/dedis/cothority/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
}
开发者ID:nikirill,项目名称:cothority,代码行数:25,代码来源:service_test.go
示例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
}
开发者ID:nikirill,项目名称:cothority,代码行数:35,代码来源:bftcosi.go
示例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
}
开发者ID:nikirill,项目名称:cothority,代码行数:11,代码来源:measure.go
示例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")
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:57,代码来源:simul.go
示例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
}
开发者ID:nikirill,项目名称:cothority,代码行数:14,代码来源:utils.go
示例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)
}
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:50,代码来源:ntree.go
示例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
}
开发者ID:nikirill,项目名称:cothority,代码行数:15,代码来源:service_test.go
示例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)
}
开发者ID:nikirill,项目名称:cothority,代码行数:15,代码来源:transactionlist.go
示例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)
}
开发者ID:nikirill,项目名称:cothority,代码行数:17,代码来源:trblock.go
示例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)
}
开发者ID:nikirill,项目名称:cothority,代码行数:31,代码来源:bftcosi.go
示例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
}
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:25,代码来源:treenode.go
示例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
}
开发者ID:nikirill,项目名称:cothority,代码行数:37,代码来源:proxy.go
示例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)
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:9,代码来源:processor.go
示例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
}
开发者ID:nikirill,项目名称:cothority,代码行数:37,代码来源:localhost.go
示例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
}
}
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:32,代码来源:service_test.go
示例16: Wait
// Wait for all processes to finish
func (d *Localhost) Wait() error {
log.Lvl3("Waiting for processes to finish")
var err error
go func() {
d.wgRun.Wait()
log.Lvl3("WaitGroup is 0")
// write to error channel when done:
d.errChan <- nil
}()
// if one of the hosts fails, stop waiting and return the error:
select {
case e := <-d.errChan:
log.Lvl3("Finished waiting for hosts:", e)
if e != nil {
if err := d.Cleanup(); err != nil {
log.Error("Couldn't cleanup running instances",
err)
}
err = e
}
}
log.Lvl2("Processes finished")
return err
}
开发者ID:nikirill,项目名称:cothority,代码行数:28,代码来源:localhost.go
示例17: 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)
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:8,代码来源:ntree.go
示例18: triggerTransactions
func (c *Client) triggerTransactions(blocksPath string, nTxs int) error {
log.Lvl2("ByzCoin Client will trigger up to", nTxs, "transactions")
parser, err := blockchain.NewParser(blocksPath, magicNum)
if err != nil {
log.Error("Error: Couldn't parse blocks in", blocksPath,
".\nPlease download bitcoin blocks as .dat files first and place them in",
blocksPath, "Either run a bitcoin node (recommended) or using a torrent.")
return err
}
transactions, err := parser.Parse(0, ReadFirstNBlocks)
if err != nil {
return fmt.Errorf("Error while parsing transactions %v", err)
}
if len(transactions) == 0 {
return errors.New("Couldn't read any transactions.")
}
if len(transactions) < nTxs {
return fmt.Errorf("Read only %v but caller wanted %v", len(transactions), nTxs)
}
consumed := nTxs
for consumed > 0 {
for _, tr := range transactions {
// "send" transaction to server (we skip tcp connection on purpose here)
c.srv.AddTransaction(tr)
}
consumed--
}
return nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:30,代码来源:client.go
示例19: startBlockSignature
// startBlockSignature will send the first signature up the tree.
func (nt *Ntree) startBlockSignature() {
log.Lvl3(nt.Name(), "Starting Block Signature Phase")
nt.computeBlockSignature()
if err := nt.SendTo(nt.Parent(), nt.tempBlockSig); err != nil {
log.Error(err)
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:9,代码来源:ntree.go
示例20: getRTime
// Returns the sytem and the user time so far.
func getRTime() (tSys, tUsr float64) {
rusage := &syscall.Rusage{}
if err := syscall.Getrusage(syscall.RUSAGE_SELF, rusage); err != nil {
log.Error("Couldn't get rusage time:", err)
}
s, u := rusage.Stime, rusage.Utime
return iiToF(int64(s.Sec), int64(s.Usec)), iiToF(int64(u.Sec), int64(u.Usec))
}
开发者ID:nikirill,项目名称:cothority,代码行数:9,代码来源:measure.go
注:本文中的github.com/dedis/cothority/log.Error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论