storage

package
v0.0.0-...-f8b7a73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2019 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInit = iota
	ErrNotFound
	ErrUnauthorized
	ErrInvalidValue
	ErrDataOverflow
	ErrNothingToReturn
	ErrInvalidSignature
	ErrNotSynced
)
View Source
const (
	BMTHash     = "BMT"
	SHA3Hash    = "SHA3" //http://golang.org/pkg/hash/hash
	DefaultHash = BMTHash
)
View Source
const AddressLength = 32
View Source
const (
	ChunkProcessors = 8
)
View Source
const CurrentDbSchema = DbSchemaHalloween

我们要使用的DB模式。实际/当前数据库架构可能不同 直到运行迁移。

View Source
const DbSchemaHalloween = "halloween"

“万圣节”在这里是因为我们有一个螺丝钉在垃圾回收索引。 因此,我们必须重建gc索引以消除错误的 这需要很长的时间。此模式用于记账, 所以重建索引只运行一次。

View Source
const DbSchemaNone = ""

曾经有一段时间我们根本没有模式。

View Source
const DbSchemaPurity = "purity"

“纯度”是我们与Swarm 0.3.5一起发布的第一个级别数据库的正式模式。

View Source
const MaxPO = 16

Variables

View Source
var (
	ErrChunkNotFound = errors.New("chunk not found")
	ErrChunkInvalid  = errors.New("invalid chunk")
)
View Source
var (
	ErrDBClosed = errors.New("LDBStore closed")
)
View Source
var ZeroAddr = Address(common.Hash{}.Bytes())

Functions

func BytesToU64

func BytesToU64(data []byte) uint64

func NewChunk

func NewChunk(addr Address, data []byte) *chunk

func NewHasherStore

func NewHasherStore(store ChunkStore, hashFunc SwarmHasher, toEncrypt bool) *hasherStore

NewHasherStore创建了一个HasherStore对象,它实现了推杆和getter接口。 使用hasherstore,您可以将区块数据(仅为[]字节)放入chunkstore中并获取它们。 如果需要,哈希存储将获取数据加密/解密的核心。

func Proximity

func Proximity(one, other []byte) (ret int)

接近(x,y)返回x和y之间的最高位距离的接近顺序。

两个等长字节序列x和y的距离度量msb(x,y)是 x^y的二进制整数转换值,即x和y位xor-ed。 二进制转换是big-endian:最高有效位优先(=msb)。

邻近度(x,y)是最大有效位距离的离散对数标度。 它被定义为基2整数部分的倒序。 距离的对数。 它是通过计算(msb)中公共前导零的数目来计算的。 x^y的二进制表示。

(最远0个,最近255个,自己256个)

func U64ToBytes

func U64ToBytes(val uint64) []byte

Types

type Address

type Address []byte

func PyramidAppend

func PyramidAppend(ctx context.Context, addr Address, reader io.Reader, putter Putter, getter Getter) (Address, func(context.Context) error, error)

func PyramidSplit

func PyramidSplit(ctx context.Context, reader io.Reader, putter Putter, getter Getter) (Address, func(context.Context) error, error)

func TreeSplit

func TreeSplit(ctx context.Context, data io.Reader, size int64, putter Putter) (k Address, wait func(context.Context) error, err error)

func (Address) Hex

func (a Address) Hex() string

func (Address) Log

func (a Address) Log() string

func (Address) MarshalJSON

func (a Address) MarshalJSON() (out []byte, err error)

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(value []byte) error

type AddressCollection

type AddressCollection []Address

func NewAddressCollection

func NewAddressCollection(l int) AddressCollection

func (AddressCollection) Len

func (c AddressCollection) Len() int

func (AddressCollection) Less

func (c AddressCollection) Less(i, j int) bool

func (AddressCollection) Swap

func (c AddressCollection) Swap(i, j int)

type Chunk

type Chunk interface {
	Address() Address
	Data() []byte
}

由context.context和数据块实现的块接口

func GenerateRandomChunk

func GenerateRandomChunk(dataSize int64) Chunk

func GenerateRandomChunks

func GenerateRandomChunks(dataSize int64, count int) (chunks []Chunk)

type ChunkData

type ChunkData []byte

func (ChunkData) Size

func (c ChunkData) Size() uint64

注意:如果块被加密,这将返回无效数据。

type ChunkStore

type ChunkStore interface {
	Put(ctx context.Context, ch Chunk) (err error)
	Get(rctx context.Context, ref Address) (ch Chunk, err error)
	Close()
}

type ChunkValidator

