forked from aergoio/aergo
/
p2pmore.go
51 lines (42 loc) · 1.03 KB
/
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
44
45
46
47
48
49
50
51
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package types
import (
"net"
"strconv"
"time"
"github.com/libp2p/go-libp2p-peer"
)
// PeerAccessor is an interface for a another actor module to get info of peers
type PeerAccessor interface {
GetPeerBlockInfos() []PeerBlockInfo
}
type PeerBlockInfo interface {
ID() peer.ID
State() PeerState
LastNotice() *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"] = peer.ID(addr.PeerID).Pretty()
arr[i] = vMap
}
return arr
}