mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
rebase on current develop branch 2016-07-09 swarm/services/ens: * Rework ENS functionality to use the current spec. * Refactor ens.go to set up sessions as needed * Refactoring to support independent registrar and personal resolver contracts * fixed tests swarm/examples/album: improve upload UX * No more unhandled errors and loose ends in the UI. * Forward/Back buttons work as undo/redo * all long operations display an informative modal dialog * minor problems with cursor movements fixed * reorder labels * throbber as default image * change browser history after delete or upload photo swarm/storage: * optimise splitter * simplify reader * benchmarks, tests improved * simplify IO, remove chunkreader.go and io.SectionReader clone * simplify error/timeout handling * port pyramid splitter by karalabe, adapt to Splitter/DPA interface, rework params etc * make NetStore.Put -> cloud.Store synchronous * chunker join fix process leak and keep parallelisation limited to depth 1 * reset the base hash to SHA3. !!hard fork = no backward compatibility :) * SectionReader -> LazySectionReader: Size method signature change * introduce abort channel to joiner to fix process leak * add abort channel context to all manifest retrieval methods * global waitgroup fixes intermittent upload test failures due to unfinished storage of chunks * streamline joiner logic, contexts now unique to each readAt call * LazyChunkReader seeker complains about missing size only if whence=2 * chunker join fix process leak and keep parallelisation limited to depth 1 swarm/network/kademlia: * simplify code * now really fix prox limit adjustment + tests and comments * simplify and make readable findclosest algo code + comments * reset initial time interval settings for kaddb findbest * fix bucket replace scheme to optimise stability and availability * absolute idle peers are disconnected after maxIdleInterval * fix index out of range when deleting last idle peer from kaddb * unwanted peers (due to full kad bucket) are now properly dropped with ErrUnwanted * improve logging and reorg in kademlia * simplify and fix code that deletes expired/unconnectable nodes * kaddb.findBest does not get stuck on empty row but finds an actual missing node * must replace node if bucket is full otherwise nodes will get stuck on empty rows * kademlia: timer fix * remove logging the state when syncing (resulting in deadlock) * improved logs, fix potential deadlock in String() * native go time marshalling * tests fixed swarm/network: * log node address consistently in syncdb * syncer logs queue cardinalities properly in syncUnSyncedKeys loop * fix hive stop issue leading to send on closed chan + minor logging fixes * better logging * hive interface change * fix process leak by adding select to state.synced <- false swarm/cmd: swarm control cli improvements * no more alias, swarm is executable so it can be called via ssh * environment vars now set to default, no need to preconfigure * local and remote hive monitoring * gethup.sh script now merged into swarm script and nice modularised * simplify bash code and fix e2e tests in swarm/test * stop method falls back to kill -9 after 10s * enode method now supplies ip addr via ipecho request * execute, options, rawoptions, setup, create-account addpeers and hive subcommands * update-src -> update * remote-update-scripts, remote-update-bin and remote-run * local and remote monitoring of kademlia * extensive documentation in swarm/cmd/README.md * add cleanlog, cleanbzz, update-src, remote-update-scripts, remote-update-bin, remote-run * for remote binary update, take scripts from swarm/cmd/swarm * raise default maxpeers to 40 * add latency loggingo to upload and download * add checkdownload and checkaccess subcommands * add mem/cpu/disk-info commands * include randomfile cmd from test * add enode, connect subcommands, improve startup (only one round needed) * TODO: simplify tests using new checks swarm/api/http: server handler: check protocol substring length to fix slice out of bounds crash swarm/api: * fix filesystem API - upload/Modify tests * simplify downloader code and fix process leak * change KAD defaults bucketsize 4, minproxbinsize 2 * add back final slash to paths in manifest matching * fix filesystem api tests
118 lines
3.6 KiB
Go
118 lines
3.6 KiB
Go
package storage
|
|
|
|
import (
|
|
"path/filepath"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/logger"
|
|
"github.com/ethereum/go-ethereum/logger/glog"
|
|
)
|
|
|
|
/*
|
|
NetStore is a cloud storage access abstaction layer for swarm
|
|
it contains the shared logic of network served chunk store/retrieval requests
|
|
both local (coming from DPA api) and remote (coming from peers via bzz protocol)
|
|
it implements the ChunkStore interface and embeds LocalStore
|
|
|
|
It is called by the bzz protocol instances via Depo (the store/retrieve request handler)
|
|
a protocol instance is running on each peer, so this is heavily parallelised.
|
|
NetStore falls back to a backend (CloudStorage interface)
|
|
implemented by bzz/network/forwarder. forwarder or IPFS or IPΞS
|
|
*/
|
|
type NetStore struct {
|
|
hashfunc Hasher
|
|
localStore *LocalStore
|
|
cloud CloudStore
|
|
lock sync.Mutex
|
|
}
|
|
|
|
// backend engine for cloud store
|
|
// It can be aggregate dispatching to several parallel implementations:
|
|
// bzz/network/forwarder. forwarder or IPFS or IPΞS
|
|
type CloudStore interface {
|
|
Store(*Chunk)
|
|
Deliver(*Chunk)
|
|
Retrieve(*Chunk)
|
|
}
|
|
|
|
type StoreParams struct {
|
|
ChunkDbPath string
|
|
DbCapacity uint64
|
|
CacheCapacity uint
|
|
Radius int
|
|
}
|
|
|
|
func NewStoreParams(path string) (self *StoreParams) {
|
|
return &StoreParams{
|
|
ChunkDbPath: filepath.Join(path, "chunks"),
|
|
DbCapacity: defaultDbCapacity,
|
|
CacheCapacity: defaultCacheCapacity,
|
|
Radius: defaultRadius,
|
|
}
|
|
}
|
|
|
|
// netstore contructor, takes path argument that is used to initialise dbStore,
|
|
// the persistent (disk) storage component of LocalStore
|
|
// the second argument is the hive, the connection/logistics manager for the node
|
|
func NewNetStore(hash Hasher, lstore *LocalStore, cloud CloudStore, params *StoreParams) *NetStore {
|
|
return &NetStore{
|
|
hashfunc: hash,
|
|
localStore: lstore,
|
|
cloud: cloud,
|
|
}
|
|
}
|
|
|
|
const (
|
|
// maximum number of peers that a retrieved message is delivered to
|
|
requesterCount = 3
|
|
)
|
|
|
|
var (
|
|
// timeout interval before retrieval is timed out
|
|
searchTimeout = 3 * time.Second
|
|
)
|
|
|
|
// store logic common to local and network chunk store requests
|
|
// ~ unsafe put in localdb no check if exists no extra copy no hash validation
|
|
// the chunk is forced to propagate (Cloud.Store) even if locally found!
|
|
// caller needs to make sure if that is wanted
|
|
func (self *NetStore) Put(entry *Chunk) {
|
|
self.localStore.Put(entry)
|
|
|
|
// handle deliveries
|
|
if entry.Req != nil {
|
|
glog.V(logger.Detail).Infof("[BZZ] NetStore.Put: localStore.Put %v hit existing request...delivering", entry.Key.Log())
|
|
// closing C singals to other routines (local requests)
|
|
// that the chunk is has been retrieved
|
|
close(entry.Req.C)
|
|
// deliver the chunk to requesters upstream
|
|
self.cloud.Deliver(entry)
|
|
} else {
|
|
glog.V(logger.Detail).Infof("[BZZ] NetStore.Put: localStore.Put %v stored locally", entry.Key.Log())
|
|
// handle propagating store requests
|
|
// go self.cloud.Store(entry)
|
|
self.cloud.Store(entry)
|
|
}
|
|
}
|
|
|
|
// retrieve logic common for local and network chunk retrieval requests
|
|
func (self *NetStore) Get(key Key) (*Chunk, error) {
|
|
var err error
|
|
chunk, err := self.localStore.Get(key)
|
|
if err == nil {
|
|
if chunk.Req == nil {
|
|
glog.V(logger.Detail).Infof("[BZZ] NetStore.Get: %v found locally", key)
|
|
} else {
|
|
glog.V(logger.Detail).Infof("[BZZ] NetStore.Get: %v hit on an existing request", key)
|
|
// no need to launch again
|
|
}
|
|
return chunk, err
|
|
}
|
|
// no data and no request status
|
|
glog.V(logger.Detail).Infof("[BZZ] NetStore.Get: %v not found locally. open new request", key)
|
|
chunk = NewChunk(key, newRequestStatus(key))
|
|
self.localStore.memStore.Put(chunk)
|
|
go self.cloud.Retrieve(chunk)
|
|
return chunk, nil
|
|
}
|