-
Notifications
You must be signed in to change notification settings - Fork 2
/
printer.go
57 lines (50 loc) · 1.18 KB
/
printer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package passtor
import (
"fmt"
"os"
)
func checkErrMsg(err error, msg string) {
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error: "+msg+"\n")
os.Exit(1)
}
}
// Print a message to stdout
func (p *Printer) Print(str string, V int) {
if V <= p.Verbose {
p.Printer.Println(str)
}
}
// WPrint prints warnings
func (p *Printer) WPrint(str string, V int) {
if V <= p.Verbose {
p.Printer.Println("Warning: " + str)
}
}
// PrintErr prints error message to stderr
func (p *Printer) PrintErr(str string) {
p.ErrPrinter.Println(str)
}
// PrintBuckets print all bucket with their state
func (p *Passtor) PrintBuckets() {
str := "----------\nPrinting Bucket\n----------\n"
for i, b := range p.Buckets {
str += fmt.Sprintln("Bucket", i, ":")
list := b.GetList()
for _, n := range list {
str += fmt.Sprintln(p.NodeID.XOR(n.NodeID), n.NodeID, n.Addr)
}
str += "\n"
}
str += "----------"
p.Printer.Print(str, V3)
}
// PrintStatuses print given lookup statuses
func PrintStatuses(h Hash, statuses []*LookupStatus) {
str := "Printing lookup statuses:\n"
for _, s := range statuses {
str += fmt.Sprintln(*s)
str += fmt.Sprintln(s.NodeAddr.NodeID.XOR(h).Hex())
}
fmt.Print(str)
}