本文整理汇总了Golang中github.com/dedis/cothority/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: CheckHosts
// CheckHosts verifies that there is either a 'Hosts' or a 'Depth/BF'
// -parameter in the Runconfig
func CheckHosts(rc platform.RunConfig) {
hosts, _ := rc.GetInt("hosts")
bf, _ := rc.GetInt("bf")
depth, _ := rc.GetInt("depth")
if hosts == 0 {
if depth == 0 || bf == 0 {
log.Fatal("No Hosts and no Depth or BF given - stopping")
}
hosts = calcHosts(bf, depth)
rc.Put("hosts", strconv.Itoa(hosts))
}
if bf == 0 {
if depth == 0 || hosts == 0 {
log.Fatal("No BF and no Depth or hosts given - stopping")
}
bf = 2
for calcHosts(bf, depth) < hosts {
bf++
}
rc.Put("bf", strconv.Itoa(bf))
}
if depth == 0 {
depth = 1
for calcHosts(bf, depth) < hosts {
depth++
}
rc.Put("depth", strconv.Itoa(depth))
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:31,代码来源:simul.go
示例2: CreateRoster
// CreateRoster creates an Roster with the host-names in 'addresses'.
// It creates 's.Hosts' entries, starting from 'port' for each round through
// 'addresses'
func (s *SimulationBFTree) CreateRoster(sc *SimulationConfig, addresses []string, port int) {
start := time.Now()
nbrAddr := len(addresses)
if sc.PrivateKeys == nil {
sc.PrivateKeys = make(map[string]abstract.Scalar)
}
hosts := s.Hosts
if s.SingleHost {
// If we want to work with a single host, we only make one
// host per server
log.Fatal("Not supported yet")
hosts = nbrAddr
if hosts > s.Hosts {
hosts = s.Hosts
}
}
localhosts := false
listeners := make([]net.Listener, hosts)
if strings.Contains(addresses[0], "localhost") {
localhosts = true
}
entities := make([]*network.ServerIdentity, hosts)
log.Lvl3("Doing", hosts, "hosts")
key := config.NewKeyPair(network.Suite)
for c := 0; c < hosts; c++ {
key.Secret.Add(key.Secret,
key.Suite.Scalar().One())
key.Public.Add(key.Public,
key.Suite.Point().Base())
address := addresses[c%nbrAddr] + ":"
if localhosts {
// If we have localhosts, we have to search for an empty port
var err error
listeners[c], err = net.Listen("tcp", ":0")
if err != nil {
log.Fatal("Couldn't search for empty port:", err)
}
_, p, _ := net.SplitHostPort(listeners[c].Addr().String())
address += p
log.Lvl4("Found free port", address)
} else {
address += strconv.Itoa(port + c/nbrAddr)
}
entities[c] = network.NewServerIdentity(key.Public, address)
sc.PrivateKeys[entities[c].Addresses[0]] = key.Secret
}
// And close all our listeners
if localhosts {
for _, l := range listeners {
err := l.Close()
if err != nil {
log.Fatal("Couldn't close port:", l, err)
}
}
}
sc.Roster = NewRoster(entities)
log.Lvl3("Creating entity List took: " + time.Now().Sub(start).String())
}
开发者ID:nikirill,项目名称:cothority,代码行数:62,代码来源:simulation.go
示例3: WriteTomlConfig
// WriteTomlConfig write 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 {
log.Fatal(err)
}
err := ioutil.WriteFile(getFullName(filename, dirOpt...), buf.Bytes(), 0660)
if err != nil {
log.Fatal(err)
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:12,代码来源:utils.go
示例4: main
// Reads in the platform that we want to use and prepares for the tests
func main() {
flag.Parse()
deployP = platform.NewPlatform(platformDst)
if deployP == nil {
log.Fatal("Platform not recognized.", platformDst)
}
log.Lvl1("Deploying to", platformDst)
simulations := flag.Args()
if len(simulations) == 0 {
log.Fatal("Please give a simulation to run")
}
for _, simulation := range simulations {
runconfigs := platform.ReadRunFile(deployP, simulation)
if len(runconfigs) == 0 {
log.Fatal("No tests found in", simulation)
}
deployP.Configure(&platform.Config{
MonitorPort: monitorPort,
Debug: log.DebugVisible(),
})
if clean {
err := deployP.Deploy(runconfigs[0])
if err != nil {
log.Fatal("Couldn't deploy:", err)
}
if err := deployP.Cleanup(); err != nil {
log.Error("Couldn't cleanup correctly:", err)
}
} else {
logname := strings.Replace(filepath.Base(simulation), ".toml", "", 1)
testsDone := make(chan bool)
go func() {
RunTests(logname, runconfigs)
testsDone <- true
}()
timeout := getExperimentWait(runconfigs)
select {
case <-testsDone:
log.Lvl3("Done with test", simulation)
case <-time.After(time.Second * time.Duration(timeout)):
log.Fatal("Test failed to finish in", timeout, "seconds")
}
}
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:50,代码来源:simul.go
示例5: UnmarshalJSON
func (sr *BlockReply) UnmarshalJSON(dataJSON []byte) error {
type Alias BlockReply
//log.Print("Starting unmarshal")
suite, err := suites.StringToSuite(sr.SuiteStr)
if err != nil {
return err
}
aux := &struct {
SignatureInfo []byte
Response abstract.Scalar
Challenge abstract.Scalar
AggCommit abstract.Point
AggPublic abstract.Point
*Alias
}{
Response: suite.Scalar(),
Challenge: suite.Scalar(),
AggCommit: suite.Point(),
AggPublic: suite.Point(),
Alias: (*Alias)(sr),
}
//log.Print("Doing JSON unmarshal")
if err := json.Unmarshal(dataJSON, &aux); err != nil {
return err
}
if err := suite.Read(bytes.NewReader(aux.SignatureInfo), &sr.Response, &sr.Challenge, &sr.AggCommit, &sr.AggPublic); err != nil {
log.Fatal("decoding signature Response / Challenge / AggCommit: ", err)
return err
}
return nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:31,代码来源:messg.go
示例6: listen
// listen starts listening for messages coming from any host that tries to
// contact this host. If 'wait' is true, it will try to connect to itself before
// returning.
func (h *Host) listen(wait bool) {
log.Lvl3(h.ServerIdentity.First(), "starts to listen")
fn := func(c network.SecureConn) {
log.Lvl3(h.workingAddress, "Accepted Connection from", c.Remote())
// register the connection once we know it's ok
h.registerConnection(c)
h.handleConn(c)
}
go func() {
log.Lvl4("Host listens on:", h.workingAddress)
err := h.host.Listen(fn)
if err != nil {
log.Fatal("Couldn't listen on", h.workingAddress, ":", err)
}
}()
if wait {
for {
log.Lvl4(h.ServerIdentity.First(), "checking if listener is up")
_, err := h.Connect(h.ServerIdentity)
if err == nil {
log.Lvl4(h.ServerIdentity.First(), "managed to connect to itself")
break
}
time.Sleep(network.WaitRetry)
}
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:30,代码来源:host.go
示例7: GetBlockDir
// Gets the block-directory starting from the current directory - this will
// hold up when running it with 'simul'
func GetBlockDir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal("Couldn't get working dir:", err)
}
return dir + "/blocks"
}
开发者ID:nikirill,项目名称:cothority,代码行数:9,代码来源:parser.go
示例8: readRunConfig
// Read a config file and fills up some fields for Stats struct
func (s *Stats) readRunConfig(rc map[string]string, defaults ...string) {
// First find the defaults keys
for _, def := range defaults {
valStr, ok := rc[def]
if !ok {
log.Fatal("Could not find the default value", def, "in the RunConfig")
}
if i, err := strconv.Atoi(valStr); err != nil {
log.Fatal("Could not parse to integer value", def)
} else {
// registers the static value
s.static[def] = i
s.staticKeys = append(s.staticKeys, def)
}
}
// Then parse the others keys
var statics []string
for k, v := range rc {
// pass the ones we already registered
var alreadyRegistered bool
for _, def := range defaults {
if k == def {
alreadyRegistered = true
break
}
}
if alreadyRegistered {
continue
}
// store it
if i, err := strconv.Atoi(v); err != nil {
log.Lvl3("Could not parse the value", k, "from runconfig (v=", v, ")")
continue
} else {
s.static[k] = i
statics = append(statics, k)
}
}
// sort them so it's always the same order
sort.Strings(statics)
// append them to the defaults one
s.staticKeys = append(s.staticKeys, statics...)
// let the filter figure out itself what it is supposed to be doing
s.filter = NewDataFilter(rc)
}
开发者ID:nikirill,项目名称:cothority,代码行数:47,代码来源:stats.go
示例9: Deploy
// Deploy copies all files to the run-directory
func (d *Localhost) Deploy(rc RunConfig) error {
if runtime.GOOS == "darwin" {
files, err := exec.Command("ulimit", "-n").Output()
if err != nil {
log.Fatal("Couldn't check for file-limit:", err)
}
filesNbr, err := strconv.Atoi(strings.TrimSpace(string(files)))
if err != nil {
log.Fatal("Couldn't convert", files, "to a number:", err)
}
hosts, _ := strconv.Atoi(rc.Get("hosts"))
if filesNbr < hosts*2 {
maxfiles := 10000 + hosts*2
log.Fatalf("Maximum open files is too small. Please run the following command:\n"+
"sudo sysctl -w kern.maxfiles=%d\n"+
"sudo sysctl -w kern.maxfilesperproc=%d\n"+
"ulimit -n %d\n"+
"sudo sysctl -w kern.ipc.somaxconn=2048\n",
maxfiles, maxfiles, maxfiles)
}
}
d.servers, _ = strconv.Atoi(rc.Get("servers"))
log.Lvl2("Localhost: Deploying and writing config-files for", d.servers, "servers")
sim, err := sda.NewSimulation(d.Simulation, string(rc.Toml()))
if err != nil {
return err
}
d.addresses = make([]string, d.servers)
for i := range d.addresses {
d.addresses[i] = "localhost" + strconv.Itoa(i)
}
d.sc, err = sim.Setup(d.runDir, d.addresses)
if err != nil {
return err
}
d.sc.Config = string(rc.Toml())
if err := d.sc.Save(d.runDir); err != nil {
return err
}
log.Lvl2("Localhost: Done deploying")
return nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:45,代码来源:localhost.go
示例10: Save
// Save takes everything in the SimulationConfig structure and saves it to
// dir + SimulationFileName
func (sc *SimulationConfig) Save(dir string) error {
network.RegisterMessageType(&SimulationConfigFile{})
scf := &SimulationConfigFile{
TreeMarshal: sc.Tree.MakeTreeMarshal(),
Roster: sc.Roster,
PrivateKeys: sc.PrivateKeys,
Config: sc.Config,
}
buf, err := network.MarshalRegisteredType(scf)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(dir+"/"+SimulationFileName, buf, 0660)
if err != nil {
log.Fatal(err)
}
return nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:21,代码来源:simulation.go
示例11: 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
示例12: Setup
// Setup implements sda.Simulation interface. It checks on the availability
// of the block-file and downloads it if missing. Then the block-file will be
// copied to the simulation-directory
func (e *Simulation) Setup(dir string, hosts []string) (*sda.SimulationConfig, error) {
err := blockchain.EnsureBlockIsAvailable(dir)
if err != nil {
log.Fatal("Couldn't get block:", err)
}
sc := &sda.SimulationConfig{}
e.CreateRoster(sc, hosts, 2000)
err = e.CreateTree(sc)
if err != nil {
return nil, err
}
return sc, nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:16,代码来源:byzcoin_simulation.go
示例13: Configure
// Configure various internal variables
func (d *Localhost) Configure(pc *Config) {
pwd, _ := os.Getwd()
d.runDir = pwd + "/platform/localhost"
d.localDir = pwd
d.debug = pc.Debug
d.running = false
d.monitorPort = pc.MonitorPort
d.errChan = make(chan error)
if d.Simulation == "" {
log.Fatal("No simulation defined in simulation")
}
log.Lvl3(fmt.Sprintf("Localhost dirs: RunDir %s", d.runDir))
log.Lvl3("Localhost configured ...")
}
开发者ID:nikirill,项目名称:cothority,代码行数:15,代码来源:localhost.go
示例14: TestReadRunfile
func TestReadRunfile(t *testing.T) {
log.TestOutput(testing.Verbose(), 2)
tplat := &TPlat{}
tmpfile := "/tmp/testrun.toml"
err := ioutil.WriteFile(tmpfile, []byte(testfile), 0666)
if err != nil {
log.Fatal("Couldn't create file:", err)
}
tests := platform.ReadRunFile(tplat, tmpfile)
log.Lvl2(tplat)
log.Lvlf2("%+v\n", tests[0])
if tplat.App != "sign" {
log.Fatal("App should be 'sign'")
}
if len(tests) != 2 {
log.Fatal("There should be 2 tests")
}
if tests[0].Get("machines") != "8" {
log.Fatal("Machines = 8 has not been copied into RunConfig")
}
}
开发者ID:nikirill,项目名称:cothority,代码行数:23,代码来源:platform_test.go
示例15: ReadTomlConfig
// ReadTomlConfig read any structure from a toml-file
// Takes a filename and an optional directory-name
func ReadTomlConfig(conf interface{}, filename string, dirOpt ...string) error {
buf, err := ioutil.ReadFile(getFullName(filename, dirOpt...))
if err != nil {
pwd, _ := os.Getwd()
log.Lvl1("Didn't find", filename, "in", pwd)
return err
}
_, err = toml.Decode(string(buf), conf)
if err != nil {
log.Fatal(err)
}
return nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:17,代码来源:utils.go
示例16: deterFromConfig
// Reads in the deterlab-config and drops out if there is an error
func deterFromConfig(name ...string) *platform.Deterlab {
d := &platform.Deterlab{}
configName := "deter.toml"
if len(name) > 0 {
configName = name[0]
}
err := sda.ReadTomlConfig(d, configName)
_, caller, line, _ := runtime.Caller(1)
who := caller + ":" + strconv.Itoa(line)
if err != nil {
log.Fatal("Couldn't read config in", who, ":", err)
}
log.SetDebugVisible(d.Debug)
return d
}
开发者ID:nikirill,项目名称:cothority,代码行数:16,代码来源:users.go
示例17: Dispatch
// Dispatch can handle timeouts
func (p *Propagate) Dispatch() error {
process := true
log.Lvl4(p.ServerIdentity())
for process {
p.Lock()
timeout := time.Millisecond * time.Duration(p.sd.Msec)
p.Unlock()
select {
case msg := <-p.ChannelSD:
log.Lvl3(p.ServerIdentity(), "Got data from", msg.ServerIdentity)
if p.onData != nil {
_, netMsg, err := network.UnmarshalRegistered(msg.Data)
if err == nil {
p.onData(netMsg)
}
}
if !p.IsRoot() {
log.Lvl3(p.ServerIdentity(), "Sending to parent")
p.SendToParent(&PropagateReply{})
}
if p.IsLeaf() {
process = false
} else {
log.Lvl3(p.ServerIdentity(), "Sending to children")
p.SendToChildren(&msg.PropagateSendData)
}
case <-p.ChannelReply:
p.received++
log.Lvl4(p.ServerIdentity(), "received:", p.received, p.subtree)
if !p.IsRoot() {
p.SendToParent(&PropagateReply{})
}
if p.received == p.subtree {
process = false
}
case <-time.After(timeout):
log.Fatal("Timeout")
process = false
}
}
if p.IsRoot() {
if p.onDoneCb != nil {
p.onDoneCb(p.received + 1)
}
}
p.Done()
return nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:49,代码来源:propagate.go
示例18: Build
// Build makes sure that the binary is available for our local platform
func (d *Localhost) Build(build string, arg ...string) error {
src := "./cothority"
dst := d.runDir + "/" + d.Simulation
start := time.Now()
// build for the local machine
res, err := Build(src, dst,
runtime.GOARCH, runtime.GOOS,
arg...)
if err != nil {
log.Fatal("Error while building for localhost (src", src, ", dst", dst, ":", res)
}
log.Lvl3("Localhost: Build src", src, ", dst", dst)
log.Lvl4("Localhost: Results of localhost build:", res)
log.Lvl2("Localhost: build finished in", time.Since(start))
return err
}
开发者ID:nikirill,项目名称:cothority,代码行数:17,代码来源:localhost.go
示例19: TestStatsString
func TestStatsString(t *testing.T) {
rc := map[string]string{"servers": "10", "hosts": "10"}
rs := NewStats(rc)
m := NewMonitor(rs)
go func() {
if err := m.Listen(); err != nil {
log.Fatal("Could not Listen():", err)
}
}()
time.Sleep(100 * time.Millisecond)
ConnectSink("localhost:10000")
measure := NewTimeMeasure("test")
time.Sleep(time.Millisecond * 100)
measure.Record()
time.Sleep(time.Millisecond * 100)
if !strings.Contains(rs.String(), "0.1") {
t.Fatal("The measurement should contain 0.1:", rs.String())
}
m.Stop()
}
开发者ID:nikirill,项目名称:cothority,代码行数:22,代码来源:stats_test.go
示例20: GenLocalHosts
// GenLocalHosts will create n hosts with the first one being connected to each of
// the other nodes if connect is true.
func GenLocalHosts(n int, connect bool, processMessages bool) []*Host {
hosts := make([]*Host, n)
for i := 0; i < n; i++ {
host := NewLocalHost(2000 + i*10)
hosts[i] = host
}
root := hosts[0]
for _, host := range hosts {
host.ListenAndBind()
log.Lvlf3("Listening on %s %x", host.ServerIdentity.First(), host.ServerIdentity.ID)
if processMessages {
host.StartProcessMessages()
}
if connect && root != host {
log.Lvl4("Connecting", host.ServerIdentity.First(), host.ServerIdentity.ID, "to",
root.ServerIdentity.First(), root.ServerIdentity.ID)
if _, err := host.Connect(root.ServerIdentity); err != nil {
log.Fatal(host.ServerIdentity.Addresses, "Could not connect hosts", root.ServerIdentity.Addresses, err)
}
// Wait for connection accepted in root
connected := false
for !connected {
time.Sleep(time.Millisecond * 10)
root.networkLock.Lock()
for id := range root.connections {
if id.Equal(host.ServerIdentity.ID) {
connected = true
break
}
}
root.networkLock.Unlock()
}
log.Lvl4(host.ServerIdentity.First(), "is connected to root")
}
}
return hosts
}
开发者ID:nikirill,项目名称:cothority,代码行数:40,代码来源:local.go
注:本文中的github.com/dedis/cothority/log.Fatal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论