本文整理汇总了Golang中github.com/dedis/cothority/lib/debug_lvl.Lvl3函数的典型用法代码示例。如果您正苦于以下问题:Golang Lvl3函数的具体用法?Golang Lvl3怎么用?Golang Lvl3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Lvl3函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GenExecCmd
// Generate all commands on one single physicial machines to launch every "nodes"
func GenExecCmd(phys string, names []string, loggerport, random_leaf string) string {
dbg.Lvl3("Random_leaf", random_leaf)
dbg.Lvl3("Names", names)
connect := false
cmd := ""
bg := " & "
for i, name := range names {
dbg.Lvl3("deter.go Generate cmd timestamper : name ==", name)
dbg.Lvl3("random_leaf ==", random_leaf)
dbg.Lvl3("testconnect is", deter.TestConnect)
if name == random_leaf && deter.TestConnect {
connect = true
}
amroot := " -amroot=false"
if name == rootname {
amroot = " -amroot=true"
}
if i == len(names)-1 {
bg = ""
}
cmd += "(cd remote; sudo ./forkexec" +
" -physaddr=" + phys +
" -hostname=" + name +
" -logger=" + loggerport +
" -test_connect=" + strconv.FormatBool(connect) +
amroot + bg +
" ); "
}
return cmd
}
开发者ID:Liamsi,项目名称:cothority,代码行数:32,代码来源:deter.go
示例2: Get
// Get gets data from the connection.
// Returns io.EOF on an irrecoveralbe error.
// Returns given error if it is Temporary.
func (tc *TCPConn) Get(bum BinaryUnmarshaler) error {
if tc.Closed() {
dbg.Lvl3("tcpconn: get: connection closed")
return ErrClosed
}
tc.encLock.Lock()
for tc.dec == nil {
tc.encLock.Unlock()
return ErrNotEstablished
}
dec := tc.dec
tc.encLock.Unlock()
if Latency != 0 {
time.Sleep(time.Duration(rand.Intn(Latency)) * time.Millisecond)
}
err := dec.Decode(bum)
if err != nil {
if IsTemporary(err) {
return err
}
// if it is an irrecoverable error
// close the channel and return that it has been closed
if err != io.EOF && err.Error() != "read tcp4" {
dbg.Lvl2("Couldn't decode packet at", tc.name, "error:", err)
} else {
dbg.Lvl3("Closing connection by EOF")
}
tc.Close()
return ErrClosed
}
return err
}
开发者ID:Liamsi,项目名称:cothority,代码行数:36,代码来源:tcpconn.go
示例3: 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(poly.SUITE)
dealer := poly.NewDealer(p.info, &p.key, &dealerKey, p.pubKeys)
// Construct the receiver
receiver := poly.NewReceiver(p.info, &p.key)
// add already its own dealer
_, err := receiver.AddDealer(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.Lvl2(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.Dealer)
for _, rp := range p.remote {
go func(rp RemotePeer) {
d := new(poly.Dealer).UnmarshalInit(p.info)
err := poly.SUITE.Read(rp.Conn, d)
if err != nil {
dbg.Fatal(p.Name, " received a strange dealer from ", rp.String())
}
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.AddDealer(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.Lvl2(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.Lvl2(p.Name, "produced shared secret !")
return sh
}
开发者ID:Liamsi,项目名称:cothority,代码行数:58,代码来源:peer.go
示例4: Listen
// listen for clients connections
// this server needs to be running on a different port
// than the Signer that is beneath it
func (s *Server) Listen() error {
dbg.Lvl3("Listening in server at", s.name)
ln, err := net.Listen("tcp4", s.name)
if err != nil {
panic(err)
}
go func() {
for {
// dbg.Lvl4("LISTENING TO CLIENTS: %p", s)
conn, err := ln.Accept()
if err != nil {
// handle error
dbg.Lvl3("failed to accept connection")
continue
}
c := coconet.NewTCPConnFromNet(conn)
// dbg.Lvl4("CLIENT TCP CONNECTION SUCCESSFULLY ESTABLISHED:", c)
if _, ok := s.Clients[c.Name()]; !ok {
s.Clients[c.Name()] = c
go func(c coconet.Conn) {
for {
tsm := TimeStampMessage{}
err := c.Get(&tsm)
if err != nil {
log.Errorf("%p Failed to get from child:", s, err)
s.Close()
return
}
switch tsm.Type {
default:
log.Errorf("Message of unknown type: %v\n", tsm.Type)
case StampRequestType:
// dbg.Lvl4("RECEIVED STAMP REQUEST")
s.mux.Lock()
READING := s.READING
s.Queue[READING] = append(s.Queue[READING],
MustReplyMessage{Tsm: tsm, To: c.Name()})
s.mux.Unlock()
}
}
}(c)
}
}
}()
return nil
}
开发者ID:Liamsi,项目名称:cothority,代码行数:55,代码来源:server.go
示例5: 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 {
log.Errorln(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)
sn.CatchUp(int(atomic.LoadInt64(&sn.LastAppliedVote)+1), from)
case <-sn.closed:
dbg.Lvl3("stopping gossip: closed")
return
}
}
}()
}
开发者ID:Liamsi,项目名称:cothority,代码行数:25,代码来源:snvoting.go
示例6: NewPeer
// NewPeer returns a new peer with its id and the number of peers in the schnorr signature algo
// TODO verification of string addr:port
func NewPeer(id int, name string, p poly.PolyInfo, isRoot bool) *Peer {
if id >= p.N {
log.Fatal("Error while NewPeer : gien ", id, " as id whereas polyinfo.N = ", p.N)
}
// Setup of the private / public pair
key := cliutils.KeyPair(poly.SUITE)
// setup of the public list of key
pubKeys := make([]abstract.Point, p.N)
pubKeys[id] = key.Public
dbg.Lvl3(name, "(id", id, ") has created its private/public key : public => ", key.Public)
return &Peer{
Id: id,
remote: make(map[int]RemotePeer),
root: isRoot,
Name: name,
info: p,
key: key,
pubKeys: pubKeys,
schnorr: new(poly.Schnorr),
synChan: make(chan Syn),
ackChan: make(chan Ack),
}
}
开发者ID:Liamsi,项目名称:cothority,代码行数:28,代码来源:peer.go
示例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) {
// First we need to SYN mutually
s := Syn{
Id: p.Id,
Public: p.key.Public,
}
err := poly.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 = poly.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
}
开发者ID:Liamsi,项目名称:cothority,代码行数:31,代码来源:peer.go
示例8: WaitACKs
// WaitAcks will make a peer waits for all others peers to send an ACK to it
func (p *Peer) WaitACKs() {
var wg sync.WaitGroup
fn := func(rp RemotePeer) {
a := Ack{}
err := poly.SUITE.Read(rp.Conn, &a)
if err != nil {
dbg.Fatal(p.Name, "could not receive an ACK from ", rp.String(), " (err ", err, ")")
}
//p.ackChan <- a
wg.Done()
}
wg.Add(len(p.remote))
p.ForRemotePeers(fn)
dbg.Lvl3(p.Name, "is waiting for acks ...")
wg.Wait()
dbg.Lvl2(p.String(), "received ALL ACKs")
//n := 0
//for {
// a := <-p.ackChan
// if a.Valid {
// n += 1
// }
// if n == p.info.N-1 {
// dbg.Lvl2(p.Name, "received all acks. Continue")
// break
// }
//}
}
开发者ID:Liamsi,项目名称:cothority,代码行数:30,代码来源:peer.go
示例9: ConnectTo
// ConnectTo will connect to the given host and start the SYN exchange (public key + id)
func (p *Peer) ConnectTo(host string) error {
tick := time.NewTicker(ConnWaitRetry)
count := 0
for range tick.C {
// connect
conn, err := net.Dial("tcp", host)
if err != nil {
// we have tried too many times => abort
if count == ConnRetry {
tick.Stop()
dbg.Fatal(p.Name, "could not connect to", host, " ", ConnRetry, "times. Abort.")
// let's try again one more time
} else {
dbg.Lvl2(p.Name, "could not connect to", host, ". Retry in ", ConnWaitRetry.String())
count += 1
}
}
// handle successful connection
dbg.Lvl3(p.Name, "has connected with peer ", host)
tick.Stop()
// start to syn with the respective peer
go p.synWithPeer(conn)
break
}
return nil
}
开发者ID:Liamsi,项目名称:cothority,代码行数:27,代码来源:peer.go
示例10: readHosts
// parse the hosts.txt file to create a separate list (and file)
// of physical nodes and virtual nodes. Such that each host on line i, in phys.txt
// corresponds to each host on line i, in virt.txt.
func (d *Deter) readHosts() {
hosts_file := d.DeployDir + "/hosts.txt"
nmachs, nloggers := d.Config.Nmachs, d.Config.Nloggers
physVirt, err := cliutils.ReadLines(hosts_file)
if err != nil {
log.Panic("Couldn't find", hosts_file)
}
d.phys = make([]string, 0, len(physVirt)/2)
d.virt = make([]string, 0, len(physVirt)/2)
for i := 0; i < len(physVirt); i += 2 {
d.phys = append(d.phys, physVirt[i])
d.virt = append(d.virt, physVirt[i+1])
}
d.phys = d.phys[:nmachs+nloggers]
d.virt = d.virt[:nmachs+nloggers]
d.physOut = strings.Join(d.phys, "\n")
d.virtOut = strings.Join(d.virt, "\n")
d.masterLogger = d.phys[0]
// slaveLogger1 := phys[1]
// slaveLogger2 := phys[2]
// phys.txt and virt.txt only contain the number of machines that we need
dbg.Lvl3("Reading phys and virt")
err = ioutil.WriteFile(d.DeployDir+"/phys.txt", []byte(d.physOut), 0666)
if err != nil {
log.Fatal("failed to write physical nodes file", err)
}
err = ioutil.WriteFile(d.DeployDir+"/virt.txt", []byte(d.virtOut), 0666)
if err != nil {
log.Fatal("failed to write virtual nodes file", err)
}
}
开发者ID:Liamsi,项目名称:cothority,代码行数:38,代码来源:deploy_deterlab.go
示例11: Build
func (d *Deter) Build(build string) error {
dbg.Lvl1("Building for", d.Login, d.Host, d.Project, build)
start := time.Now()
var wg sync.WaitGroup
// Start with a clean build-directory
current, _ := os.Getwd()
dbg.Lvl4("Current dir is:", current)
defer os.Chdir(current)
// Go into deterlab-dir and create the build-dir
os.Chdir(d.DeterDir)
os.RemoveAll(d.BuildDir)
os.Mkdir(d.BuildDir, 0777)
// start building the necessary packages
packages := []string{"logserver", "forkexec", "../../app", "deter"}
if build != "" {
packages = strings.Split(build, ",")
}
dbg.Lvl3("Starting to build all executables", packages)
for _, p := range packages {
basename := path.Base(p)
dbg.Lvl4("Building ", p, "into", basename)
wg.Add(1)
src := p + "/" + basename + ".go"
dst := d.BuildDir + "/" + basename
if p == "deter" {
go func(s, d string) {
defer wg.Done()
// the users node has a 386 FreeBSD architecture
out, err := cliutils.Build(s, d, "386", "freebsd")
if err != nil {
cliutils.KillGo()
fmt.Println(out)
log.Fatal(err)
}
}(src, dst)
continue
}
go func(s, d string) {
defer wg.Done()
// deter has an amd64, linux architecture
out, err := cliutils.Build(s, d, "amd64", "linux")
if err != nil {
cliutils.KillGo()
fmt.Println(out)
log.Fatal(err)
}
}(src, dst)
}
// wait for the build to finish
wg.Wait()
dbg.Lvl1("Build is finished after", time.Since(start))
return nil
}
开发者ID:Liamsi,项目名称:cothority,代码行数:57,代码来源:deploy_deterlab.go
示例12: Start
func (d *Deter) Start() error {
dbg.Lvl1("Running with", d.Config.Nmachs, "nodes *", d.Config.Hpn, "hosts per node =",
d.Config.Nmachs*d.Config.Hpn, "and", d.Config.Nloggers, "loggers")
// setup port forwarding for viewing log server
dbg.Lvl3("setup port forwarding for master logger: ", d.masterLogger, d.Login, d.Host)
cmd := exec.Command(
"ssh",
"-t",
"-t",
fmt.Sprintf("%[email protected]%s", d.Login, d.Host),
"-L",
"8081:"+d.masterLogger+":10000")
err := cmd.Start()
if err != nil {
log.Fatal("failed to setup portforwarding for logging server")
}
dbg.Lvl3("runnning deter with nmsgs:", d.Config.Nmsgs, d.Login, d.Host)
// run the deter lab boss nodes process
// it will be responsible for forwarding the files and running the individual
// timestamping servers
go func() {
dbg.Lvl3(cliutils.SshRunStdout(d.Login, d.Host,
"GOMAXPROCS=8 remote/deter -nmsgs="+strconv.Itoa(d.Config.Nmsgs)+
" -hpn="+strconv.Itoa(d.Config.Hpn)+
" -bf="+strconv.Itoa(d.Config.Bf)+
" -rate="+strconv.Itoa(d.Config.Rate)+
" -rounds="+strconv.Itoa(d.Config.Rounds)+
" -debug="+strconv.Itoa(d.Config.Debug)+
" -failures="+strconv.Itoa(d.Config.Failures)+
" -rfail="+strconv.Itoa(d.Config.RFail)+
" -ffail="+strconv.Itoa(d.Config.FFail)+
" -app="+d.Config.App+
" -suite="+d.Config.Suite))
dbg.Lvl3("Sending stop of ssh")
d.sshDeter <- "stop"
}()
return nil
}
开发者ID:Liamsi,项目名称:cothority,代码行数:42,代码来源:deploy_deterlab.go
示例13: Stop
func (d *Deter) Stop() error {
killssh := exec.Command("pkill", "-f", "ssh -t -t")
killssh.Stdout = os.Stdout
killssh.Stderr = os.Stderr
err := killssh.Run()
if err != nil {
dbg.Lvl3("Stopping ssh: ", err)
}
select {
case msg := <-d.sshDeter:
if msg == "stop" {
dbg.Lvl3("SSh is stopped")
} else {
dbg.Lvl1("Received other command", msg)
}
case <-time.After(time.Second * 3):
dbg.Lvl3("Timeout error when waiting for end of ssh")
}
return nil
}
开发者ID:Liamsi,项目名称:cothority,代码行数:20,代码来源:deploy_deterlab.go
示例14: ExampleLevel2
func ExampleLevel2() {
dbg.Lvl1("Level1")
dbg.Lvl3("Level2")
dbg.Lvl4("Level3")
dbg.Lvl4("Level4")
dbg.Lvl5("Level5")
// Output:
// 1: ( debug_lvl_test.ExampleLevel2: 0) - Level1
// 2: ( debug_lvl_test.ExampleLevel2: 0) - Level2
}
开发者ID:Liamsi,项目名称:cothority,代码行数:11,代码来源:debug_lvl_test.go
示例15: NewView
func (v *Views) NewView(view int, parent string, children []string, hostlist []string) {
dbg.Lvl3("New view", view, hostlist)
v.Lock()
vi := &View{Num: view, Parent: parent}
vi.HostList = make([]string, len(hostlist))
copy(vi.HostList, hostlist)
vi.Children = make([]string, len(children))
copy(vi.Children, children)
v.Views[view] = vi
v.Unlock()
}
开发者ID:Liamsi,项目名称:cothority,代码行数:12,代码来源:view.go
示例16: Close
// Close closes the connection.
func (tc *TCPConn) Close() {
dbg.Lvl3("tcpconn: closing connection")
tc.encLock.Lock()
defer tc.encLock.Unlock()
if tc.conn != nil {
// ignore error because only other possibility was an invalid
// connection. but we don't care if we close a connection twice.
tc.conn.Close()
}
tc.closed = true
tc.conn = nil
tc.enc = nil
tc.dec = nil
}
开发者ID:Liamsi,项目名称:cothority,代码行数:15,代码来源:tcpconn.go
示例17: WaitSYNs
// WaitSYNs will wait until every peers has syn'd with this one
func (p *Peer) WaitSYNs() {
for {
s := <-p.synChan
dbg.Lvl3(p.Name, " synChan received Syn id ", s.Id)
_, ok := p.remote[s.Id]
if !ok {
dbg.Fatal(p.Name, "received syn'd notification of an unknown peer... ABORT")
}
if len(p.remote) == p.info.N-1 {
dbg.Lvl2(p.Name, "is SYN'd with every one")
break
}
}
}
开发者ID:Liamsi,项目名称:cothority,代码行数:15,代码来源:peer.go
示例18: 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,
&TimeStampMessage{
Type: StampRequestType,
ReqNo: myReqno,
Sreq: &StampRequest{Val: val}})
if err != nil {
if err != coconet.ErrNotEstablished {
log.Warn(c.Name(), "error timestamping to ", TSServerName, ": ", err)
}
// pass back up all errors from putting to server
return err
}
// get channel associated with request
c.Mux.Lock()
myChan := c.doneChan[myReqno]
c.Mux.Unlock()
// wait until ProcessStampReply signals that reply was received
select {
case err = <-myChan:
//log.Println("-------------client received response from" + TSServerName)
break
case <-time.After(10 * ROUND_TIME):
dbg.Lvl3("client timeouted on waiting for response from" + TSServerName)
break
// err = ErrClientToTSTimeout
}
if err != nil {
log.Errorln(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:Liamsi,项目名称:cothority,代码行数:52,代码来源:client_funcs.go
示例19: Close
// Close closes all the connections currently open.
func (h *TCPHost) Close() {
dbg.Lvl3("tcphost: closing")
// stop accepting new connections
atomic.StoreInt64(&h.closed, 1)
h.listener.Close()
// close peer connections
h.PeerLock.Lock()
for _, p := range h.peers {
if p != nil {
p.Close()
}
}
h.PeerLock.Unlock()
}
开发者ID:Liamsi,项目名称:cothority,代码行数:17,代码来源:tcphost.go
示例20: RunServer
func RunServer(app *config.AppConfig, conf *deploy.Config, hc *config.HostConfig) {
// run this specific host
err := hc.Run(false, sign.MerkleTree, app.Hostname)
if err != nil {
log.Fatal(err)
}
dbg.Lvl3(app.Hostname, "started up in server-mode")
// Let's start the client if we're the root-node
if hc.SNodes[0].IsRoot(0) {
dbg.Lvl1(app.Hostname, "started client")
RunClient(conf, hc)
} else {
// Endless-loop till we stop by tearing down the connections
for {
time.Sleep(time.Minute)
}
}
}
开发者ID:Liamsi,项目名称:cothority,代码行数:20,代码来源:server.go
注:本文中的github.com/dedis/cothority/lib/debug_lvl.Lvl3函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论