本文整理汇总了Golang中github.com/dedis/cothority/lib/dbg.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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)
}
}
}
示例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
}
示例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
}
示例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")
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
示例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)
}
示例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
}
示例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())
}
}
示例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
}