本文整理汇总了Golang中github.com/dedis/cothority/lib/dbg.Lvl3函数的典型用法代码示例。如果您正苦于以下问题:Golang Lvl3函数的具体用法?Golang Lvl3怎么用?Golang Lvl3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Lvl3函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Start
func (d *Localhost) Start(args ...string) error {
os.Chdir(d.RunDir)
dbg.Lvl4("Localhost: chdir into", d.RunDir)
ex := d.RunDir + "/" + d.App
dbg.Lvl4("Localhost: in Start() => hosts", d.Hosts)
d.running = true
dbg.Lvl1("Starting", len(d.Hosts), "applications of", ex)
for index, host := range d.Hosts {
dbg.Lvl3("Starting", index, "=", host)
amroot := fmt.Sprintf("-amroot=%s", strconv.FormatBool(index == 0))
cmdArgs := []string{"-hostname", host, "-mode", "server", "-logger",
"localhost:" + monitor.SinkPort, amroot}
cmdArgs = append(args, cmdArgs...)
dbg.Lvl3("CmdArgs are", cmdArgs)
cmd := exec.Command(ex, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
go func(i int, h string) {
dbg.Lvl3("Localhost: will start host", host)
d.wg_run.Add(1)
err := cmd.Run()
if err != nil {
dbg.Lvl3("Error running localhost", h, ":", err)
}
d.wg_run.Done()
dbg.Lvl3("host (index", i, ")", h, "done")
}(index, host)
}
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:30,代码来源:localhost.go
示例2: StatusReturn
// StatusReturn just adds up all children and sends the result to
// the parent
func (sn *Node) StatusReturn(view int, sm *SigningMessage) error {
sn.PeerStatusRcvd += 1
sn.PeerStatus.Responders += sm.SRm.Responders
sn.PeerStatus.Peers += sm.SRm.Peers
// Wait for other children before propagating the message
if sn.PeerStatusRcvd < len(sn.Children(view)) {
dbg.Lvl3(sn.Name(), "Waiting for other children")
return nil
}
var err error = nil
if sn.IsRoot(view) {
// Add the root-node
sn.PeerStatus.Peers += 1
dbg.Lvl3("We got", sn.PeerStatus.Responders, "responses from", sn.PeerStatus.Peers, "peers.")
} else {
dbg.Lvl4(sn.Name(), "puts up statusReturn for", sn.PeerStatus)
ctx := context.TODO()
sm.SRm = &sn.PeerStatus
err = sn.PutUp(ctx, view, sm)
}
dbg.Lvl3("Deleting round", sm.RoundNbr, sn.Rounds)
delete(sn.Rounds, sm.RoundNbr)
return err
}
开发者ID:mlncn,项目名称:cothority,代码行数:28,代码来源:nodeprotocol.go
示例3: SigScanner
// Scanner for a file contatining singatures
func SigScanner(filename string) ([]string, error) {
var blocks []string
head := "-----BEGIN PGP SIGNATURE-----"
dbg.Lvl3("Reading file", filename)
file, err := os.Open(filename)
defer file.Close()
if err != nil {
dbg.Lvl1("Couldn't open file", file, err)
return nil, err
}
scanner := bufio.NewScanner(file)
var block []string
for scanner.Scan() {
text := scanner.Text()
dbg.Lvl3("Decoding", text)
// end of the first part
if text == head {
dbg.Lvl3("Found header")
if len(block) > 0 {
blocks = append(blocks, strings.Join(block, "\n"))
block = make([]string, 0)
}
}
block = append(block, text)
}
blocks = append(blocks, strings.Join(block, "\n"))
return blocks, nil
}
开发者ID:nikirill,项目名称:cothority,代码行数:31,代码来源:parser.go
示例4: LoadEdgeList
// takes in a byte array representing an edge list and loads the graph
func (g *Graph) LoadEdgeList(edgelist []byte) {
dbg.Lvl3(g.Names)
fields := bytes.Fields(edgelist)
// create name map from string to index
dbg.Lvl3(g.Names)
names := make(map[string]int)
for i, n := range g.Names {
names[n] = i
}
// read fields in groups of three: from, to, edgeweight
for i := 0; i < len(fields)-2; i += 3 {
from := string(fields[i])
to := string(fields[i+1])
weight, err := strconv.ParseFloat(string(fields[i+2]), 64)
if err != nil {
dbg.Lvl3(err)
continue
}
fi, ok := names[from]
if !ok {
dbg.Lvl3("from not ok:", from)
continue
}
ti, ok := names[to]
if !ok {
dbg.Lvl3("to not ok:", to)
continue
}
g.Weights[fi][ti] = weight
}
}
开发者ID:mlncn,项目名称:cothority,代码行数:35,代码来源:graph.go
示例5: String
func (hc *HostConfig) String() string {
b := bytes.NewBuffer([]byte{})
// write the hosts
b.WriteString("{\"hosts\": [")
for i, sn := range hc.SNodes {
if i != 0 {
b.WriteString(", ")
}
b.WriteString("\"" + sn.Name() + "\"")
}
b.WriteString("],")
// write the tree structure
b.WriteString("\"tree\": ")
if len(hc.SNodes) != 0 {
root := hc.SNodes[0]
writeHC(b, hc, root)
} else {
b.WriteString("{}")
}
b.WriteString("}\n")
// format the resulting JSON for readability
bformatted := bytes.NewBuffer([]byte{})
err := json.Indent(bformatted, b.Bytes(), "", "\t")
if err != nil {
dbg.Lvl3(string(b.Bytes()))
dbg.Lvl3("ERROR:", err)
}
return string(bformatted.Bytes())
}
开发者ID:mlncn,项目名称:cothority,代码行数:33,代码来源:node.go
示例6: CloseAll
func (sn *Node) CloseAll(view int) error {
dbg.Lvl2(sn.Name(), "received CloseAll on", view)
// At the leaves
if len(sn.Children(view)) == 0 {
dbg.Lvl3(sn.Name(), "in CloseAll is root leaf")
} else {
dbg.Lvl3(sn.Name(), "in CloseAll is calling", len(sn.Children(view)), "children")
// Inform all children of announcement
messgs := make([]coconet.BinaryMarshaler, sn.NChildren(view))
for i := range messgs {
sm := SigningMessage{
Suite: sn.Suite().String(),
Type: CloseAll,
ViewNbr: view,
//LastSeenVote: int(atomic.LoadInt64(&sn.LastSeenVote)),
}
messgs[i] = &sm
}
ctx := context.TODO()
if err := sn.PutDown(ctx, view, messgs); err != nil {
return err
}
}
dbg.Lvl3("Closing down shop", sn.Isclosed)
sn.Close()
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:29,代码来源:nodehelper.go
示例7: 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
示例8: PrintTreeNode
func PrintTreeNode(t *Tree) {
dbg.Lvl3(t.Name)
for _, c := range t.Children {
dbg.Lvl3("\t", c.Name)
}
}
开发者ID:mlncn,项目名称:cothority,代码行数:7,代码来源:tree.go
示例9: TestStamp
// Runs two conodes and tests if the value returned is OK
func TestStamp(t *testing.T) {
dbg.TestOutput(testing.Verbose(), 4)
peer1, peer2 := createPeers()
go peer1.LoopRounds(conode.RoundStamperListenerType, 4)
go peer2.LoopRounds(conode.RoundStamperListenerType, 4)
time.Sleep(2 * time.Second)
s, err := conode.NewStamp("testdata/config.toml")
if err != nil {
t.Fatal("Couldn't open config-file:", err)
}
for _, port := range []int{7000, 7010} {
stamper := "localhost:" + strconv.Itoa(port)
dbg.Lvl2("Contacting stamper", stamper)
tsm, err := s.GetStamp([]byte("test"), stamper)
dbg.Lvl3("Evaluating results of", stamper)
if err != nil {
t.Fatal("Couldn't get stamp from server:", err)
}
if !tsm.Srep.AggPublic.Equal(s.X0) {
t.Fatal("Not correct aggregate public key")
}
}
dbg.Lvl2("Closing peer1")
peer1.Close()
dbg.Lvl2("Closing peer2")
peer2.Close()
dbg.Lvl3("Done with test")
}
开发者ID:mlncn,项目名称:cothority,代码行数:33,代码来源:stamp_test.go
示例10: 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
示例11: Filter
// Filter out a serie of values
func (df *DataFilter) Filter(measure string, values []float64) []float64 {
// do we have a filter for this measure ?
if _, ok := df.percentiles[measure]; !ok {
return values
}
// Compute the percentile value
max, err := stats.PercentileNearestRank(values, df.percentiles[measure])
if err != nil {
dbg.Lvl2("Monitor: Error filtering data:", err)
return values
}
// Find the index from where to filter
maxIndex := -1
for i, v := range values {
if v > max {
maxIndex = i
}
}
// check if we foud something to filter out
if maxIndex == -1 {
dbg.Lvl3("Filtering: nothing to filter for", measure)
return values
}
// return the values below the percentile
dbg.Lvl3("Filtering: filters out", measure, ":", maxIndex, "/", len(values))
return values[:maxIndex]
}
开发者ID:mlncn,项目名称:cothority,代码行数:29,代码来源:stats.go
示例12: Challenge
// initiated by root, propagated by all others
func (sn *Node) Challenge(sm *SigningMessage) error {
view := sm.ViewNbr
RoundNbr := sm.RoundNbr
dbg.Lvl3("Challenge for round", RoundNbr)
// update max seen round
sn.roundmu.Lock()
sn.LastSeenRound = max(sn.LastSeenRound, RoundNbr)
sn.roundmu.Unlock()
children := sn.Children(view)
challs := make([]*SigningMessage, len(children))
i := 0
for child := range children {
challs[i] = &SigningMessage{
Suite: sn.Suite().String(),
ViewNbr: view,
RoundNbr: RoundNbr,
Type: Challenge,
To: child,
Chm: &ChallengeMessage{
Message: make([]byte, 0),
}}
i++
}
round := sn.Rounds[RoundNbr]
if round == nil {
dbg.Lvl3("No Round Interface created for this round. Children:",
len(children))
} else {
err := round.Challenge(sm, challs)
if err != nil {
return err
}
}
// if we are a leaf, send the respond up
if len(children) == 0 {
sn.Respond(&SigningMessage{
Suite: sn.Suite().String(),
Type: Response,
ViewNbr: view,
RoundNbr: RoundNbr,
})
} else {
// otherwise continue to pass down challenge
for _, out := range challs {
if out.To != "" {
conn := children[out.To]
conn.PutData(out)
} else {
dbg.Error("Out.To == nil with children", children)
}
}
}
// dbg.Lvl4(sn.Name(), "Done handling challenge message")
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:60,代码来源:nodeprotocol.go
示例13: EnableMeasure
// Enables / Disables a measure.
func EnableMeasure(b bool) {
if b {
dbg.Lvl3("Monitor: Measure enabled")
} else {
dbg.Lvl3("Monitor: Measure disabled")
}
enabled = b
}
开发者ID:mlncn,项目名称:cothority,代码行数:9,代码来源:measure.go
示例14: 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
示例15: SignatureBroadcast
// This will broadcast the final signature to give to client
// it contins the global Response adn global challenge
func (sn *Node) SignatureBroadcast(sm *SigningMessage) error {
view := sm.ViewNbr
RoundNbr := sm.RoundNbr
dbg.Lvl3(sn.Name(), "received SignatureBroadcast on", view)
sn.PeerStatusRcvd = 0
ri := sn.Rounds[RoundNbr]
if ri == nil {
return fmt.Errorf("No round created for this round number (signature broadcast)")
}
out := make([]*SigningMessage, sn.NChildren(view))
for i := range out {
out[i] = &SigningMessage{
Suite: sn.Suite().String(),
Type: SignatureBroadcast,
ViewNbr: view,
RoundNbr: RoundNbr,
SBm: &SignatureBroadcastMessage{
R0_hat: sn.suite.Secret().One(),
C: sn.suite.Secret().One(),
X0_hat: sn.suite.Point().Null(),
V0_hat: sn.suite.Point().Null(),
},
}
}
err := ri.SignatureBroadcast(sm, out)
if err != nil {
return err
}
if len(sn.Children(view)) > 0 {
dbg.Lvl3(sn.Name(), "in SignatureBroadcast is calling", len(sn.Children(view)), "children")
ctx := context.TODO()
msgs := make([]coconet.BinaryMarshaler, len(out))
for i := range msgs {
msgs[i] = out[i]
// Why oh why do we have to do this?
out[i].SBm.X0_hat = sn.suite.Point().Add(out[i].SBm.X0_hat, sn.suite.Point().Null())
}
if err := sn.PutDown(ctx, view, msgs); err != nil {
return err
}
} else {
dbg.Lvl3(sn.Name(), "sending StatusReturn")
return sn.StatusReturn(view, &SigningMessage{
Suite: sn.Suite().String(),
Type: StatusReturn,
ViewNbr: view,
RoundNbr: RoundNbr,
SRm: &StatusReturnMessage{},
})
}
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:57,代码来源:nodeprotocol.go
示例16: TrimLastIncompleteLevel
func TrimLastIncompleteLevel(root *Tree, hosts []string, depths []int, bf int) (*Tree, []string) {
treed := Depth(root)
var sj, j int
n := len(hosts)
expectedNNodes := 1
// if there is any incomplete tree level it should be treed
// if it's not treed, then the tree should be fully filled for its depth
// we check that this is the case and if treed is incomplete
// we remove the nodes and hosts from the treed level
lastLevel := treed
for d := 1; d <= treed; d++ {
nNodes := 0
sj = j
for ; j < n && depths[j] == d; j++ {
nNodes++
}
if nNodes != expectedNNodes {
lastLevel = d
break
}
expectedNNodes *= bf
}
if lastLevel != treed {
panic("Incomplete level is not last tree level" + strconv.Itoa(lastLevel) + " " + strconv.Itoa(treed))
}
bhMap := make(map[string]bool)
badHosts := hosts[sj:]
for _, bh := range badHosts {
bhMap[bh] = true
}
newRoot := &Tree{Name: root.Name}
TrimTree(newRoot, root, bhMap)
d := Depth(newRoot)
if len(badHosts) != 0 && d != treed-1 {
dbg.Lvl3(d, "!=", treed-1)
panic("TrimTree return wrong result")
} else {
if len(badHosts) == 0 && d != treed {
dbg.Lvl3(d, "!=", treed)
panic("TrimTree return wrong result")
}
}
// dbg.Lvl3(" Trimmed", n-sj, "nodes")
return newRoot, hosts[:sj]
}
开发者ID:mlncn,项目名称:cothority,代码行数:53,代码来源:graph.go
示例17: Listen
// Monitor will start listening for incoming connections on this address
// It needs the stats struct pointer to update when measures come
// Return an error if something went wrong during the connection setup
func (m *Monitor) Listen() error {
ln, err := net.Listen("tcp", Sink+":"+SinkPort)
if err != nil {
return fmt.Errorf("Error while monitor is binding address: %v", err)
}
m.listener = ln
dbg.Lvl2("Monitor listening for stats on", Sink, ":", SinkPort)
finished := false
go func() {
for {
if finished {
break
}
conn, err := ln.Accept()
if err != nil {
operr, ok := err.(*net.OpError)
// We cant accept anymore we closed the listener
if ok && operr.Op == "accept" {
break
}
dbg.Lvl2("Error while monitor accept connection:", operr)
continue
}
dbg.Lvl3("Monitor: new connection from", conn.RemoteAddr().String())
m.mutexConn.Lock()
m.conns[conn.RemoteAddr().String()] = conn
go m.handleConnection(conn)
m.mutexConn.Unlock()
}
}()
for !finished {
select {
// new stats
case measure := <-m.measures:
m.update(measure)
// end of a peer conn
case peer := <-m.done:
dbg.Lvl3("Connections left:", len(m.conns))
m.mutexConn.Lock()
delete(m.conns, peer)
m.mutexConn.Unlock()
// end of monitoring,
if len(m.conns) == 0 {
m.listener.Close()
finished = true
break
}
}
}
dbg.Lvl2("Monitor finished waiting !")
m.conns = make(map[string]net.Conn)
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:56,代码来源:monitor.go
示例18: Ready
// Only sends a ready-string
func Ready(addr string) error {
if encoder == nil {
dbg.Lvl3("Connecting to sink", addr)
err := ConnectSink(addr)
if err != nil {
return err
}
}
dbg.Lvl3("Sending ready-signal")
send(Measure{Name: "ready"})
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:13,代码来源:measure.go
示例19: Configure
// Configure various
func (d *Localhost) Configure() {
pwd, _ := os.Getwd()
d.AppDir = pwd + "/../app"
d.RunDir = pwd + "/platform/localhost"
d.LocalDir = pwd
d.Debug = dbg.DebugVisible
d.running = false
if d.App == "" {
dbg.Fatal("No app defined in simulation")
}
dbg.Lvl3(fmt.Sprintf("Localhost dirs: AppDir %s, RunDir %s", d.AppDir, d.RunDir))
dbg.Lvl3("Localhost configured ...")
}
开发者ID:mlncn,项目名称:cothority,代码行数:14,代码来源:localhost.go
示例20: TimeStamp
// When client asks for val to be timestamped
// It blocks until it get a coll_stamp reply back
func (c *Client) TimeStamp(val []byte, TSServerName string) error {
c.Mux.Lock()
if c.Error != nil {
c.Mux.Unlock()
return c.Error
}
c.reqno++
myReqno := c.reqno
c.doneChan[c.reqno] = make(chan error, 1) // new done channel for new req
c.Mux.Unlock()
// send request to TSServer
err := c.PutToServer(TSServerName,
&conode.TimeStampMessage{
Type: conode.StampRequestType,
ReqNo: myReqno,
Sreq: &conode.StampRequest{Val: val}})
if err != nil {
if err != coconet.ErrNotEstablished {
dbg.Lvl3(c.Name(), "error timestamping to", TSServerName, ":", err)
}
// pass back up all errors from putting to server
return err
}
dbg.Lvl4("Client Sent timestamp request to", TSServerName)
// get channel associated with request
c.Mux.Lock()
myChan := c.doneChan[myReqno]
c.Mux.Unlock()
// wait until ProcessStampSignature signals that reply was received
select {
case err = <-myChan:
//log.Println("-------------client received response from" + TSServerName)
break
case <-time.After(10 * sign.ROUND_TIME):
dbg.Lvl3("client timeouted on waiting for response from" + TSServerName)
break
// err = ErrClientToTSTimeout
}
if err != nil {
dbg.Lvl3(c.Name(), "error received from DoneChan:", err)
return err
}
// delete channel as it is of no longer meaningful
c.Mux.Lock()
delete(c.doneChan, myReqno)
c.Mux.Unlock()
return err
}
开发者ID:mlncn,项目名称:cothority,代码行数:53,代码来源:client_funcs.go
注:本文中的github.com/dedis/cothority/lib/dbg.Lvl3函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论