Skip to content

Commit

Permalink
Merge pull request #185 from libp2p/remove-interning
Browse files Browse the repository at this point in the history
remove metadata interning
  • Loading branch information
marten-seemann committed Dec 2, 2021
2 parents 7be535b + 0364daa commit 584b33d
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions p2p/host/peerstore/pstoremem/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ import (

type memoryPeerMetadata struct {
// store other data, like versions
// ds ds.ThreadSafeDatastore
ds map[peer.ID]map[string]interface{}
dslock sync.RWMutex
interned map[string]interface{}
ds map[peer.ID]map[string]interface{}
dslock sync.RWMutex
}

var _ pstore.PeerMetadata = (*memoryPeerMetadata)(nil)

func NewPeerMetadata() *memoryPeerMetadata {
return &memoryPeerMetadata{
ds: make(map[peer.ID]map[string]interface{}),
interned: make(map[string]interface{}),
ds: make(map[peer.ID]map[string]interface{}),
}
}

Expand All @@ -30,13 +27,6 @@ func (ps *memoryPeerMetadata) Put(p peer.ID, key string, val interface{}) error
}
ps.dslock.Lock()
defer ps.dslock.Unlock()
if vals, ok := val.(string); ok && (key == "AgentVersion" || key == "ProtocolVersion") {
if interned, ok := ps.interned[vals]; ok {
val = interned
} else {
ps.interned[vals] = val
}
}
m, ok := ps.ds[p]
if !ok {
m = make(map[string]interface{})
Expand Down

0 comments on commit 584b33d

Please sign in to comment.