Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions network/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package network

import (
"bytes"
"encoding/hex"
"fmt"
"math/rand"
"sort"
Expand Down Expand Up @@ -95,6 +96,7 @@ type Kademlia struct {
}

type KademliaInfo struct {
Self string `json:"self"`
Depth int `json:"depth"`
TotalConnections int `json:"total_connections"`
TotalKnown int `json:"total_known"`
Expand Down Expand Up @@ -140,7 +142,7 @@ func Label(e *entry) string {

// Hex is the hexadecimal serialisation of the entry address
func (e *entry) Hex() string {
return fmt.Sprintf("%x", e.Address())
return hex.EncodeToString(e.Address())
}

// Register enters each address as kademlia peer record into the
Expand Down Expand Up @@ -580,6 +582,7 @@ func (k *Kademlia) KademliaInfo() KademliaInfo {
}

func (k *Kademlia) kademliaInfo() (ki KademliaInfo) {
ki.Self = hex.EncodeToString(k.BaseAddr())
ki.Depth = depthForPot(k.conns, k.NeighbourhoodSize, k.base)
ki.TotalConnections = k.conns.Size()
ki.TotalKnown = k.addrs.Size()
Expand All @@ -594,7 +597,7 @@ func (k *Kademlia) kademliaInfo() (ki KademliaInfo) {
row := []string{}
f(func(val pot.Val) bool {
e := val.(*Peer)
row = append(row, fmt.Sprintf("%x", e.Address()))
row = append(row, hex.EncodeToString(e.Address()))
return true
})
sort.Strings(row)
Expand All @@ -611,7 +614,7 @@ func (k *Kademlia) kademliaInfo() (ki KademliaInfo) {
row := []string{}
f(func(val pot.Val) bool {
e := val.(*entry)
row = append(row, fmt.Sprintf("%x", e.Address()))
row = append(row, hex.EncodeToString(e.Address()))
return true
})
sort.Strings(row)
Expand Down Expand Up @@ -657,7 +660,7 @@ func (k *Kademlia) string() string {
rest -= size
f(func(val pot.Val) bool {
e := val.(*Peer)
row = append(row, fmt.Sprintf("%x", e.Address()[:2]))
row = append(row, hex.EncodeToString(e.Address()[:2]))
rowlen++
return rowlen < 4
})
Expand Down