forked from aergoio/aergo
/
p2pmore.go
43 lines (37 loc) · 865 Bytes
/
p2pmore.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
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package types
import (
"net"
"strconv"
"time"
)
type PeerBlockInfo interface {
ID() PeerID
State() PeerState
LastStatus() *LastBlockStatus
}
// LastBlockStatus i
type LastBlockStatus struct {
CheckTime time.Time
BlockHash []byte
BlockNumber uint64
}
// ResponseMessage contains response status
type ResponseMessage interface {
GetStatus() ResultStatus
}
// AddressesToStringMap make map of string for logging or json encoding
func AddressesToStringMap(addrs []*PeerAddress) []map[string]string {
arr := make([]map[string]string, len(addrs))
for i, addr := range addrs {
vMap := make(map[string]string)
vMap["address"] = net.IP(addr.Address).String()
vMap["port"] = strconv.Itoa(int(addr.Port))
vMap["peerId"] = PeerID(addr.PeerID).Pretty()
arr[i] = vMap
}
return arr
}