type ChunkValidator interface {
	Validate(chunk Chunk) bool
}

type ChunkerParams

type ChunkerParams struct {
	// contains filtered or unexported fields
}

type ContentAddressValidator

type ContentAddressValidator struct {
	Hasher SwarmHasher
}

提供对内容地址进行块验证的方法 保留相应的哈希值以创建地址

func NewContentAddressValidator

func NewContentAddressValidator(hasher SwarmHasher) *ContentAddressValidator

构造函数

func (*ContentAddressValidator) Validate

func (v *ContentAddressValidator) Validate(chunk Chunk) bool

验证给定密钥是否为给定数据的有效内容地址

type FakeChunkStore

type FakeChunkStore struct {
}

FakeChunkStore不存储任何内容,只实现ChunkStore接口 如果您不想实际存储数据,可以使用它来注入哈希存储,只需执行 哈希

func (*FakeChunkStore) Close

func (f *FakeChunkStore) Close()

close不存储任何内容,它只是在这里实现chunkstore

func (*FakeChunkStore) Get

func (f *FakeChunkStore) Get(_ context.Context, ref Address) (Chunk, error)

gut不存储任何东西,它只是在这里实现chunkstore

func (*FakeChunkStore) Put

func (f *FakeChunkStore) Put(_ context.Context, ch Chunk) error

Put不存储任何东西它只是在这里实现chunkstore

type FileStore

type FileStore struct {
	ChunkStore
	// contains filtered or unexported fields
}

func NewFileStore

func NewFileStore(store ChunkStore, params *FileStoreParams) *FileStore

func NewLocalFileStore

func NewLocalFileStore(datadir string, basekey []byte) (*FileStore, error)

用于本地测试

func (*FileStore) HashSize

func (f *FileStore) HashSize() int

func (*FileStore) Retrieve

func (f *FileStore) Retrieve(ctx context.Context, addr Address) (reader *LazyChunkReader, isEncrypted bool)

公共API。文档直接检索的主要入口点。使用的 支持fs的api和httpaccess NetStore请求上的区块检索块超时,因此读卡器将 如果在请求的范围内检索块超时,则报告错误。 它返回一个读卡器,其中包含块数据以及内容是否加密。

func (*FileStore) Store

func (f *FileStore) Store(ctx context.Context, data io.Reader, size int64, toEncrypt bool) (addr Address, wait func(context.Context) error, err error)

公共API。文档直接存储的主要入口点。使用的 支持fs的api和httpaccess

type FileStoreParams

type FileStoreParams struct {
	Hash string
}

func NewFileStoreParams

func NewFileStoreParams() *FileStoreParams

type Getter

type Getter interface {
	Get(context.Context, Reference) (ChunkData, error)
}

getter是一个通过引用来检索块数据的接口。

type HashWithLength

type HashWithLength struct {
	hash.Hash
}

func (*HashWithLength) ResetWithLength

func (h *HashWithLength) ResetWithLength(length []byte)

type JoinerParams

type JoinerParams struct {
	ChunkerParams
	// contains filtered or unexported fields
}

type LDBDatabase

type LDBDatabase struct {
	// contains filtered or unexported fields
}

func NewLDBDatabase

func NewLDBDatabase(file string) (*LDBDatabase, error)

func (*LDBDatabase) Close

func (db *LDBDatabase) Close()

func (*LDBDatabase) Delete

func (db *LDBDatabase) Delete(key []byte) error

func (*LDBDatabase) Get

func (db *LDBDatabase) Get(key []byte) ([]byte, error)

func (*LDBDatabase) NewIterator

func (db *LDBDatabase) NewIterator() iterator.Iterator

func (*LDBDatabase) Put

func (db *LDBDatabase) Put(key []byte, value []byte) error

func (*LDBDatabase) Write

func (db *LDBDatabase) Write(batch *leveldb.Batch) error

type LDBStore

type LDBStore struct {
	// contains filtered or unexported fields
}

func NewLDBStore

func NewLDBStore(params *LDBStoreParams) (s *LDBStore, err error)

TODO:不传递距离函数,只传递计算距离的地址 为了避免可插拔距离度量的出现以及与提供 一种不同于实际使用的函数。

func NewMockDbStore

func NewMockDbStore(params *LDBStoreParams, mockStore *mock.NodeStore) (s *LDBStore, err error)

newmockdbstore创建dbstore的新实例 mockstore设置为提供的值。如果mockstore参数为零, 此函数的行为与newdbstore完全相同。

func (*LDBStore) BinIndex

func (s *LDBStore) BinIndex(po uint8) uint64

