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-peerstore
Commits
aae59b74
Commit
aae59b74
authored
Apr 23, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize memory of in-memory peerstore
parent
deb2163a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
pstoremem/metadata.go
pstoremem/metadata.go
+9
-9
No files found.
pstoremem/metadata.go
View file @
aae59b74
...
...
@@ -7,10 +7,15 @@ import (
pstore
"github.com/libp2p/go-libp2p-peerstore"
)
type
metakey
struct
{
id
peer
.
ID
key
string
}
type
memoryPeerMetadata
struct
{
// store other data, like versions
//ds ds.ThreadSafeDatastore
ds
map
[
string
]
interface
{}
ds
map
[
metakey
]
interface
{}
dslock
sync
.
Mutex
}
...
...
@@ -18,26 +23,21 @@ var _ pstore.PeerMetadata = (*memoryPeerMetadata)(nil)
func
NewPeerMetadata
()
pstore
.
PeerMetadata
{
return
&
memoryPeerMetadata
{
ds
:
make
(
map
[
string
]
interface
{}),
ds
:
make
(
map
[
metakey
]
interface
{}),
}
}
func
(
ps
*
memoryPeerMetadata
)
Put
(
p
peer
.
ID
,
key
string
,
val
interface
{})
error
{
//dsk := ds.NewKey(string(p) + "/" + key)
//return ps.ds.Put(dsk, val)
ps
.
dslock
.
Lock
()
defer
ps
.
dslock
.
Unlock
()
ps
.
ds
[
string
(
p
)
+
"/"
+
key
]
=
val
ps
.
ds
[
metakey
{
p
,
key
}
]
=
val
return
nil
}
func
(
ps
*
memoryPeerMetadata
)
Get
(
p
peer
.
ID
,
key
string
)
(
interface
{},
error
)
{
//dsk := ds.NewKey(string(p) + "/" + key)
//return ps.ds.Get(dsk)
ps
.
dslock
.
Lock
()
defer
ps
.
dslock
.
Unlock
()
i
,
ok
:=
ps
.
ds
[
string
(
p
)
+
"/"
+
key
]
i
,
ok
:=
ps
.
ds
[
metakey
{
p
,
key
}
]
if
!
ok
{
return
nil
,
pstore
.
ErrNotFound
}
...
...
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