-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDHT Store.go
48 lines (40 loc) · 1.48 KB
/
DHT Store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
File Username: DHT Store.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/
package core
import (
"github.com/PeernetOfficial/core/protocol"
"github.com/PeernetOfficial/core/store"
)
// TODO: Via descriptors, files stored by other peers
func (backend *Backend) initStore() {
backend.dhtStore = store.NewMemoryStore()
}
// announcementGetData returns data for an announcement
func (peer *PeerInfo) announcementGetData(hash []byte) (stored bool, data []byte) {
// TODO: Create RetrieveIfSize to prevent files larger than EmbeddedFileSizeMax from being loaded
data, found := peer.Backend.dhtStore.Get(hash)
if !found {
return false, nil
}
if len(data) <= protocol.EmbeddedFileSizeMax {
return true, data
}
return true, nil
}
// announcementStore handles an incoming announcement by another peer about storing data
func (peer *PeerInfo) announcementStore(records []protocol.InfoStore) {
// TODO: Only store the other peers data if certain conditions are met:
// - enough storage available
// - 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)
//Warehouse.Store(record.ID.Hash, )
// TODO: Request data from remote node.
//peer.sendAnnouncement(false, false, nil, []KeyHash{record.ID}, nil, nil)
//}
}