本文整理汇总了Golang中github.com/dedis/cothority/lib/debug_lvl.Lvl4函数的典型用法代码示例。如果您正苦于以下问题:Golang Lvl4函数的具体用法?Golang Lvl4怎么用?Golang Lvl4使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Lvl4函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetAddress
// getAddress gets the localhosts IPv4 address.
func GetAddress() (string, error) {
name, err := os.Hostname()
if err != nil {
log.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
}
示例2: RunClient
func RunClient(server string, nmsgs int, name string, rate int) {
dbg.Lvl4("Starting to run stampclient")
c := NewClient(name)
servers := strings.Split(server, ",")
// connect to all the servers listed
for _, s := range servers {
h, p, err := net.SplitHostPort(s)
if err != nil {
log.Fatal("improperly formatted host")
}
pn, _ := strconv.Atoi(p)
c.AddServer(s, coconet.NewTCPConn(net.JoinHostPort(h, strconv.Itoa(pn+1))))
}
// Check if somebody asks for the old way
if rate < 0 {
log.Fatal("Rounds based limiting deprecated")
}
// Stream time coll_stamp requests
// if rate specified send out one message every rate milliseconds
dbg.Lvl1(name, "starting to stream at rate", rate)
streamMessgs(c, servers, rate)
dbg.Lvl4("Finished streaming")
return
}
示例3: generateHostsFile
/*
* Write the hosts.txt file automatically
* from project name and number of servers
*/
func (d *Deter) generateHostsFile() error {
hosts_file := d.DeployDir + "/hosts.txt"
num_servers := d.Config.Nmachs + d.Config.Nloggers
// open and erase file if needed
if _, err1 := os.Stat(hosts_file); err1 == nil {
dbg.Lvl4("Hosts file", hosts_file, "already exists. Erasing ...")
os.Remove(hosts_file)
}
// create the file
f, err := os.Create(hosts_file)
if err != nil {
log.Fatal("Could not create hosts file description: ", hosts_file, " :: ", err)
return err
}
defer f.Close()
// write the name of the server + \t + IP address
ip := "10.255.0."
name := "SAFER.isi.deterlab.net"
for i := 1; i <= num_servers; i++ {
f.WriteString(fmt.Sprintf("server-%d.%s.%s\t%s%d\n", i-1, d.Project, name, ip, i))
}
dbg.Lvl4(fmt.Sprintf("Created hosts file description (%d hosts)", num_servers))
return err
}
示例4: Announce
func (sn *Node) Announce(view int, am *AnnouncementMessage) error {
dbg.Lvl4(sn.Name(), "received announcement on", view)
if err := sn.TryFailure(view, am.Round); err != nil {
return err
}
if err := sn.setUpRound(view, am); err != nil {
return err
}
// Inform all children of announcement
messgs := make([]coconet.BinaryMarshaler, sn.NChildren(view))
for i := range messgs {
sm := SigningMessage{
Type: Announcement,
View: view,
LastSeenVote: int(atomic.LoadInt64(&sn.LastSeenVote)),
Am: am}
messgs[i] = &sm
}
dbg.Lvl4(sn.Name(), "sending to all children")
ctx := context.TODO()
//ctx, _ := context.WithTimeout(context.Background(), 2000*time.Millisecond)
if err := sn.PutDown(ctx, view, messgs); err != nil {
return err
}
// return sn.Commit(view, am)
if len(sn.Children(view)) == 0 {
sn.Commit(view, am.Round, nil)
}
return nil
}
示例5: 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.Lvl4(sn.Name(), "INITIATING VIEW CHANGE FOR VIEW:", view)
go func() {
err := sn.StartVotingRound(
&Vote{
View: view,
Type: ViewChangeVT,
Vcv: &ViewChangeVote{
View: view,
Root: sn.Name()}})
if err != nil {
log.Errorln(sn.Name(), "TRY VIEW CHANGE FAILED: ", err)
}
}()
}
return nil
}
示例6: 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.Put(data[i]); e != nil {
errLock.Lock()
err = e
errLock.Unlock()
}
dbg.Lvl4("Informed child", c)
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
}
示例7: 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
}
示例8: setUpRound
func (sn *Node) setUpRound(view int, am *AnnouncementMessage) error {
// TODO: accept annoucements on old views?? linearizabiltity?
sn.viewmu.Lock()
// if (sn.ChangingView && am.Vote == nil) || (sn.ChangingView && am.Vote != nil && am.Vote.Vcv == nil) {
// dbg.Lvl4(sn.Name(), "currently chaning view")
// sn.viewmu.Unlock()
// return ChangingViewError
// }
if sn.ChangingView && am.Vote != nil && am.Vote.Vcv == nil {
dbg.Lvl4(sn.Name(), "currently chaning view")
sn.viewmu.Unlock()
return ChangingViewError
}
sn.viewmu.Unlock()
sn.roundmu.Lock()
Round := am.Round
if Round <= sn.LastSeenRound {
sn.roundmu.Unlock()
return ErrPastRound
}
// make space for round type
if len(sn.RoundTypes) <= Round {
sn.RoundTypes = append(sn.RoundTypes, make([]RoundType, max(len(sn.RoundTypes), Round+1))...)
}
if am.Vote == nil {
dbg.Lvl4(Round, len(sn.RoundTypes))
sn.RoundTypes[Round] = SigningRT
} else {
sn.RoundTypes[Round] = RoundType(am.Vote.Type)
}
sn.roundmu.Unlock()
// set up commit and response channels for the new round
sn.Rounds[Round] = NewRound(sn.suite)
sn.initCommitCrypto(Round)
sn.Rounds[Round].Vote = am.Vote
// update max seen round
sn.roundmu.Lock()
sn.LastSeenRound = max(sn.LastSeenRound, Round)
sn.roundmu.Unlock()
// the root is the only node that keeps track of round # internally
if sn.IsRoot(view) {
sn.RoundsAsRoot += 1
// TODO: is sn.Round needed if we have LastSeenRound
sn.Round = Round
// Create my back link to previous round
sn.SetBackLink(Round)
// sn.SetAccountableRound(Round)
}
return nil
}
示例9: ConnectToLogger
func (s *Server) ConnectToLogger() {
return
if s.Logger == "" || s.Hostname == "" || s.App == "" {
dbg.Lvl4("skipping connect to logger")
return
}
dbg.Lvl4("Connecting to Logger")
lh, _ := logutils.NewLoggerHook(s.Logger, s.Hostname, s.App)
dbg.Lvl4("Connected to Logger")
log.AddHook(lh)
}
示例10: actOnResponses
func (sn *Node) actOnResponses(view, Round int, exceptionV_hat abstract.Point, exceptionX_hat abstract.Point) error {
dbg.Lvl4(sn.Name(), "got all responses for view, round", view, Round)
round := sn.Rounds[Round]
err := sn.VerifyResponses(view, Round)
isroot := sn.IsRoot(view)
// if error put it up if parent exists
if err != nil && !isroot {
sn.PutUpError(view, err)
return err
}
// if no error send up own response
if err == nil && !isroot {
if round.Log.v == nil && sn.ShouldIFail("response") {
dbg.Lvl4(sn.Name(), "failing on response")
return nil
}
// create and putup own response message
rm := &ResponseMessage{
R_hat: round.r_hat,
ExceptionList: round.ExceptionList,
ExceptionV_hat: exceptionV_hat,
ExceptionX_hat: exceptionX_hat,
Round: Round}
// ctx, _ := context.WithTimeout(context.Background(), 2000*time.Millisecond)
ctx := context.TODO()
dbg.Lvl4(sn.Name(), "put up response to", sn.Parent(view))
err = sn.PutUp(ctx, view, &SigningMessage{
Type: Response,
View: view,
LastSeenVote: int(atomic.LoadInt64(&sn.LastSeenVote)),
Rm: rm})
} else {
dbg.Lvl4("Root received response")
}
if sn.TimeForViewChange() {
dbg.Lvl4("acting on responses: trying viewchanges")
err := sn.TryViewChange(view + 1)
if err != nil {
log.Errorln(err)
}
}
// root reports round is done
if isroot {
sn.done <- Round
}
return err
}
示例11: 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
}
示例12: Build
func Build(path, out, goarch, goos string) (string, error) {
var cmd *exec.Cmd
var b bytes.Buffer
build_buffer := bufio.NewWriter(&b)
cmd = exec.Command("go", "build", "-v", "-o", out, path)
dbg.Lvl4("Building", 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
}
示例13: NewReverseProxy
func NewReverseProxy(target *url.URL) *httputil.ReverseProxy {
director := func(r *http.Request) {
r.URL.Scheme = target.Scheme
r.URL.Host = target.Host
// get rid of the (/d/short_name)/debug of the url path requested
// --> long_name/debug
pathComp := strings.Split(r.URL.Path, "/")
// remove the first two components /d/short_name
pathComp = pathComp[3:]
r.URL.Path = target.Path + "/" + strings.Join(pathComp, "/")
dbg.Lvl4("redirected to: ", r.URL.String())
}
dbg.Lvl4("setup reverse proxy for destination url:", target.Host, target.Path)
return &httputil.ReverseProxy{Director: director}
}
示例14: actOnCommits
// Finalize commits by initiating the challenge pahse if root
// Send own commitment message up to parent if non-root
func (sn *Node) actOnCommits(view, Round int) error {
round := sn.Rounds[Round]
var err error
if sn.IsRoot(view) {
sn.commitsDone <- Round
err = sn.FinalizeCommits(view, Round)
} else {
// create and putup own commit message
com := &CommitmentMessage{
V: round.Log.V,
V_hat: round.Log.V_hat,
X_hat: round.X_hat,
MTRoot: round.MTRoot,
ExceptionList: round.ExceptionList,
Vote: round.Vote,
Round: Round}
// ctx, _ := context.WithTimeout(context.Background(), 2000*time.Millisecond)
dbg.Lvl4(sn.Name(), "puts up commit")
ctx := context.TODO()
err = sn.PutUp(ctx, view, &SigningMessage{
View: view,
Type: Commitment,
LastSeenVote: int(atomic.LoadInt64(&sn.LastSeenVote)),
Com: com})
}
return err
}
示例15: LogReRun
func (s *Server) LogReRun(nextRole string, curRole string) {
if nextRole == "root" {
var messg = s.Name() + " became root"
if curRole == "root" {
messg = s.Name() + " remained root"
}
go s.ConnectToLogger()
log.WithFields(log.Fields{
"file": logutils.File(),
"type": "role_change",
}).Infoln(messg)
// dbg.Lvl4("role change: %p", s)
} else {
var messg = s.Name() + " remained regular"
if curRole == "root" {
messg = s.Name() + " became regular"
}
if curRole == "root" {
log.WithFields(log.Fields{
"file": logutils.File(),
"type": "role_change",
}).Infoln(messg)
dbg.Lvl4("role change: %p", s)
}
}
}