Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kad-dht
Commits
75458ac9
Commit
75458ac9
authored
Jan 27, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(dht/message) add PeerRoutingInfo
parent
3fdba426
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
pb/message.go
pb/message.go
+27
-0
No files found.
pb/message.go
View file @
75458ac9
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment