Commit 75458ac9 authored by Brian Tiger Chow's avatar Brian Tiger Chow

feat(dht/message) add PeerRoutingInfo

parent 3fdba426
......@@ -10,6 +10,11 @@ import (
var log = eventlog.Logger("dht.pb")
type PeerRoutingInfo struct {
peer.PeerInfo
inet.Connectedness
}
// NewMessage constructs a new dht message with given type, key, and level
func NewMessage(typ Message_MessageType, key string, level int) *Message {
m := &Message{
......@@ -20,6 +25,20 @@ func NewMessage(typ Message_MessageType, key string, level int) *Message {
return m
}
func peerRoutingInfoToPBPeer(p PeerRoutingInfo) *Message_Peer {
pbp := new(Message_Peer)
pbp.Addrs = make([][]byte, len(p.Addrs))
for i, maddr := range p.Addrs {
pbp.Addrs[i] = maddr.Bytes() // Bytes, not String. Compressed.
}
s := string(p.ID)
pbp.Id = &s
c := ConnectionType(p.Connectedness)
pbp.Connection = &c
return pbp
}
func peerInfoToPBPeer(p peer.PeerInfo) *Message_Peer {
pbp := new(Message_Peer)
......@@ -63,6 +82,14 @@ func PeerInfosToPBPeers(n inet.Network, peers []peer.PeerInfo) []*Message_Peer {
return pbps
}
func PeerRoutingInfosToPBPeers(peers []PeerRoutingInfo) []*Message_Peer {
pbpeers := make([]*Message_Peer, len(peers))
for i, p := range peers {
pbpeers[i] = peerRoutingInfoToPBPeer(p)
}
return pbpeers
}
// PBPeersToPeerInfos converts given []*Message_Peer into []peer.PeerInfo
// Invalid addresses will be silently omitted.
func PBPeersToPeerInfos(pbps []*Message_Peer) []peer.PeerInfo {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment