cmd/swarm, swarm: LocalStore storage integration
This commit is contained in:
committed by
Anton Evangelatov
parent
c94d582aa7
commit
996755c4a8
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations"
|
||||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||
"github.com/ethereum/go-ethereum/swarm/network"
|
||||
"github.com/ethereum/go-ethereum/swarm/network/simulation"
|
||||
"github.com/ethereum/go-ethereum/swarm/pot"
|
||||
@@ -190,10 +191,10 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
|
||||
node := sim.Net.GetRandomUpNode()
|
||||
item, ok := sim.NodeItem(node.ID(), bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("No localstore")
|
||||
return errors.New("no store in simulation bucket")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID(), chunkCount, lstore)
|
||||
store := item.(chunk.Store)
|
||||
hashes, err := uploadFileToSingleNodeStore(node.ID(), chunkCount, store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -221,25 +222,25 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
|
||||
localChunks := conf.idToChunksMap[id]
|
||||
for _, ch := range localChunks {
|
||||
//get the real chunk by the index in the index array
|
||||
chunk := conf.hashes[ch]
|
||||
log.Trace(fmt.Sprintf("node has chunk: %s:", chunk))
|
||||
ch := conf.hashes[ch]
|
||||
log.Trace("node has chunk", "address", ch)
|
||||
//check if the expected chunk is indeed in the localstore
|
||||
var err error
|
||||
if *useMockStore {
|
||||
//use the globalStore if the mockStore should be used; in that case,
|
||||
//the complete localStore stack is bypassed for getting the chunk
|
||||
_, err = globalStore.Get(common.BytesToAddress(id.Bytes()), chunk)
|
||||
_, err = globalStore.Get(common.BytesToAddress(id.Bytes()), ch)
|
||||
} else {
|
||||
//use the actual localstore
|
||||
item, ok := sim.NodeItem(id, bucketKeyStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("Error accessing localstore")
|
||||
return errors.New("no store in simulation bucket")
|
||||
}
|
||||
lstore := item.(*storage.LocalStore)
|
||||
_, err = lstore.Get(ctx, chunk)
|
||||
store := item.(chunk.Store)
|
||||
_, err = store.Get(ctx, chunk.ModeGetLookup, ch)
|
||||
}
|
||||
if err != nil {
|
||||
log.Debug(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
|
||||
log.Debug("chunk not found", "address", ch.Hex(), "node", id)
|
||||
// Do not get crazy with logging the warn message
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
continue REPEAT
|
||||
@@ -247,10 +248,10 @@ func runSim(conf *synctestConfig, ctx context.Context, sim *simulation.Simulatio
|
||||
evt := &simulations.Event{
|
||||
Type: EventTypeChunkArrived,
|
||||
Node: sim.Net.GetNode(id),
|
||||
Data: chunk.String(),
|
||||
Data: ch.String(),
|
||||
}
|
||||
sim.Net.Events().Send(evt)
|
||||
log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id))
|
||||
log.Trace("chunk found", "address", ch.Hex(), "node", id)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -296,9 +297,9 @@ func mapKeysToNodes(conf *synctestConfig) {
|
||||
}
|
||||
|
||||
//upload a file(chunks) to a single local node store
|
||||
func uploadFileToSingleNodeStore(id enode.ID, chunkCount int, lstore *storage.LocalStore) ([]storage.Address, error) {
|
||||
func uploadFileToSingleNodeStore(id enode.ID, chunkCount int, store chunk.Store) ([]storage.Address, error) {
|
||||
log.Debug(fmt.Sprintf("Uploading to node id: %s", id))
|
||||
fileStore := storage.NewFileStore(lstore, storage.NewFileStoreParams())
|
||||
fileStore := storage.NewFileStore(store, storage.NewFileStoreParams())
|
||||
size := chunkSize
|
||||
var rootAddrs []storage.Address
|
||||
for i := 0; i < chunkCount; i++ {
|
||||
|
Reference in New Issue
Block a user