本文整理汇总了Golang中github.com/dedis/cothority/lib/dbg.Lvl4函数的典型用法代码示例。如果您正苦于以下问题:Golang Lvl4函数的具体用法?Golang Lvl4怎么用?Golang Lvl4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Lvl4函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetAddress
// getAddress gets the localhosts IPv4 address.
func GetAddress() (string, error) {
name, err := os.Hostname()
if err != nil {
dbg.Error("Error Resolving Hostname:", err)
return "", err
}
if ipv4host == "NONE" {
as, err := net.LookupHost(name)
if err != nil {
return "", err
}
addr := ""
for _, a := range as {
dbg.Lvl4("a = %+v", a)
if ipv4Reg.MatchString(a) {
dbg.Lvl4("matches")
addr = a
}
}
if addr == "" {
err = errors.New("No IPv4 Address for Hostname")
}
return addr, err
}
return ipv4host, nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:31,代码来源:node.go
示例2: 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
示例3: PutDown
// PutDown sends a message (an interface{} value) up to all children through
// whatever 'network' interface each child Peer implements.
func (h *TCPHost) PutDown(ctx context.Context, view int, data []BinaryMarshaler) error {
// Try to send the message to all children
// If at least one of the attempts fails, return a non-nil error
var err error
var errLock sync.Mutex
children := h.views.Children(view)
if len(data) != len(children) {
panic("number of messages passed down != number of children")
}
var canceled int64
var wg sync.WaitGroup
dbg.Lvl4(h.Name(), "sending to", len(children), "children")
for i, c := range children {
dbg.Lvl4("Sending to child", c)
wg.Add(1)
go func(i int, c string) {
defer wg.Done()
// try until it is canceled, successful, or timed-out
for {
// check to see if it has been canceled
if atomic.LoadInt64(&canceled) == 1 {
return
}
// if it is not Ready try again later
h.PeerLock.Lock()
Ready := h.Ready[c]
conn := h.peers[c]
h.PeerLock.Unlock()
if Ready {
if e := conn.PutData(data[i]); e != nil {
errLock.Lock()
err = e
errLock.Unlock()
}
dbg.Lvl4("Informed child", c, "of", data[i])
return
}
dbg.Lvl4("Re-trying, waiting to put down msg from", h.Name(), "to", c)
time.Sleep(250 * time.Millisecond)
}
}(i, c)
}
done := make(chan struct{})
go func() {
wg.Wait()
done <- struct{}{}
}()
select {
case <-done:
case <-ctx.Done():
err = ctx.Err()
atomic.StoreInt64(&canceled, 1)
}
return err
}
开发者ID:mlncn,项目名称:cothority,代码行数:61,代码来源:tcphost.go
示例4: Response
func (round *RoundException) Response(in []*SigningMessage, out *SigningMessage) error {
if round.Name == ExceptionForceFailure {
dbg.Lvl1("Forcing failure in response")
round.RaiseException()
}
// initialize exception handling
nullPoint := round.Cosi.Suite.Point().Null()
children := round.Cosi.Children
for _, sm := range in {
from := sm.From
switch sm.Type {
default:
// default == no response from child
dbg.Lvl4(round.Name, "Empty response from child", from, sm.Type)
if children[from] != nil {
round.Cosi.ExceptionList = append(round.Cosi.ExceptionList, children[from].PubKey())
// remove public keys and point commits from subtree of failed child
round.Cosi.ExceptionX_hat.Add(round.Cosi.ExceptionX_hat, round.Cosi.ChildX_hat[from])
round.Cosi.ExceptionV_hat.Add(round.Cosi.ExceptionV_hat, round.Cosi.ChildV_hat[from])
}
continue
case Response:
// disregard response from children who did not commit
_, ok := round.Cosi.ChildV_hat[from]
if ok == true && round.Cosi.ChildV_hat[from].Equal(nullPoint) {
dbg.Lvl4(round.Name, ": no response from", from, sm.Type)
continue
}
dbg.Lvl4(round.Name, "accepts response from", from, sm.Type)
round.Cosi.ExceptionV_hat.Add(round.Cosi.ExceptionV_hat, sm.Rm.ExceptionV_hat)
round.Cosi.ExceptionX_hat.Add(round.Cosi.ExceptionX_hat, sm.Rm.ExceptionX_hat)
round.Cosi.ExceptionList = append(round.Cosi.ExceptionList, sm.Rm.ExceptionList...)
}
}
round.Cosi.X_hat.Sub(round.Cosi.X_hat, round.Cosi.ExceptionX_hat)
err := round.RoundCosi.Response(in, out)
if err != nil {
return err
}
out.Rm.ExceptionList = round.Cosi.ExceptionList
out.Rm.ExceptionV_hat = round.Cosi.ExceptionV_hat
out.Rm.ExceptionX_hat = round.Cosi.ExceptionX_hat
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:51,代码来源:roundexception.go
示例5: NotifyOfAction
func (sn *Node) NotifyOfAction(view int, v *Vote) {
dbg.Lvl4(sn.Name(), "Notifying node to be added/removed of action")
gcm := &SigningMessage{
Suite: sn.Suite().String(),
Type: GroupChanged,
From: sn.Name(),
ViewNbr: view,
//LastSeenVote: int(sn.LastSeenVote),
Gcm: &GroupChangedMessage{
V: v,
HostList: sn.HostListOn(view)}}
switch v.Type {
case AddVT:
if sn.Name() == v.Av.Parent {
sn.PutTo(context.TODO(), v.Av.Name, gcm)
}
case RemoveVT:
if sn.Name() == v.Rv.Parent {
sn.PutTo(context.TODO(), v.Rv.Name, gcm)
}
default:
dbg.Error("notifyofaction: unkown action type")
}
}
开发者ID:mlncn,项目名称:cothority,代码行数:25,代码来源:nodevoting.go
示例6: StartGossip
func (sn *Node) StartGossip() {
go func() {
t := time.Tick(GOSSIP_TIME)
for {
select {
case <-t:
sn.viewmu.Lock()
c := sn.HostListOn(sn.ViewNo)
sn.viewmu.Unlock()
if len(c) == 0 {
dbg.Error(sn.Name(), "StartGossip: none in hostlist for view:", sn.ViewNo, len(c))
continue
}
sn.randmu.Lock()
from := c[sn.Rand.Int()%len(c)]
sn.randmu.Unlock()
dbg.Lvl4("Gossiping with:", from)
// we dont use voting anyway
// sn.CatchUp(int(atomic.LoadInt64(&sn.LastAppliedVote)+1), from)
case <-sn.closed:
dbg.Lvl3("stopping gossip: closed")
return
}
}
}()
}
开发者ID:mlncn,项目名称:cothority,代码行数:26,代码来源:nodevoting.go
示例7: 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
示例8: setup_deter
func setup_deter() {
vpmap := make(map[string]string)
for i := range deter.Virt {
vpmap[deter.Virt[i]] = deter.Phys[i]
}
deter.Phys = deter.Phys[:]
deter.Virt = deter.Virt[:]
hostnames := deter.Hostnames
dbg.Lvl4("hostnames:", hostnames)
rootname = hostnames[0]
// mapping from physical node name to the app servers that are running there
// essentially a reverse mapping of vpmap except ports are also used
physToServer = make(map[string][]string)
for _, virt := range hostnames {
v, _, _ := net.SplitHostPort(virt)
p := vpmap[v]
ss := physToServer[p]
ss = append(ss, virt)
physToServer[p] = ss
}
dbg.Lvl3("PhysToServer is", physToServer)
}
开发者ID:mlncn,项目名称:cothority,代码行数:27,代码来源:forkexec.go
示例9: Commitment
func (round *RoundStamper) Commitment(in []*sign.SigningMessage, out *sign.SigningMessage) error {
// compute the local Merkle root
// give up if nothing to process
if len(round.StampQueue) == 0 {
round.StampRoot = make([]byte, hashid.Size)
round.StampProofs = make([]proof.Proof, 1)
} else {
// pull out to be Merkle Tree leaves
round.StampLeaves = make([]hashid.HashId, 0)
for _, msg := range round.StampQueue {
round.StampLeaves = append(round.StampLeaves, hashid.HashId(msg))
}
// create Merkle tree for this round's messages and check corectness
round.StampRoot, round.StampProofs = proof.ProofTree(round.Suite.Hash, round.StampLeaves)
if dbg.DebugVisible > 2 {
if proof.CheckLocalProofs(round.Suite.Hash, round.StampRoot, round.StampLeaves, round.StampProofs) == true {
dbg.Lvl4("Local Proofs of", round.Name, "successful for round "+
strconv.Itoa(round.RoundNbr))
} else {
panic("Local Proofs" + round.Name + " unsuccessful for round " +
strconv.Itoa(round.RoundNbr))
}
}
}
out.Com.MTRoot = round.StampRoot
round.RoundCosi.Commitment(in, out)
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:30,代码来源:roundstamper.go
示例10: VerifyResponses
// Called by every node after receiving aggregate responses from descendants
func (cosi *CosiStruct) VerifyResponses() error {
// Check that: base**r_hat * X_hat**c == V_hat
// Equivalent to base**(r+xc) == base**(v) == T in vanillaElGamal
Aux := cosi.Suite.Point()
V_clean := cosi.Suite.Point()
V_clean.Add(V_clean.Mul(nil, cosi.R_hat), Aux.Mul(cosi.X_hat, cosi.C))
// T is the recreated V_hat
T := cosi.Suite.Point().Null()
T.Add(T, V_clean)
T.Add(T, cosi.ExceptionV_hat)
var c2 abstract.Secret
isroot := cosi.Parent == ""
if isroot {
// round challenge must be recomputed given potential
// exception list
msg := cosi.Msg
msg = append(msg, []byte(cosi.MTRoot)...)
cosi.C = cosi.HashElGamal(msg, cosi.Log.V_hat)
c2 = cosi.HashElGamal(msg, T)
}
// intermediary nodes check partial responses aginst their partial keys
// the root node is also able to check against the challenge it emitted
if !T.Equal(cosi.Log.V_hat) || (isroot && !cosi.C.Equal(c2)) {
return errors.New("Verifying ElGamal Collective Signature failed in " +
cosi.Name)
} else if isroot {
dbg.Lvl4(cosi.Name, "reports ElGamal Collective Signature succeeded")
}
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:34,代码来源:cosistruct.go
示例11: TryViewChange
func (sn *Node) TryViewChange(view int) error {
dbg.Lvl4(sn.Name(), "TRY VIEW CHANGE on", view, "with last view", sn.ViewNo)
// should ideally be compare and swap
sn.viewmu.Lock()
if view <= sn.ViewNo {
sn.viewmu.Unlock()
return errors.New("trying to view change on previous/ current view")
}
if sn.ChangingView {
sn.viewmu.Unlock()
return ChangingViewError
}
sn.ChangingView = true
sn.viewmu.Unlock()
// take action if new view root
if sn.Name() == sn.RootFor(view) {
dbg.Fatal(sn.Name(), "Initiating view change for view:", view, "BTH")
/*
go func() {
err := sn.StartVotingRound(
&Vote{
View: view,
Type: ViewChangeVT,
Vcv: &ViewChangeVote{
View: view,
Root: sn.Name()}})
if err != nil {
dbg.Lvl2(sn.Name(), "Try view change failed:", err)
}
}()
*/
}
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:35,代码来源:nodeconsensus.go
示例12: Close
func (sn *Node) Close() {
// sn.printRoundTypes()
sn.hbLock.Lock()
if sn.heartbeat != nil {
sn.heartbeat.Stop()
sn.heartbeat = nil
dbg.Lvl4("after close", sn.Name(), "has heartbeat=", sn.heartbeat)
}
if !sn.Isclosed {
close(sn.closed)
dbg.Lvl4("signing node: closing:", sn.Name())
sn.Host.Close()
}
dbg.Lvl3("Closed connection")
sn.Isclosed = true
sn.hbLock.Unlock()
}
开发者ID:mlncn,项目名称:cothority,代码行数:17,代码来源:nodehelper.go
示例13: Build
func Build(path, out, goarch, goos string) (string, error) {
var cmd *exec.Cmd
var b bytes.Buffer
build_buffer := bufio.NewWriter(&b)
wd, _ := os.Getwd()
dbg.Lvl4("In directory", wd)
cmd = exec.Command("go", "build", "-v", "-o", out, path)
dbg.Lvl4("Building", cmd.Args, "in", path)
cmd.Stdout = build_buffer
cmd.Stderr = build_buffer
cmd.Env = append([]string{"GOOS=" + goos, "GOARCH=" + goarch}, os.Environ()...)
wd, err := os.Getwd()
dbg.Lvl4(wd)
dbg.Lvl4("Command:", cmd.Args)
err = cmd.Run()
dbg.Lvl4(b.String())
return b.String(), err
}
开发者ID:mlncn,项目名称:cothority,代码行数:20,代码来源:utils.go
示例14: CatchUp
func (sn *Node) CatchUp(vi int, from string) {
dbg.Lvl4(sn.Name(), "attempting to catch up vote", vi)
ctx := context.TODO()
sn.PutTo(ctx, from,
&SigningMessage{
Suite: sn.Suite().String(),
From: sn.Name(),
Type: CatchUpReq,
Cureq: &CatchUpRequest{Index: vi}})
}
开发者ID:mlncn,项目名称:cothority,代码行数:11,代码来源:nodevoting.go
示例15: AddParent
// AddParent adds a parent node to the TCPHost, for the given view.
func (h *TCPHost) AddParent(view int, c string) {
h.PeerLock.Lock()
if _, ok := h.peers[c]; !ok {
h.peers[c] = NewTCPConn(c)
}
// remove from pending peers list
delete(h.PendingPeers, c)
h.PeerLock.Unlock()
dbg.Lvl4("Adding parent to views on", h.Name(), "for", c)
h.views.AddParent(view, c)
}
开发者ID:mlncn,项目名称:cothority,代码行数:12,代码来源:tcphost.go
示例16: GenerateHosts
// GenerateHosts will generate the list of hosts
// with a new port each
func (d *Localhost) GenerateHosts() {
nrhosts := d.Machines * d.Ppm
d.Hosts = make([]string, nrhosts)
port := 2000
inc := 5
for i := 0; i < nrhosts; i++ {
s := "127.0.0.1:" + strconv.Itoa(port+inc*i)
d.Hosts[i] = s
}
dbg.Lvl4("Localhost: Generated hosts list", d.Hosts)
}
开发者ID:mlncn,项目名称:cothority,代码行数:13,代码来源:localhost.go
示例17: ExampleLevel2
func ExampleLevel2() {
dbg.DebugVisible = 2
dbg.Lvl1("Level1")
dbg.Lvl2("Level2")
dbg.Lvl3("Level3")
dbg.Lvl4("Level4")
dbg.Lvl5("Level5")
// Output:
// 1: ( dbg_test.ExampleLevel2: 0) - Level1
// 2: ( dbg_test.ExampleLevel2: 0) - Level2
}
开发者ID:mlncn,项目名称:cothority,代码行数:12,代码来源:debug_lvl_test.go
示例18: SshRunStdout
func SshRunStdout(username, host, command string) error {
addr := host
if username != "" {
addr = username + "@" + addr
}
dbg.Lvl4("Going to ssh to", addr, command)
cmd := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", addr,
"eval '"+command+"'")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return cmd.Run()
}
开发者ID:mlncn,项目名称:cothority,代码行数:13,代码来源:utils.go
示例19: Response
// TODO make that in == nil in case we are a leaf to stay consistent with
// others calls
func (round *RoundCosi) Response(in []*SigningMessage, out *SigningMessage) error {
dbg.Lvl4(round.Cosi.Name, "got all responses")
for _, sm := range in {
round.Cosi.R_hat.Add(round.Cosi.R_hat, sm.Rm.R_hat)
}
err := round.Cosi.VerifyResponses()
if err != nil {
dbg.Lvl3(round.Node.Name(), "Could not verify responses..")
return err
}
out.Rm.R_hat = round.Cosi.R_hat
return nil
}
开发者ID:mlncn,项目名称:cothority,代码行数:15,代码来源:roundcosi.go
示例20: AddSelf
func (sn *Node) AddSelf(parent string) error {
dbg.Lvl4("AddSelf: connecting to:", parent)
err := sn.ConnectTo(parent)
if err != nil {
return err
}
dbg.Lvl4("AddSelf: putting group change message to:", parent)
return sn.PutTo(
context.TODO(),
parent,
&SigningMessage{
Suite: sn.Suite().String(),
Type: GroupChange,
ViewNbr: -1,
Vrm: &VoteRequestMessage{
Vote: &Vote{
Type: AddVT,
Av: &AddVote{
Name: sn.Name(),
Parent: parent}}}})
}
开发者ID:mlncn,项目名称:cothority,代码行数:22,代码来源:nodevoting.go
注:本文中的github.com/dedis/cothority/lib/dbg.Lvl4函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论