mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Key/value database rename functions.
This commit is contained in:
@@ -141,7 +141,7 @@ func GetData(hash []byte) (data []byte, senderNodeID []byte, found bool) {
|
||||
|
||||
// GetDataLocal returns data from the local warehouse.
|
||||
func GetDataLocal(hash []byte) (data []byte, found bool) {
|
||||
return Warehouse.Retrieve(hash)
|
||||
return Warehouse.Get(hash)
|
||||
}
|
||||
|
||||
// GetDataDHT requests data via DHT
|
||||
@@ -153,14 +153,14 @@ func GetDataDHT(hash []byte) (data []byte, senderNodeID []byte, found bool) {
|
||||
// StoreDataLocal stores data into the local warehouse.
|
||||
func StoreDataLocal(data []byte) error {
|
||||
key := hashData(data)
|
||||
return Warehouse.Store(key, data)
|
||||
return Warehouse.Set(key, data)
|
||||
}
|
||||
|
||||
// StoreDataDHT stores data locally and informs closestCount peers in the DHT about it.
|
||||
// Remote peers may choose to keep a record (in case another peers asks) or mirror the full data.
|
||||
func StoreDataDHT(data []byte, closestCount int) error {
|
||||
key := hashData(data)
|
||||
if err := Warehouse.Store(key, data); err != nil {
|
||||
if err := Warehouse.Set(key, data); err != nil {
|
||||
return err
|
||||
}
|
||||
return nodesDHT.Store(key, uint64(len(data)), closestCount)
|
||||
|
||||
14
Store.go
14
Store.go
@@ -7,9 +7,6 @@ Author: Peter Kleissner
|
||||
package core
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/PeernetOfficial/core/store"
|
||||
)
|
||||
|
||||
@@ -25,7 +22,7 @@ func initStore() {
|
||||
// announcementGetData returns data for an announcement
|
||||
func announcementGetData(hash []byte) (stored bool, data []byte) {
|
||||
// TODO: Create RetrieveIfSize to prevent files larger than EmbeddedFileSizeMax from being loaded
|
||||
data, found := Warehouse.Retrieve(hash)
|
||||
data, found := Warehouse.Get(hash)
|
||||
if !found {
|
||||
return false, nil
|
||||
}
|
||||
@@ -44,7 +41,10 @@ func (peer *PeerInfo) announcementStore(records []InfoStore) {
|
||||
// - not exceeding record count per peer
|
||||
// - not exceeding total record count limit
|
||||
// - not exceeding record count per CIDR
|
||||
for _, record := range records {
|
||||
fmt.Printf("Remote node %s stores hash %s (size %d type %d)\n", hex.EncodeToString(peer.NodeID), hex.EncodeToString(record.ID.Hash), record.Size, record.Type)
|
||||
}
|
||||
//for _, record := range records {
|
||||
//fmt.Printf("Remote node %s stores hash %s (size %d type %d)\n", hex.EncodeToString(peer.NodeID), hex.EncodeToString(record.ID.Hash), record.Size, record.Type)
|
||||
//Warehouse.Store(record.ID.Hash, )
|
||||
// TODO: Request data from remote node.
|
||||
//peer.sendAnnouncement(false, false, nil, []KeyHash{record.ID}, nil, nil)
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ func (ms *MemoryStore) ExpireKeys() {
|
||||
}
|
||||
}
|
||||
|
||||
// Store stores the key/value pair.
|
||||
func (ms *MemoryStore) Store(key []byte, data []byte) error {
|
||||
// Set stores the key/value pair.
|
||||
func (ms *MemoryStore) Set(key []byte, data []byte) error {
|
||||
ms.mutex.Lock()
|
||||
ms.data[string(key)] = data
|
||||
ms.mutex.Unlock()
|
||||
@@ -56,8 +56,8 @@ func (ms *MemoryStore) StoreExpire(key []byte, data []byte, expiration time.Time
|
||||
return nil
|
||||
}
|
||||
|
||||
// Retrieve returns the value for the key if present.
|
||||
func (ms *MemoryStore) Retrieve(key []byte) (data []byte, found bool) {
|
||||
// Get returns the value for the key if present.
|
||||
func (ms *MemoryStore) Get(key []byte) (data []byte, found bool) {
|
||||
ms.mutex.Lock()
|
||||
data, found = ms.data[string(key)]
|
||||
ms.mutex.Unlock()
|
||||
|
||||
@@ -14,15 +14,15 @@ import (
|
||||
|
||||
// Store is the interface for implementing the storage mechanism for the DHT.
|
||||
type Store interface {
|
||||
// Store stores the key/value pair.
|
||||
Store(key []byte, data []byte) error
|
||||
// Set stores the key/value pair.
|
||||
Set(key []byte, data []byte) error
|
||||
|
||||
// StoreExpire stores the key/value pair and deletes it after the expiration time.
|
||||
// If key/value already exists, it will be overwritten and the new expiration time applies.
|
||||
StoreExpire(key []byte, data []byte, expiration time.Time) error
|
||||
|
||||
// Retrieve returns the value for the key if present.
|
||||
Retrieve(key []byte) (data []byte, found bool)
|
||||
// Get returns the value for the key if present.
|
||||
Get(key []byte) (data []byte, found bool)
|
||||
|
||||
// Delete deletes a key/value pair.
|
||||
Delete(key []byte)
|
||||
|
||||
Reference in New Issue
Block a user