@@ -18,6 +18,7 @@ package network
18
18
19
19
import (
20
20
"bytes"
21
+ "encoding/hex"
21
22
"fmt"
22
23
"math/rand"
23
24
"sort"
@@ -95,6 +96,7 @@ type Kademlia struct {
95
96
}
96
97
97
98
type KademliaInfo struct {
99
+ Self string `json:"self"`
98
100
Depth int `json:"depth"`
99
101
TotalConnections int `json:"total_connections"`
100
102
TotalKnown int `json:"total_known"`
@@ -140,7 +142,7 @@ func Label(e *entry) string {
140
142
141
143
// Hex is the hexadecimal serialisation of the entry address
142
144
func (e * entry ) Hex () string {
143
- return fmt . Sprintf ( "%x" , e .Address ())
145
+ return hex . EncodeToString ( e .Address ())
144
146
}
145
147
146
148
// Register enters each address as kademlia peer record into the
@@ -580,6 +582,7 @@ func (k *Kademlia) KademliaInfo() KademliaInfo {
580
582
}
581
583
582
584
func (k * Kademlia ) kademliaInfo () (ki KademliaInfo ) {
585
+ ki .Self = hex .EncodeToString (k .BaseAddr ())
583
586
ki .Depth = depthForPot (k .conns , k .NeighbourhoodSize , k .base )
584
587
ki .TotalConnections = k .conns .Size ()
585
588
ki .TotalKnown = k .addrs .Size ()
@@ -594,7 +597,7 @@ func (k *Kademlia) kademliaInfo() (ki KademliaInfo) {
594
597
row := []string {}
595
598
f (func (val pot.Val ) bool {
596
599
e := val .(* Peer )
597
- row = append (row , fmt . Sprintf ( "%x" , e .Address ()))
600
+ row = append (row , hex . EncodeToString ( e .Address ()))
598
601
return true
599
602
})
600
603
sort .Strings (row )
@@ -611,7 +614,7 @@ func (k *Kademlia) kademliaInfo() (ki KademliaInfo) {
611
614
row := []string {}
612
615
f (func (val pot.Val ) bool {
613
616
e := val .(* entry )
614
- row = append (row , fmt . Sprintf ( "%x" , e .Address ()))
617
+ row = append (row , hex . EncodeToString ( e .Address ()))
615
618
return true
616
619
})
617
620
sort .Strings (row )
@@ -657,7 +660,7 @@ func (k *Kademlia) string() string {
657
660
rest -= size
658
661
f (func (val pot.Val ) bool {
659
662
e := val .(* Peer )
660
- row = append (row , fmt . Sprintf ( "%x" , e .Address ()[:2 ]))
663
+ row = append (row , hex . EncodeToString ( e .Address ()[:2 ]))
661
664
rowlen ++
662
665
return rowlen < 4
663
666
})
0 commit comments