func (*LDBStore) CleanGCIndex

func (s *LDBStore) CleanGCIndex() error

CleangIndex从头重建垃圾收集器索引,而 删除不一致的元素,例如缺少数据块的索引。 警告:这是一个相当重的长期运行功能。

func (*LDBStore) Cleanup

func (s *LDBStore) Cleanup(f func(*chunk) bool)

cleanup循环访问数据库,并在块通过“f”条件时删除块。

func (*LDBStore) Close

func (s *LDBStore) Close()

func (*LDBStore) Delete

func (s *LDBStore) Delete(addr Address) error

删除是删除块并更新索引。 线程安全

func (*LDBStore) Export

func (s *LDBStore) Export(out io.Writer) (int64, error)

export将存储区中的所有块写入tar存档,并返回 写入的块数。

func (*LDBStore) Get

func (s *LDBStore) Get(_ context.Context, addr Address) (chunk Chunk, err error)

get从数据库中检索与提供的键匹配的块。 如果块条目不存在,则返回错误 更新访问计数并且是线程安全的

func (*LDBStore) GetSchema

func (s *LDBStore) GetSchema() (string, error)

GetSchema正在返回从LevelDB读取的数据存储的当前命名架构。

func (*LDBStore) Import

func (s *LDBStore) Import(in io.Reader) (int64, error)

块读取。

func (*LDBStore) MarkAccessed

func (s *LDBStore) MarkAccessed(addr Address)

markaccessed将访问计数器增加为块的最佳工作,因此 块不会被垃圾收集。

func (*LDBStore) Put

func (s *LDBStore) Put(ctx context.Context, chunk Chunk) error

Put向数据库添加一个块,添加索引并增加全局计数器。 如果它已经存在,它只增加现有条目的访问计数。 线程安全

func (*LDBStore) PutSchema

func (s *LDBStore) PutSchema(schema string) error

PutSchema正在将命名架构保存到LevelDB数据存储

func (*LDBStore) SyncIterator

func (s *LDBStore) SyncIterator(since uint64, until uint64, po uint8, f func(Address, uint64) bool) error

synciterator(start、stop、po、f)从开始到停止对bin po的每个哈希调用f

type LDBStoreParams

type LDBStoreParams struct {
	*StoreParams
	Path string
	Po   func(Address) uint8
}

func NewLDBStoreParams

func NewLDBStoreParams(storeparams *StoreParams, path string) *LDBStoreParams

newldbstoreparams用指定的值构造ldbstoreparams。

type LazyChunkReader

type LazyChunkReader struct {
	// contains filtered or unexported fields
}

Lazychunkreader实现LazySectionReader

func TreeJoin

func TreeJoin(ctx context.Context, addr Address, getter Getter, depth int) *LazyChunkReader

func (*LazyChunkReader) Context

func (r *LazyChunkReader) Context() context.Context

func (*LazyChunkReader) Read

func (r *LazyChunkReader) Read(b []byte) (read int, err error)

read保留一个光标,因此不能同时调用,请参阅readat

func (*LazyChunkReader) ReadAt

func (r *LazyChunkReader) ReadAt(b []byte, off int64) (read int, err error)

读在可以被称为无数次 允许并发读取 首先需要在Lazychunkreader上同步调用size()。

func (*LazyChunkReader) Seek

func (r *LazyChunkReader) Seek(offset int64, whence int) (int64, error)

func (*LazyChunkReader) Size

func (r *LazyChunkReader) Size(ctx context.Context, quitC chan bool) (n int64, err error)

大小将在LazySectionReader上调用

type LazySectionReader

type LazySectionReader interface {
	Context() context.Context
	Size(context.Context, chan bool) (int64, error)
	io.Seeker
	io.Reader
	io.ReaderAt
}

大小、查找、读取、读取

type LazyTestSectionReader

type LazyTestSectionReader struct {
	*io.SectionReader
}

func (*LazyTestSectionReader) Context

func (r *LazyTestSectionReader) Context() context.Context

func (*LazyTestSectionReader) Size

type LocalStore

type LocalStore struct {
	Validators []ChunkValidator

	DbStore *LDBStore
	// contains filtered or unexported fields
}

localstore是InMemory数据库与磁盘持久化数据库的组合 使用任意2个chunkstore实现带有回退(缓存)逻辑的get/put

func NewLocalStore

func NewLocalStore(params *LocalStoreParams, mockStore *mock.NodeStore) (*LocalStore, error)

此构造函数使用memstore和dbstore作为组件

func NewTestLocalStoreForAddr

