-
Notifications
You must be signed in to change notification settings - Fork 342
/
Copy pathstore.go
83 lines (63 loc) · 2.11 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2022 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package inmemstore
import (
"context"
"sync"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
)
// Store implements a simple Putter and Getter which can be used to temporarily cache
// chunks. Currently this is used in the bootstrapping process of new nodes where
// we sync the postage events from the swarm network.
type Store struct {
mtx sync.Mutex
store map[string]swarm.Chunk
}
func New() *Store {
return &Store{
store: make(map[string]swarm.Chunk),
}
}
func (s *Store) Get(_ context.Context, _ storage.ModeGet, addr swarm.Address) (ch swarm.Chunk, err error) {
s.mtx.Lock()
defer s.mtx.Unlock()
if ch, ok := s.store[addr.ByteString()]; ok {
return ch, nil
}
return nil, storage.ErrNotFound
}
func (s *Store) Put(_ context.Context, _ storage.ModePut, chs ...swarm.Chunk) (exist []bool, err error) {
s.mtx.Lock()
defer s.mtx.Unlock()
for _, ch := range chs {
s.store[ch.Address().ByteString()] = ch
}
exist = make([]bool, len(chs))
return exist, err
}
func (s *Store) GetMulti(_ context.Context, _ storage.ModeGet, _ ...swarm.Address) (ch []swarm.Chunk, err error) {
panic("not implemented")
}
func (s *Store) Has(_ context.Context, _ swarm.Address) (yes bool, err error) {
panic("not implemented")
}
func (s *Store) HasMulti(_ context.Context, _ ...swarm.Address) (yes []bool, err error) {
panic("not implemented")
}
func (s *Store) Set(_ context.Context, _ storage.ModeSet, _ ...swarm.Address) (err error) {
panic("not implemented")
}
func (s *Store) LastPullSubscriptionBinID(_ uint8) (id uint64, err error) {
panic("not implemented")
}
func (s *Store) SubscribePull(_ context.Context, _ uint8, _ uint64, _ uint64) (c <-chan storage.Descriptor, closed <-chan struct{}, stop func()) {
panic("not implemented")
}
func (s *Store) SubscribePush(_ context.Context, _ func([]byte) bool) (c <-chan swarm.Chunk, repeat func(), stop func()) {
panic("not implemented")
}
func (s *Store) Close() error {
return nil
}