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