func NewTestLocalStoreForAddr(params *LocalStoreParams) (*LocalStore, error)

func (*LocalStore) BinIndex

func (ls *LocalStore) BinIndex(po uint8) uint64

func (*LocalStore) Close

func (ls *LocalStore) Close()

关闭本地存储

func (*LocalStore) FetchFunc

func (ls *LocalStore) FetchFunc(ctx context.Context, addr Address) func(context.Context) error

func (*LocalStore) Get

func (ls *LocalStore) Get(ctx context.Context, addr Address) (chunk Chunk, err error)

get(chunk*chunk)在本地商店中查找一个chunk 在获取块之前,此方法正在阻塞 因此,如果 chunkstore是远程的,可以有很长的延迟

func (*LocalStore) Iterator

func (ls *LocalStore) Iterator(from uint64, to uint64, po uint8, f func(Address, uint64) bool) error

func (*LocalStore) Migrate

func (ls *LocalStore) Migrate() error

迁移检查数据存储架构与运行时架构并运行 迁移如果不匹配

func (*LocalStore) Put

func (ls *LocalStore) Put(ctx context.Context, chunk Chunk) error

Put负责验证和存储块 通过使用配置的chunkvalidator、memstore和ldbstore。 如果区块无效,则其getErrored函数将 返回errchunkinvalid。 此方法将检查块是否已在memstore中 如果是的话,它会退回的。如果出现错误 memstore.get,将通过调用getErrored返回 在块上。 此方法负责关闭chunk.reqc通道 当块存储在memstore中时。 在ldbstore.put之后,确保memstore 包含具有相同数据但没有reqc通道的块。

type LocalStoreParams

type LocalStoreParams struct {
	*StoreParams
	ChunkDbPath string
	Validators  []ChunkValidator `toml:"-"`
}

func NewDefaultLocalStoreParams

func NewDefaultLocalStoreParams() *LocalStoreParams

func (*LocalStoreParams) Init

func (p *LocalStoreParams) Init(path string)

这只能在所有配置选项(文件、命令行、env vars)之后最终设置。 已经过评估

type MemStore

type MemStore struct {
	// contains filtered or unexported fields
}

func NewMemStore

func NewMemStore(params *StoreParams, _ *LDBStore) (m *MemStore)

newmemstore正在实例化memstore缓存,以保留所有经常请求的缓存 “cache”lru缓存中的块。

func (*MemStore) Close

func (s *MemStore) Close()

func (*MemStore) Get

func (m *MemStore) Get(_ context.Context, addr Address) (Chunk, error)

func (*MemStore) Put

func (m *MemStore) Put(_ context.Context, c Chunk) error

type NetFetcher

type NetFetcher interface {
	Request(ctx context.Context, hopCount uint8)
	Offer(ctx context.Context, source *enode.ID)
}

type NetStore

type NetStore struct {
	NewNetFetcherFunc NewNetFetcherFunc
	// contains filtered or unexported fields
}

NetStore是本地存储的扩展 它实现chunkstore接口 根据请求,它使用获取器启动远程云检索 取数器对块是唯一的,并存储在取数器的LRU内存缓存中。 fetchfuncFactory是为特定块地址创建提取函数的工厂对象

func NewNetStore

func NewNetStore(store SyncChunkStore, nnf NewNetFetcherFunc) (*NetStore, error)

NewNetStore使用给定的本地存储创建新的NetStore对象。newfetchfunc是一个 可以为特定块地址创建提取函数的构造函数函数。

func (*NetStore) BinIndex

func (n *NetStore) BinIndex(po uint8) uint64

func (*NetStore) Close

func (n *NetStore) Close()

关闭区块存储

func (*NetStore) FetchFunc

func (n *NetStore) FetchFunc(ctx context.Context, ref Address) func(context.Context) error

如果存储包含给定地址,则fetchfunc返回nil。否则返回一个等待函数, 在块可用或上下文完成后返回

func (*NetStore) Get

func (n *NetStore) Get(rctx context.Context, ref Address) (Chunk, error)

get同步从netstore dpa中检索区块。 它调用netstore.get,如果块不在本地存储中 它调用带有请求的fetch,该请求将一直阻塞到块 到达或上下文完成

func (*NetStore) Iterator

func (n *NetStore) Iterator(from uint64, to uint64, po uint8, f func(Address, uint64) bool) error

func (*NetStore) Put

func (n *NetStore) Put(ctx context.Context, ch Chunk) error

将块存储在localstore中,并使用存储在 取数器缓存

func (*NetStore) RequestsCacheLen

