mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm/storage: global chunk rules in MRU
This commit is contained in:
parent
898a548ad1
commit
7c0013c364
6 changed files with 13 additions and 29 deletions
|
|
@ -99,6 +99,8 @@ func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error) {
|
|||
// contains the chunk with the same data, but nil ReqC channel.
|
||||
func (ls *LocalStore) Put(ctx context.Context, chunk *Chunk) {
|
||||
valid := true
|
||||
// ls.Validators contains a list of one validator per chunk type.
|
||||
// if one validator succeeds, then the chunk is valid
|
||||
for _, v := range ls.Validators {
|
||||
if valid = v.Validate(chunk.Addr, chunk.SData); valid {
|
||||
break
|
||||
|
|
|
|||
|
|
@ -25,12 +25,11 @@ import (
|
|||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||
"github.com/ethereum/go-ethereum/swarm/log"
|
||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||
)
|
||||
|
||||
const chunkSize = 4096 // temporary until we implement FileStore in the resourcehandler
|
||||
|
||||
type Handler struct {
|
||||
chunkStore *storage.NetStore
|
||||
HashSize int
|
||||
|
|
@ -65,8 +64,7 @@ func init() {
|
|||
}
|
||||
|
||||
// NewHandler creates a new Mutable Resource API
|
||||
func NewHandler(params *HandlerParams) (*Handler, error) {
|
||||
|
||||
func NewHandler(params *HandlerParams) *Handler {
|
||||
rh := &Handler{
|
||||
resources: make(map[uint64]*resource),
|
||||
storeTimeout: defaultStoreTimeout,
|
||||
|
|
@ -81,7 +79,7 @@ func NewHandler(params *HandlerParams) (*Handler, error) {
|
|||
hashPool.Put(hashfunc)
|
||||
}
|
||||
|
||||
return rh, nil
|
||||
return rh
|
||||
}
|
||||
|
||||
// SetStore sets the store backend for the Mutable Resource API
|
||||
|
|
@ -94,7 +92,7 @@ func (h *Handler) SetStore(store *storage.NetStore) {
|
|||
// It implements the storage.ChunkValidator interface
|
||||
func (h *Handler) Validate(chunkAddr storage.Address, data []byte) bool {
|
||||
dataLength := len(data)
|
||||
if dataLength < minimumChunkLength {
|
||||
if dataLength < minimumChunkLength || dataLength > chunk.DefaultSize+8 {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -170,11 +168,6 @@ func (h *Handler) GetVersion(rootAddr storage.Address) (uint32, error) {
|
|||
return rsrc.version, nil
|
||||
}
|
||||
|
||||
// \TODO should be hashsize * branches from the chosen chunker, implement with FileStore
|
||||
func (h *Handler) chunkSize() int64 {
|
||||
return chunkSize
|
||||
}
|
||||
|
||||
// New creates a new metadata chunk out of the request passed in.
|
||||
func (h *Handler) New(ctx context.Context, request *Request) error {
|
||||
|
||||
|
|
|
|||
|
|
@ -777,10 +777,7 @@ func TestValidatorInStore(t *testing.T) {
|
|||
|
||||
// set up resource handler and add is as a validator to the localstore
|
||||
rhParams := &HandlerParams{}
|
||||
rh, err := NewHandler(rhParams)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rh := NewHandler(rhParams)
|
||||
store.Validators = append(store.Validators, rh)
|
||||
|
||||
// create content addressed chunks, one good, one faulty
|
||||
|
|
|
|||
|
|
@ -38,10 +38,7 @@ func (t *TestHandler) Close() {
|
|||
// NewTestHandler creates Handler object to be used for testing purposes.
|
||||
func NewTestHandler(datadir string, params *HandlerParams) (*TestHandler, error) {
|
||||
path := filepath.Join(datadir, testDbDirName)
|
||||
rh, err := NewHandler(params)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("resource handler create fail: %v", err)
|
||||
}
|
||||
rh := NewHandler(params)
|
||||
localstoreparams := storage.NewDefaultLocalStoreParams()
|
||||
localstoreparams.Init(path)
|
||||
localStore, err := storage.NewLocalStore(localstoreparams, nil)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||
"github.com/ethereum/go-ethereum/swarm/log"
|
||||
"github.com/ethereum/go-ethereum/swarm/multihash"
|
||||
)
|
||||
|
|
@ -42,7 +43,7 @@ const chunkPrefixLength = 2 + 2
|
|||
//
|
||||
// Minimum size is Header + 1 (minimum data length, enforced)
|
||||
const minimumUpdateDataLength = updateHeaderLength + 1
|
||||
const maxUpdateDataLength = chunkSize - signatureLength - updateHeaderLength - chunkPrefixLength
|
||||
const maxUpdateDataLength = chunk.DefaultSize - signatureLength - updateHeaderLength - chunkPrefixLength
|
||||
|
||||
// binaryPut serializes the resource update information into the given slice
|
||||
func (r *resourceUpdate) binaryPut(serializedData []byte) error {
|
||||
|
|
|
|||
|
|
@ -195,19 +195,13 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e
|
|||
var resourceHandler *mru.Handler
|
||||
rhparams := &mru.HandlerParams{}
|
||||
|
||||
resourceHandler, err = mru.NewHandler(rhparams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resourceHandler = mru.NewHandler(rhparams)
|
||||
resourceHandler.SetStore(netStore)
|
||||
|
||||
validators := []storage.ChunkValidator{
|
||||
self.lstore.Validators = []storage.ChunkValidator{
|
||||
storage.NewContentAddressValidator(storage.MakeHashFunc(storage.DefaultHash)),
|
||||
resourceHandler,
|
||||
}
|
||||
if resourceHandler != nil {
|
||||
validators = append(validators, resourceHandler)
|
||||
}
|
||||
self.lstore.Validators = validators
|
||||
|
||||
// setup local store
|
||||
log.Debug(fmt.Sprintf("Set up local storage"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue