本文整理汇总了Golang中github.com/dedis/cothority/lib/dbg.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Build
// This file handles the creation a of cothority tree.
// Basically, it takes a list of files generated by the "key" command by each
// hosts and turn that into a full tree with the hostname and public key in each
// node.
// BuildTree takes a file formatted like this :
// host pubKey
// host2 pubKey
// ... ...
// For the moment it takes a branching factor on how to make the tree
// and the name of the file where to write the config
// It writes the tree + any other configs to output using toml format
// with the app/config_conode.go struct
func Build(hostFile string, bf int, configFile string) {
// First, read the list of host and public keys
hosts, pubs, err := readHostFile(hostFile)
if err != nil {
dbg.Fatal("Error reading the host file:", err)
}
// Then construct the tree
tree := constructTree(hosts, pubs, bf)
// then constrcut the aggregated public key K0
k0 := aggregateKeys(pubs)
var b bytes.Buffer
err = cliutils.WritePub64(suite, &b, k0)
if err != nil {
dbg.Fatal("Could not aggregate public keys in base64")
}
// Then write the config
conf := app.ConfigConode{
Suite: suiteStr,
Tree: tree,
Hosts: hosts,
AggPubKey: b.String(),
}
app.WriteTomlConfig(conf, configFile)
dbg.Lvl1("Written config file with tree to", configFile)
}
开发者ID:mlncn,项目名称:cothority,代码行数:41,代码来源:config.go
示例2: init
func init() {
command := cli.Command{
Name: "check",
Aliases: []string{"c"},
Usage: "Checks if a given CoNode is valid in order to be incorporated into a cothority tree",
Description: "It checks the public key given and the availability of the server. It will be contacted multiple times a day during 24 hours",
ArgsUsage: "Public-key-file: file where reside the public key of the host to check",
Subcommands: []cli.Command{
{
Name: "exit",
Usage: "Asks the remote node to exit",
Action: func(c *cli.Context) {
if c.Args().First() == "" {
dbg.Fatal("No public key file given for exit.")
}
CheckExit(c.Args().First())
},
},
},
Action: func(c *cli.Context) {
if c.Args().First() == "" {
dbg.Fatal("No public key file given for check.")
}
Check(c.Args().First())
},
}
registerCommand(command)
}
开发者ID:mlncn,项目名称:cothority,代码行数:28,代码来源:check.go
示例3: main
// Reads in the platform that we want to use and prepares for the tests
func main() {
flag.Parse()
deployP = platform.NewPlatform(platform_dst)
if deployP == nil {
dbg.Fatal("Platform not recognized.", platform_dst)
}
dbg.Lvl1("Deploying to", platform_dst)
simulations := flag.Args()
if len(simulations) == 0 {
dbg.Fatal("Please give a simulation to run")
}
for _, simulation := range simulations {
runconfigs := platform.ReadRunFile(deployP, simulation)
if len(runconfigs) == 0 {
dbg.Fatal("No tests found in", simulation)
}
deployP.Configure()
if clean {
deployP.Deploy(runconfigs[0])
deployP.Cleanup()
} else {
logname := strings.Replace(filepath.Base(simulation), ".toml", "", 1)
RunTests(logname, runconfigs)
}
}
}
开发者ID:mlncn,项目名称:cothority,代码行数:31,代码来源:deploy.go
示例4: NewStampListener
// Creates a new stamp listener one port above the
// address given in nameP
func NewStampListener(nameP string) *StampListener {
// listen for client requests at one port higher
// than the signing node
var nameL string
h, p, err := net.SplitHostPort(nameP)
if err == nil {
i, err := strconv.Atoi(p)
if err != nil {
dbg.Fatal(err)
}
nameL = net.JoinHostPort(h, strconv.Itoa(i+1))
} else {
dbg.Fatal("Couldn't split host into name and port:", err)
}
sl, ok := SLList[nameL]
if !ok {
sl = &StampListener{}
dbg.Lvl3("Creating new StampListener for", nameL)
sl.Queue = make([][]MustReplyMessage, 2)
sl.Queue[READING] = make([]MustReplyMessage, 0)
sl.Queue[PROCESSING] = make([]MustReplyMessage, 0)
sl.Clients = make(map[string]coconet.Conn)
sl.waitClose = make(chan string)
sl.NameL = nameL
SLList[sl.NameL] = sl
sl.ListenRequests()
} else {
dbg.Lvl3("Taking cached StampListener")
}
return sl
}
开发者ID:mlncn,项目名称:cothority,代码行数:34,代码来源:stamplistener.go
示例5: Start
func (d *Deterlab) Start(args ...string) error {
// setup port forwarding for viewing log server
d.started = true
// Remote tunneling : the sink port is used both for the sink and for the
// proxy => the proxy redirects packets to the same port the sink is
// listening.
// -n = stdout == /Dev/null, -N => no command stream, -T => no tty
cmd := []string{"-nNTf", "-o", "StrictHostKeyChecking=no", "-o", "ExitOnForwardFailure=yes", "-R", d.ProxyRedirectionPort + ":" + d.ProxyRedirectionAddress + ":" + monitor.SinkPort, fmt.Sprintf("%[email protected]%s", d.Login, d.Host)}
exCmd := exec.Command("ssh", cmd...)
if err := exCmd.Start(); err != nil {
dbg.Fatal("Failed to start the ssh port forwarding:", err)
}
if err := exCmd.Wait(); err != nil {
dbg.Fatal("ssh port forwarding exited in failure:", err)
}
dbg.Lvl3("Setup remote port forwarding", cmd)
go func() {
err := cliutils.SshRunStdout(d.Login, d.Host, "cd remote; GOMAXPROCS=8 ./users")
if err != nil {
dbg.Lvl3(err)
}
d.sshDeter <- "finished"
}()
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:26,代码来源:deterlab.go
示例6: GoSigner
// The signer connects to the leader and then waits for a message to be
// signed
func GoSigner(conf *app.NaiveConfig) {
// Wait for leader to be ready
time.Sleep(2 * time.Second)
host := net.NewTcpHost(app.RunFlags.Hostname)
key := cliutils.KeyPair(suite)
signer := NewPeer(host, ServRole, key.Secret, key.Public)
dbg.Lvl3(signer.String(), "will contact leader", conf.Hosts[0])
l := signer.Open(conf.Hosts[0])
dbg.Lvl3(signer.String(), "is connected to leader", l.PeerName())
// make the protocol for each round
for round := 0; round < conf.Rounds; round++ {
// Receive message
m, err := l.Receive()
dbg.Lvl3(signer.String(), "round", round, "received the message to be signed from the leader")
if err != nil {
dbg.Fatal(signer.String(), "round", round, "received error waiting msg")
}
if m.MsgType != net.MessageSigningType {
dbg.Fatal(app.RunFlags.Hostname, "round", round, "wanted to receive a msg to sign but..",
m.MsgType.String())
}
msg := m.Msg.(net.MessageSigning).Msg
dbg.Lvl3(signer.String(), "round", round, "received msg:", msg[:])
// Generate signature & send
s := signer.Signature(msg[:])
l.Send(*s)
dbg.Lvl3(signer.String(), "round", round, "sent the signature to leader")
}
l.Close()
dbg.Lvl3(app.RunFlags.Hostname, "Finished")
}
开发者ID:mlncn,项目名称:cothority,代码行数:34,代码来源:server.go
示例7: synWithPeer
// SynWithPeer will receive and send the public keys between the peer
// If all goes well, it will add the peer to the remotePeer array
// and notify to the channel synChan
func (p *Peer) synWithPeer(conn net.Conn) {
if conn == nil {
dbg.Fatal("Connection of", p.String(), "is nil")
}
// First we need to SYN mutually
s := Syn{
Id: p.Id,
Public: p.key.Public,
}
err := p.suite.Write(conn, &s)
if err != nil {
dbg.Fatal(p.Name, "could not send SYN to", conn.RemoteAddr().String())
}
// Receive the other SYN
s2 := Syn{}
err = p.suite.Read(conn, &s2)
if err != nil {
dbg.Fatal(p.Name, "could not receive SYN from", conn.RemoteAddr().String())
}
if s2.Id < 0 || s2.Id >= p.info.N {
dbg.Fatal(p.Name, "received wrong SYN info from", conn.RemoteAddr().String())
}
if p.pubKeys[s2.Id] != nil {
dbg.Fatal(p.Name, "already received a SYN for this index ")
}
p.pubKeys[s2.Id] = s2.Public
rp := RemotePeer{Conn: conn, Id: s2.Id, Hostname: conn.RemoteAddr().String()}
p.remote[s2.Id] = rp
dbg.Lvl3(p.String(), "has SYN'd with peer", rp.String())
p.synChan <- s2
}
开发者ID:mlncn,项目名称:cothority,代码行数:34,代码来源:peer.go
示例8: BroadcastSignature
// BroadcastSIgnature will broadcast the given signature to every other peer
// AND will retrieve the signature of every other peer also !
func (p *Peer) BroadcastSignature(s *poly.SchnorrSig) []*poly.SchnorrSig {
arr := make([]*poly.SchnorrSig, 0, p.info.N)
arr = append(arr, s)
err := p.SendToAll(s)
if err != nil {
dbg.Fatal(p.String(), "could not sent to everyone its schnorr sig")
}
sigChan := make(chan *poly.SchnorrSig)
fn := func(rp RemotePeer) {
sch := new(poly.SchnorrSig).Init(p.suite, p.info)
err := p.suite.Read(rp.Conn, sch)
if err != nil {
dbg.Fatal(p.String(), "could not decode schnorr sig from", rp.String())
}
sigChan <- sch
}
// wait for every peers's schnorr sig
p.ForRemotePeers(fn)
n := 0
for {
sig := <-sigChan
arr = append(arr, sig)
n += 1
if n == p.info.N-1 {
dbg.Lvl3(p.String(), "received every other schnorr sig.")
break
}
}
return arr
}
开发者ID:mlncn,项目名称:cothority,代码行数:34,代码来源:peer.go
示例9: ComputeSharedSecret
// ComputeSharedSecret will make the exchange of dealers between
// the peers and will compute the sharedsecret at the end
func (p *Peer) ComputeSharedSecret() *poly.SharedSecret {
// Construct the dealer
dealerKey := cliutils.KeyPair(p.suite)
dealer := new(poly.Deal).ConstructDeal(&dealerKey, &p.key, p.info.T, p.info.R, p.pubKeys)
// Construct the receiver
receiver := poly.NewReceiver(p.suite, p.info, &p.key)
// add already its own dealer
_, err := receiver.AddDeal(p.Id, dealer)
if err != nil {
dbg.Fatal(p.String(), "could not add its own dealer >< ABORT")
}
// Send the dealer struct TO every one
err = p.SendToAll(dealer)
dbg.Lvl3(p.Name, "sent its dealer to every peers. (err =", err, ")")
// Receive the dealer struct FROM every one
// wait with a chan to get ALL dealers
dealChan := make(chan *poly.Deal)
for _, rp := range p.remote {
go func(rp RemotePeer) {
d := new(poly.Deal).UnmarshalInit(p.info.T, p.info.R, p.info.N, p.suite)
err := p.suite.Read(rp.Conn, d)
if err != nil {
dbg.Fatal(p.Name, "received a strange dealer from", rp.String(), ":", err)
}
dealChan <- d
}(rp)
}
// wait to get all dealers
dbg.Lvl3(p.Name, "wait to receive every other peer's dealer...")
n := 0
for {
// get the dealer and add it
d := <-dealChan
dbg.Lvl3(p.Name, "collected one more dealer (count =", n, ")")
// TODO: get the response back to the dealer
_, err := receiver.AddDeal(p.Id, d)
if err != nil {
dbg.Fatal(p.Name, "has error when adding the dealer:", err)
}
n += 1
// we get enough dealers to compute the shared secret
if n == p.info.T-1 {
dbg.Lvl3(p.Name, "received every Dealers")
break
}
}
sh, err := receiver.ProduceSharedSecret()
if err != nil {
dbg.Fatal(p.Name, "could not produce shared secret. Abort. (err", err, ")")
}
dbg.Lvl3(p.Name, "produced shared secret !")
return sh
}
开发者ID:mlncn,项目名称:cothority,代码行数:58,代码来源:peer.go
示例10: WriteTomlConfig
/*
* Writes any structure to a toml-file
*
* Takes a filename and an optional directory-name.
*/
func WriteTomlConfig(conf interface{}, filename string, dirOpt ...string) {
buf := new(bytes.Buffer)
if err := toml.NewEncoder(buf).Encode(conf); err != nil {
dbg.Fatal(err)
}
err := ioutil.WriteFile(getFullName(filename, dirOpt...), buf.Bytes(), 0660)
if err != nil {
dbg.Fatal(err)
}
}
开发者ID:mlncn,项目名称:cothority,代码行数:15,代码来源:app.go
示例11: ReceiveMessage
func (l *Peer) ReceiveMessage(c net.Conn) net.MessageSigning {
app, err := c.Receive()
if err != nil {
dbg.Fatal(l.String(), "could not receive message from", c.PeerName())
}
if app.MsgType != net.MessageSigningType {
dbg.Fatal(l.String(), "MS error: received", app.MsgType.String(), "from", c.PeerName())
}
return app.Msg.(net.MessageSigning)
}
开发者ID:mlncn,项目名称:cothority,代码行数:11,代码来源:peer.go
示例12: ReceiveListBasicSignature
func (l *Peer) ReceiveListBasicSignature(c net.Conn) net.ListBasicSignature {
app, err := c.Receive()
if err != nil {
dbg.Fatal(l.String(), "could not receive listbasicsig from", c.PeerName())
}
if app.MsgType != net.ListBasicSignatureType {
dbg.Fatal(l.String(), "LBS error: received", app.MsgType.String(), "from", c.PeerName())
}
return app.Msg.(net.ListBasicSignature)
}
开发者ID:mlncn,项目名称:cothority,代码行数:12,代码来源:peer.go
示例13: ReceiveBasicSignature
// Wait for the leader to receive the generated signatures from the servers
func (l *Peer) ReceiveBasicSignature(c net.Conn) *net.BasicSignature {
appMsg, err := c.Receive()
if err != nil {
dbg.Fatal(l.String(), "error decoding message from", c.PeerName())
}
if appMsg.MsgType != net.BasicSignatureType {
dbg.Fatal(l.String(), "Received an unknown type:", appMsg.MsgType.String())
}
bs := appMsg.Msg.(net.BasicSignature)
return &bs
}
开发者ID:mlncn,项目名称:cothority,代码行数:13,代码来源:peer.go
示例14: SendMessage
// Will send the message to be signed to everyone
func (l *Peer) SendMessage(msg []byte, c net.Conn) {
if len(msg) > msgMaxLenght {
dbg.Fatal("Tried to send a too big message to sign. Abort")
}
ms := new(net.MessageSigning)
ms.Length = len(msg)
ms.Msg = msg
err := c.Send(*ms)
if err != nil {
dbg.Fatal("Could not send message to", c.PeerName())
}
}
开发者ID:mlncn,项目名称:cothority,代码行数:13,代码来源:peer.go
示例15: SchnorrSigRoot
// SchnorrSigRoot will first generate a
// random shared secret, then start a new round
// It will wait for the partial sig of the peers
// to finally render a SchnorrSig struct
func (p *Peer) SchnorrSigRoot(msg []byte) *poly.SchnorrSig {
// First, gen. a random secret
random := p.ComputeSharedSecret()
// gen the hash out of the msg
h := p.suite.Hash()
h.Write(msg)
// launch the new round
err := p.schnorr.NewRound(random, h)
if err != nil {
dbg.Fatal(p.String(), "could not make a new round:", err)
}
// compute its own share of the signature
ps := p.schnorr.RevealPartialSig()
// add its own
p.schnorr.AddPartialSig(ps)
// no need to send to all if you are the root
// p.SendToAll(ps)
// then receive every partial sig
sigChan := make(chan *poly.SchnorrPartialSig)
fn := func(rp RemotePeer) {
psig := new(poly.SchnorrPartialSig)
err := p.suite.Read(rp.Conn, psig)
if err != nil {
dbg.Fatal(p.String(), "could not decode PartialSig of", rp.String())
}
sigChan <- psig
}
p.ForRemotePeers(fn)
// wait for all partial sig to be received
n := 0
for {
psig := <-sigChan
err := p.schnorr.AddPartialSig(psig)
if err != nil {
dbg.Fatal(p.String(), "could not add the partial signature received:", err)
}
n += 1
if n == p.info.N-1 {
dbg.Lvl3(p.String(), "received every other partial sig.")
break
}
}
sign, err := p.schnorr.Sig()
if err != nil {
dbg.Fatal(p.String(), "could not generate the global SchnorrSig", err)
}
return sign
}
开发者ID:mlncn,项目名称:cothority,代码行数:56,代码来源:peer.go
示例16: main
func main() {
Current := new(Node)
Magic := [4]byte{0xF9, 0xBE, 0xB4, 0xD9}
Current.IP = net.IPv4(0, 1, 2, 3)
Current.PublicKey = "my_cool_key"
Current.Last_Block = "0"
Parser, _ := BitCoSi.NewParser("/home/lefteris/hi/blocks", Magic)
server := "localhost:2011"
// suite = app.GetSuite("25519")
dbg.Lvl2("Connecting to", server)
conn := coconet.NewTCPConn(server)
err := conn.Connect()
if err != nil {
dbg.Fatal("Error when getting the connection to the host:", err)
}
dbg.Lvl1("Connected to ", server)
go wait_for_blocks()
for i := 0; i < 10; i++ {
Current.transaction_pool = Parser.Parse(i, 10+i)
for len(Current.transaction_pool) > 0 {
msg := &BitCoSi.BitCoSiMessage{
Type: BitCoSi.TransactionAnnouncmentType,
ReqNo: 0,
Treq: &BitCoSi.TransactionAnnouncment{Val: Current.transaction_pool[0]}}
err = conn.PutData(msg)
Current.transaction_pool = Current.transaction_pool[1:]
if err != nil {
dbg.Fatal("Couldn't send hash-message to server: ", err)
}
time.Sleep(10 * time.Millisecond)
}
}
wait_for_Key_blocks()
time.Sleep(900000 * time.Millisecond)
// Asking to close the connection
err = conn.PutData(&BitCoSi.BitCoSiMessage{
ReqNo: 1,
Type: BitCoSi.BitCoSiClose,
})
conn.Close()
dbg.Lvl2("Connection closed with server")
}
开发者ID:LefKok,项目名称:Coin,代码行数:51,代码来源:client.go
示例17: wait_for_blocks
func wait_for_blocks() {
server := "localhost:2011"
suite = app.GetSuite("25519")
dbg.Lvl2("Connecting to", server)
conn := coconet.NewTCPConn(server)
err := conn.Connect()
if err != nil {
dbg.Fatal("Error when getting the connection to the host:", err)
}
dbg.Lvl1("Connected to ", server)
for i := 0; i < 1000; i++ {
time.Sleep(1 * time.Second)
msg := &BitCoSi.BitCoSiMessage{
Type: BitCoSi.BlockRequestType,
ReqNo: 0,
}
err = conn.PutData(msg)
if err != nil {
dbg.Fatal("Couldn't send hash-message to server: ", err)
}
dbg.Lvl1("Sent signature request")
// Wait for the signed message
tsm := new(BitCoSi.BitCoSiMessage)
tsm.Brep = &BitCoSi.BlockReply{}
tsm.Brep.SuiteStr = suite.String()
err = conn.GetData(tsm)
if err != nil {
dbg.Fatal("Error while receiving signature:", err)
}
//dbg.Lvlf1("Got signature response %+v", tsm.Brep)
T := new(BitCoSi.TrBlock)
T.Block = tsm.Brep.Block
T.Print()
dbg.Lvlf1("Response %v ", tsm.Brep.Response)
}
// Asking to close the connection
err = conn.PutData(&BitCoSi.BitCoSiMessage{
ReqNo: 1,
Type: BitCoSi.BitCoSiClose,
})
conn.Close()
}
开发者ID:LefKok,项目名称:Coin,代码行数:49,代码来源:client.go
示例18: NewPeer
// NewPeer returns a peer that can be used to set up
// connections.
func NewPeer(address string, conf *app.ConfigConode) *Peer {
suite := app.GetSuite(conf.Suite)
var err error
// make sure address has a port or insert default one
address, err = cliutils.VerifyPort(address, DefaultPort)
if err != nil {
dbg.Fatal(err)
}
// For retro compatibility issues, convert the base64 encoded key into hex
// encoded keys....
convertTree(suite, conf.Tree)
// Add our private key to the tree (compatibility issues again with graphs/
// lib)
addPrivateKey(suite, address, conf)
// load the configuration
dbg.Lvl3("loading configuration")
var hc *graphs.HostConfig
opts := graphs.ConfigOptions{ConnType: "tcp", Host: address, Suite: suite}
hc, err = graphs.LoadConfig(conf.Hosts, conf.Tree, suite, opts)
if err != nil {
dbg.Fatal(err)
}
// Listen to stamp-requests on port 2001
node := hc.Hosts[address]
peer := &Peer{
conf: conf,
Node: node,
RLock: sync.Mutex{},
CloseChan: make(chan bool, 5),
Hostname: address,
}
// Start the cothority-listener on port 2000
err = hc.Run(true, sign.MerkleTree, address)
if err != nil {
dbg.Fatal(err)
}
go func() {
err := peer.Node.Listen()
dbg.Lvl3("Node.listen quits with status", err)
peer.CloseChan <- true
peer.Close()
}()
return peer
}
开发者ID:mlncn,项目名称:cothority,代码行数:51,代码来源:peer.go
示例19: Listen
func (p *Peer) Listen() {
results := strings.Split(p.Name, ":")
port := ":" + results[1]
ln, err := net.Listen("tcp", port)
if err != nil {
dbg.Fatal(p.Name, ": Error while listening on port", port, "ABORT =>", err)
}
for {
conn, err := ln.Accept()
if err != nil {
dbg.Fatal(p.Name, ": Error while listening on port", port, "=>", err)
}
go p.synWithPeer(conn)
}
}
开发者ID:mlncn,项目名称:cothority,代码行数:15,代码来源:peer.go
示例20: readKeyFile
// readKeyPair will read both private and public files
// and returns a keypair containing the respective private and public keys
func readKeyFile(keyFile string) (config.KeyPair, string) {
sec, err := cliutils.ReadPrivKey(suite, namePriv(keyFile))
if err != nil {
dbg.Fatal("Could not read private key:", err)
}
pub, addr, err := cliutils.ReadPubKey(suite, namePub(keyFile))
if err != nil {
dbg.Fatal("Could not read public key:", err)
}
return config.KeyPair{
Suite: suite,
Secret: sec,
Public: pub,
}, addr
}
开发者ID:mlncn,项目名称:cothority,代码行数:17,代码来源:validate.go
注:本文中的github.com/dedis/cothority/lib/dbg.Fatal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论