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-core
Commits
6690d78e
Unverified
Commit
6690d78e
authored
Mar 27, 2020
by
Vibhav Pant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
peer: Add PeerRecordFromProtobuf.
parent
075ac748
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
peer/record.go
peer/record.go
+21
-5
No files found.
peer/record.go
View file @
6690d78e
...
...
@@ -108,6 +108,23 @@ func PeerRecordFromAddrInfo(info AddrInfo) *PeerRecord {
return
rec
}
// PeerRecordFromProtobuf creates a PeerRecord from a protobuf PeerRecord
// struct.
func
PeerRecordFromProtobuf
(
msg
*
pb
.
PeerRecord
)
(
*
PeerRecord
,
error
)
{
record
:=
&
PeerRecord
{}
var
id
ID
if
err
:=
id
.
UnmarshalBinary
(
msg
.
PeerId
);
err
!=
nil
{
return
nil
,
err
}
record
.
PeerID
=
id
record
.
Addrs
=
addrsFromProtobuf
(
msg
.
Addresses
)
record
.
Seq
=
msg
.
Seq
return
record
,
nil
}
// TimestampSeq is a helper to generate a timestamp-based sequence number for a PeerRecord.
func
TimestampSeq
()
uint64
{
return
uint64
(
time
.
Now
()
.
UnixNano
())
...
...
@@ -138,14 +155,13 @@ func (r *PeerRecord) UnmarshalRecord(bytes []byte) error {
if
err
!=
nil
{
return
err
}
var
id
ID
err
=
id
.
UnmarshalBinary
(
msg
.
PeerId
)
rPtr
,
err
:
=
PeerRecordFromProtobuf
(
&
msg
)
if
err
!=
nil
{
return
err
}
r
.
PeerID
=
id
r
.
Addrs
=
addrsFromProtobuf
(
msg
.
Addresses
)
r
.
Seq
=
msg
.
Seq
*
r
=
*
rPtr
return
nil
}
...
...
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