func (n *NetStore) RequestsCacheLen() int

requestscachelen返回当前存储在缓存中的传出请求数

type NewNetFetcherFunc

type NewNetFetcherFunc func(ctx context.Context, addr Address, peers *sync.Map) NetFetcher

type Putter

type Putter interface {
	Put(context.Context, ChunkData) (Reference, error)
	//refsize返回此推杆创建的参考长度
	RefSize() int64
	//CLOSE是指在这个推杆上不再放置数据块。
	Close()
	//如果所有数据都已存储并调用了close(),则wait返回。
	Wait(context.Context) error
}

推杆负责存储数据并为其创建参考。

type PyramidChunker

type PyramidChunker struct {
	// contains filtered or unexported fields
}

func NewPyramidSplitter

func NewPyramidSplitter(params *PyramidSplitterParams) (pc *PyramidChunker)

func (*PyramidChunker) Append

func (pc *PyramidChunker) Append(ctx context.Context) (k Address, wait func(context.Context) error, err error)

func (*PyramidChunker) Join

func (pc *PyramidChunker) Join(addr Address, getter Getter, depth int) LazySectionReader

func (*PyramidChunker) Split

func (pc *PyramidChunker) Split(ctx context.Context) (k Address, wait func(context.Context) error, err error)

type PyramidSplitterParams

type PyramidSplitterParams struct {
	SplitterParams
	// contains filtered or unexported fields
}

func NewPyramidSplitterParams

func NewPyramidSplitterParams(addr Address, reader io.Reader, putter Putter, getter Getter, chunkSize int64) *PyramidSplitterParams

type Reference

type Reference []byte

type SplitterParams

type SplitterParams struct {
	ChunkerParams
	// contains filtered or unexported fields
}

type StoreParams

type StoreParams struct {
	Hash          SwarmHasher `toml:"-"`
	DbCapacity    uint64
	CacheCapacity uint
	BaseKey       []byte
}

func NewDefaultStoreParams

func NewDefaultStoreParams() *StoreParams

func NewStoreParams

func NewStoreParams(ldbCap uint64, cacheCap uint, hash SwarmHasher, basekey []byte) *StoreParams

type SwarmHash

type SwarmHash interface {
	hash.Hash
	ResetWithLength([]byte)
}

type SwarmHasher

type SwarmHasher func() SwarmHash

func MakeHashFunc

func MakeHashFunc(hash string) SwarmHasher

type SyncChunkStore

type SyncChunkStore interface {
	ChunkStore
	BinIndex(po uint8) uint64
	Iterator(from uint64, to uint64, po uint8, f func(Address, uint64) bool) error
	FetchFunc(ctx context.Context, ref Address) func(context.Context) error
}

SyncChunkStore是支持同步的ChunkStore

type TreeChunker

type TreeChunker struct {
	// contains filtered or unexported fields
}

func NewTreeJoiner

func NewTreeJoiner(params *JoinerParams) *TreeChunker

func NewTreeSplitter

func NewTreeSplitter(params *TreeSplitterParams) *TreeChunker

func (*TreeChunker) Join

func (tc *TreeChunker) Join(ctx context.Context) *LazyChunkReader

func (*TreeChunker) Split

func (tc *TreeChunker) Split(ctx context.Context) (k Address, wait func(context.Context) error, err error)

type TreeEntry

type TreeEntry struct {
	// contains filtered or unexported fields
}

创建树节点的条目

func NewTreeEntry

func NewTreeEntry(pyramid *PyramidChunker) *TreeEntry

type TreeSplitterParams

type TreeSplitterParams struct {
	SplitterParams
	// contains filtered or unexported fields
}

Directories

Path Synopsis
处理程序是源的API 它支持创建、更新、同步和检索源更新及其数据
处理程序是源的API 它支持创建、更新、同步和检索源更新及其数据
包模拟定义了不同实现使用的类型 模拟仓库。
包模拟定义了不同实现使用的类型 模拟仓库。
db
包DB实现了一个模拟存储,它将所有块数据保存在LevelDB数据库中。
包DB实现了一个模拟存储,它将所有块数据保存在LevelDB数据库中。
mem
package mem实现了一个模拟存储,将所有块数据保存在内存中。
package mem实现了一个模拟存储,将所有块数据保存在内存中。
rpc
package rpc实现一个连接到集中模拟存储的rpc客户机。
package rpc实现一个连接到集中模拟存储的rpc客户机。
test
包测试提供用于测试的函数 GlobalStrer实施。
包测试提供用于测试的函数 GlobalStrer实施。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL