mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/storage: import swarm/chunk with original package name everywhere
This commit is contained in:
parent
62d79bfbf0
commit
d6916a7bec
10 changed files with 57 additions and 60 deletions
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
"github.com/ethereum/go-ethereum/swarm/log"
|
"github.com/ethereum/go-ethereum/swarm/log"
|
||||||
"github.com/ethereum/go-ethereum/swarm/spancontext"
|
"github.com/ethereum/go-ethereum/swarm/spancontext"
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
|
|
@ -127,7 +127,7 @@ type TreeChunker struct {
|
||||||
func TreeJoin(ctx context.Context, addr Address, getter Getter, depth int) *LazyChunkReader {
|
func TreeJoin(ctx context.Context, addr Address, getter Getter, depth int) *LazyChunkReader {
|
||||||
jp := &JoinerParams{
|
jp := &JoinerParams{
|
||||||
ChunkerParams: ChunkerParams{
|
ChunkerParams: ChunkerParams{
|
||||||
chunkSize: ch.DefaultSize,
|
chunkSize: chunk.DefaultSize,
|
||||||
hashSize: int64(len(addr)),
|
hashSize: int64(len(addr)),
|
||||||
},
|
},
|
||||||
addr: addr,
|
addr: addr,
|
||||||
|
|
@ -147,7 +147,7 @@ func TreeSplit(ctx context.Context, data io.Reader, size int64, putter Putter) (
|
||||||
tsp := &TreeSplitterParams{
|
tsp := &TreeSplitterParams{
|
||||||
SplitterParams: SplitterParams{
|
SplitterParams: SplitterParams{
|
||||||
ChunkerParams: ChunkerParams{
|
ChunkerParams: ChunkerParams{
|
||||||
chunkSize: ch.DefaultSize,
|
chunkSize: chunk.DefaultSize,
|
||||||
hashSize: putter.RefSize(),
|
hashSize: putter.RefSize(),
|
||||||
},
|
},
|
||||||
reader: data,
|
reader: data,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ func mput(store ChunkStore, n int, f func(i int64) Chunk) (hs []Chunk, err error
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
for i := int64(0); i < int64(n); i++ {
|
for i := int64(0); i < int64(n); i++ {
|
||||||
chunk := f(ch.DefaultSize)
|
chunk := f(chunk.DefaultSize)
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case errc <- store.Put(ctx, chunk):
|
case errc <- store.Put(ctx, chunk):
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import "github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrInit = iota
|
ErrInit = iota
|
||||||
|
|
@ -33,6 +31,6 @@ const (
|
||||||
|
|
||||||
// Errors are the same as the ones in chunk package for backward compatibility.
|
// Errors are the same as the ones in chunk package for backward compatibility.
|
||||||
var (
|
var (
|
||||||
ErrChunkNotFound = ch.ErrChunkNotFound
|
ErrChunkNotFound = chunk.ErrChunkNotFound
|
||||||
ErrChunkInvalid = ch.ErrChunkNotFound
|
ErrChunkInvalid = chunk.ErrChunkNotFound
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage/encryption"
|
"github.com/ethereum/go-ethereum/swarm/storage/encryption"
|
||||||
"golang.org/x/crypto/sha3"
|
"golang.org/x/crypto/sha3"
|
||||||
)
|
)
|
||||||
|
|
@ -189,9 +189,9 @@ func (h *hasherStore) decryptChunkData(chunkData ChunkData, encryptionKey encryp
|
||||||
|
|
||||||
// removing extra bytes which were just added for padding
|
// removing extra bytes which were just added for padding
|
||||||
length := ChunkData(decryptedSpan).Size()
|
length := ChunkData(decryptedSpan).Size()
|
||||||
for length > ch.DefaultSize {
|
for length > chunk.DefaultSize {
|
||||||
length = length + (ch.DefaultSize - 1)
|
length = length + (chunk.DefaultSize - 1)
|
||||||
length = length / ch.DefaultSize
|
length = length / chunk.DefaultSize
|
||||||
length *= uint64(h.refSize)
|
length *= uint64(h.refSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,11 +232,11 @@ func (h *hasherStore) decrypt(chunkData ChunkData, key encryption.Key) ([]byte,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hasherStore) newSpanEncryption(key encryption.Key) encryption.Encryption {
|
func (h *hasherStore) newSpanEncryption(key encryption.Key) encryption.Encryption {
|
||||||
return encryption.New(key, 0, uint32(ch.DefaultSize/h.refSize), sha3.NewLegacyKeccak256)
|
return encryption.New(key, 0, uint32(chunk.DefaultSize/h.refSize), sha3.NewLegacyKeccak256)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hasherStore) newDataEncryption(key encryption.Key) encryption.Encryption {
|
func (h *hasherStore) newDataEncryption(key encryption.Key) encryption.Encryption {
|
||||||
return encryption.New(key, int(ch.DefaultSize), 0, sha3.NewLegacyKeccak256)
|
return encryption.New(key, int(chunk.DefaultSize), 0, sha3.NewLegacyKeccak256)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hasherStore) storeChunk(ctx context.Context, chunk Chunk) {
|
func (h *hasherStore) storeChunk(ctx context.Context, chunk Chunk) {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
"github.com/ethereum/go-ethereum/swarm/log"
|
"github.com/ethereum/go-ethereum/swarm/log"
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
|
"github.com/ethereum/go-ethereum/swarm/storage/mock/mem"
|
||||||
ldberrors "github.com/syndtr/goleveldb/leveldb/errors"
|
ldberrors "github.com/syndtr/goleveldb/leveldb/errors"
|
||||||
|
|
@ -103,7 +103,7 @@ func TestMarkAccessed(t *testing.T) {
|
||||||
t.Fatalf("init dbStore failed: %v", err)
|
t.Fatalf("init dbStore failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h := GenerateRandomChunk(ch.DefaultSize)
|
h := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
db.Put(context.Background(), h)
|
db.Put(context.Background(), h)
|
||||||
|
|
||||||
|
|
@ -201,7 +201,7 @@ func testIterator(t *testing.T, mock bool) {
|
||||||
t.Fatalf("init dbStore failed: %v", err)
|
t.Fatalf("init dbStore failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
chunks := GenerateRandomChunks(ch.DefaultSize, chunkcount)
|
chunks := GenerateRandomChunks(chunk.DefaultSize, chunkcount)
|
||||||
|
|
||||||
for i = 0; i < len(chunks); i++ {
|
for i = 0; i < len(chunks); i++ {
|
||||||
chunkkeys[i] = chunks[i].Address()
|
chunkkeys[i] = chunks[i].Address()
|
||||||
|
|
@ -468,7 +468,7 @@ func testLDBStoreRemoveThenCollectGarbage(t *testing.T) {
|
||||||
// put capacity count number of chunks
|
// put capacity count number of chunks
|
||||||
chunks := make([]Chunk, n)
|
chunks := make([]Chunk, n)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
c := GenerateRandomChunk(ch.DefaultSize)
|
c := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
chunks[i] = c
|
chunks[i] = c
|
||||||
log.Trace("generate random chunk", "idx", i, "chunk", c)
|
log.Trace("generate random chunk", "idx", i, "chunk", c)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/shed"
|
"github.com/ethereum/go-ethereum/swarm/shed"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
)
|
)
|
||||||
|
|
@ -243,7 +242,7 @@ func init() {
|
||||||
// random data, and their execution time can be decreased
|
// random data, and their execution time can be decreased
|
||||||
// using this function.
|
// using this function.
|
||||||
func generateTestRandomChunk() chunk.Chunk {
|
func generateTestRandomChunk() chunk.Chunk {
|
||||||
data := make([]byte, ch.DefaultSize)
|
data := make([]byte, chunk.DefaultSize)
|
||||||
rand.Read(data)
|
rand.Read(data)
|
||||||
key := make([]byte, 32)
|
key := make([]byte, 32)
|
||||||
rand.Read(key)
|
rand.Read(key)
|
||||||
|
|
@ -261,16 +260,16 @@ func TestGenerateTestRandomChunk(t *testing.T) {
|
||||||
t.Errorf("first chunk address length %v, want %v", addrLen, 32)
|
t.Errorf("first chunk address length %v, want %v", addrLen, 32)
|
||||||
}
|
}
|
||||||
dataLen := len(c1.Data())
|
dataLen := len(c1.Data())
|
||||||
if dataLen != ch.DefaultSize {
|
if dataLen != chunk.DefaultSize {
|
||||||
t.Errorf("first chunk data length %v, want %v", dataLen, ch.DefaultSize)
|
t.Errorf("first chunk data length %v, want %v", dataLen, chunk.DefaultSize)
|
||||||
}
|
}
|
||||||
addrLen = len(c2.Address())
|
addrLen = len(c2.Address())
|
||||||
if addrLen != 32 {
|
if addrLen != 32 {
|
||||||
t.Errorf("second chunk address length %v, want %v", addrLen, 32)
|
t.Errorf("second chunk address length %v, want %v", addrLen, 32)
|
||||||
}
|
}
|
||||||
dataLen = len(c2.Data())
|
dataLen = len(c2.Data())
|
||||||
if dataLen != ch.DefaultSize {
|
if dataLen != chunk.DefaultSize {
|
||||||
t.Errorf("second chunk data length %v, want %v", dataLen, ch.DefaultSize)
|
t.Errorf("second chunk data length %v, want %v", dataLen, chunk.DefaultSize)
|
||||||
}
|
}
|
||||||
if bytes.Equal(c1.Address(), c2.Address()) {
|
if bytes.Equal(c1.Address(), c2.Address()) {
|
||||||
t.Error("fake chunks addresses do not differ")
|
t.Error("fake chunks addresses do not differ")
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -65,7 +65,7 @@ func TestValidator(t *testing.T) {
|
||||||
// add content address validator and check puts
|
// add content address validator and check puts
|
||||||
// bad should fail, good should pass
|
// bad should fail, good should pass
|
||||||
store.Validators = append(store.Validators, NewContentAddressValidator(hashfunc))
|
store.Validators = append(store.Validators, NewContentAddressValidator(hashfunc))
|
||||||
chunks = GenerateRandomChunks(ch.DefaultSize, 2)
|
chunks = GenerateRandomChunks(chunk.DefaultSize, 2)
|
||||||
goodChunk = chunks[0]
|
goodChunk = chunks[0]
|
||||||
badChunk = chunks[1]
|
badChunk = chunks[1]
|
||||||
copy(badChunk.Data(), goodChunk.Data())
|
copy(badChunk.Data(), goodChunk.Data())
|
||||||
|
|
@ -83,7 +83,7 @@ func TestValidator(t *testing.T) {
|
||||||
var negV boolTestValidator
|
var negV boolTestValidator
|
||||||
store.Validators = append(store.Validators, negV)
|
store.Validators = append(store.Validators, negV)
|
||||||
|
|
||||||
chunks = GenerateRandomChunks(ch.DefaultSize, 2)
|
chunks = GenerateRandomChunks(chunk.DefaultSize, 2)
|
||||||
goodChunk = chunks[0]
|
goodChunk = chunks[0]
|
||||||
badChunk = chunks[1]
|
badChunk = chunks[1]
|
||||||
copy(badChunk.Data(), goodChunk.Data())
|
copy(badChunk.Data(), goodChunk.Data())
|
||||||
|
|
@ -101,7 +101,7 @@ func TestValidator(t *testing.T) {
|
||||||
var posV boolTestValidator = true
|
var posV boolTestValidator = true
|
||||||
store.Validators = append(store.Validators, posV)
|
store.Validators = append(store.Validators, posV)
|
||||||
|
|
||||||
chunks = GenerateRandomChunks(ch.DefaultSize, 2)
|
chunks = GenerateRandomChunks(chunk.DefaultSize, 2)
|
||||||
goodChunk = chunks[0]
|
goodChunk = chunks[0]
|
||||||
badChunk = chunks[1]
|
badChunk = chunks[1]
|
||||||
copy(badChunk.Data(), goodChunk.Data())
|
copy(badChunk.Data(), goodChunk.Data())
|
||||||
|
|
@ -138,7 +138,7 @@ func putChunks(store *LocalStore, chunks ...Chunk) []error {
|
||||||
|
|
||||||
func put(store *LocalStore, n int, f func(i int64) Chunk) (hs []Address, errs []error) {
|
func put(store *LocalStore, n int, f func(i int64) Chunk) (hs []Address, errs []error) {
|
||||||
for i := int64(0); i < int64(n); i++ {
|
for i := int64(0); i < int64(n); i++ {
|
||||||
chunk := f(ch.DefaultSize)
|
chunk := f(chunk.DefaultSize)
|
||||||
err := store.Put(context.TODO(), chunk)
|
err := store.Put(context.TODO(), chunk)
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
hs = append(hs, chunk.Address())
|
hs = append(hs, chunk.Address())
|
||||||
|
|
@ -158,7 +158,7 @@ func TestGetFrequentlyAccessedChunkWontGetGarbageCollected(t *testing.T) {
|
||||||
|
|
||||||
var chunks []Chunk
|
var chunks []Chunk
|
||||||
for i := 0; i < ldbCap; i++ {
|
for i := 0; i < ldbCap; i++ {
|
||||||
chunks = append(chunks, GenerateRandomChunk(ch.DefaultSize))
|
chunks = append(chunks, GenerateRandomChunk(chunk.DefaultSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
mostAccessed := chunks[0].Address()
|
mostAccessed := chunks[0].Address()
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sourcePeerID = enode.HexID("99d8594b52298567d2ca3f4c441a5ba0140ee9245e26460d01102a52773c73b9")
|
var sourcePeerID = enode.HexID("99d8594b52298567d2ca3f4c441a5ba0140ee9245e26460d01102a52773c73b9")
|
||||||
|
|
@ -114,7 +114,7 @@ func mustNewNetStoreWithFetcher(t *testing.T) (*NetStore, *mockNetFetcher) {
|
||||||
func TestNetStoreGetAndPut(t *testing.T) {
|
func TestNetStoreGetAndPut(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -174,7 +174,7 @@ func TestNetStoreGetAndPut(t *testing.T) {
|
||||||
func TestNetStoreGetAfterPut(t *testing.T) {
|
func TestNetStoreGetAfterPut(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -209,7 +209,7 @@ func TestNetStoreGetAfterPut(t *testing.T) {
|
||||||
func TestNetStoreGetTimeout(t *testing.T) {
|
func TestNetStoreGetTimeout(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -261,7 +261,7 @@ func TestNetStoreGetTimeout(t *testing.T) {
|
||||||
func TestNetStoreGetCancel(t *testing.T) {
|
func TestNetStoreGetCancel(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||||
|
|
||||||
|
|
@ -313,7 +313,7 @@ func TestNetStoreGetCancel(t *testing.T) {
|
||||||
func TestNetStoreMultipleGetAndPut(t *testing.T) {
|
func TestNetStoreMultipleGetAndPut(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -387,7 +387,7 @@ func TestNetStoreMultipleGetAndPut(t *testing.T) {
|
||||||
func TestNetStoreFetchFuncTimeout(t *testing.T) {
|
func TestNetStoreFetchFuncTimeout(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -426,7 +426,7 @@ func TestNetStoreFetchFuncTimeout(t *testing.T) {
|
||||||
func TestNetStoreFetchFuncAfterPut(t *testing.T) {
|
func TestNetStoreFetchFuncAfterPut(t *testing.T) {
|
||||||
netStore := mustNewNetStore(t)
|
netStore := mustNewNetStore(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -453,7 +453,7 @@ func TestNetStoreFetchFuncAfterPut(t *testing.T) {
|
||||||
func TestNetStoreGetCallsRequest(t *testing.T) {
|
func TestNetStoreGetCallsRequest(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), "hopcount", uint8(5))
|
ctx := context.WithValue(context.Background(), "hopcount", uint8(5))
|
||||||
ctx, cancel := context.WithTimeout(ctx, 200*time.Millisecond)
|
ctx, cancel := context.WithTimeout(ctx, 200*time.Millisecond)
|
||||||
|
|
@ -481,7 +481,7 @@ func TestNetStoreGetCallsRequest(t *testing.T) {
|
||||||
func TestNetStoreGetCallsOffer(t *testing.T) {
|
func TestNetStoreGetCallsOffer(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
// If a source peer is added to the context, NetStore will handle it as an offer
|
// If a source peer is added to the context, NetStore will handle it as an offer
|
||||||
ctx := context.WithValue(context.Background(), "source", sourcePeerID.String())
|
ctx := context.WithValue(context.Background(), "source", sourcePeerID.String())
|
||||||
|
|
@ -567,7 +567,7 @@ func TestNetStoreFetcherCountPeers(t *testing.T) {
|
||||||
func TestNetStoreFetchFuncCalledMultipleTimes(t *testing.T) {
|
func TestNetStoreFetchFuncCalledMultipleTimes(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -632,7 +632,7 @@ func TestNetStoreFetchFuncCalledMultipleTimes(t *testing.T) {
|
||||||
func TestNetStoreFetcherLifeCycleWithTimeout(t *testing.T) {
|
func TestNetStoreFetcherLifeCycleWithTimeout(t *testing.T) {
|
||||||
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
netStore, fetcher := mustNewNetStoreWithFetcher(t)
|
||||||
|
|
||||||
chunk := GenerateRandomChunk(ch.DefaultSize)
|
chunk := GenerateRandomChunk(chunk.DefaultSize)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
"github.com/ethereum/go-ethereum/swarm/log"
|
"github.com/ethereum/go-ethereum/swarm/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -97,11 +97,11 @@ func NewPyramidSplitterParams(addr Address, reader io.Reader, putter Putter, get
|
||||||
New chunks to store are store using the putter which the caller provides.
|
New chunks to store are store using the putter which the caller provides.
|
||||||
*/
|
*/
|
||||||
func PyramidSplit(ctx context.Context, reader io.Reader, putter Putter, getter Getter) (Address, func(context.Context) error, error) {
|
func PyramidSplit(ctx context.Context, reader io.Reader, putter Putter, getter Getter) (Address, func(context.Context) error, error) {
|
||||||
return NewPyramidSplitter(NewPyramidSplitterParams(nil, reader, putter, getter, ch.DefaultSize)).Split(ctx)
|
return NewPyramidSplitter(NewPyramidSplitterParams(nil, reader, putter, getter, chunk.DefaultSize)).Split(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PyramidAppend(ctx context.Context, addr Address, reader io.Reader, putter Putter, getter Getter) (Address, func(context.Context) error, error) {
|
func PyramidAppend(ctx context.Context, addr Address, reader io.Reader, putter Putter, getter Getter) (Address, func(context.Context) error, error) {
|
||||||
return NewPyramidSplitter(NewPyramidSplitterParams(addr, reader, putter, getter, ch.DefaultSize)).Append(ctx)
|
return NewPyramidSplitter(NewPyramidSplitterParams(addr, reader, putter, getter, chunk.DefaultSize)).Append(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry to create a tree node
|
// Entry to create a tree node
|
||||||
|
|
|
||||||
|
|
@ -25,26 +25,26 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/bmt"
|
"github.com/ethereum/go-ethereum/swarm/bmt"
|
||||||
ch "github.com/ethereum/go-ethereum/swarm/chunk"
|
"github.com/ethereum/go-ethereum/swarm/chunk"
|
||||||
"golang.org/x/crypto/sha3"
|
"golang.org/x/crypto/sha3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MaxPO is the same as chunk.MaxPO for backward compatibility.
|
// MaxPO is the same as chunk.MaxPO for backward compatibility.
|
||||||
const MaxPO = ch.MaxPO
|
const MaxPO = chunk.MaxPO
|
||||||
|
|
||||||
// AddressLength is the same as chunk.AddressLength for backward compatibility.
|
// AddressLength is the same as chunk.AddressLength for backward compatibility.
|
||||||
const AddressLength = ch.AddressLength
|
const AddressLength = chunk.AddressLength
|
||||||
|
|
||||||
type SwarmHasher func() SwarmHash
|
type SwarmHasher func() SwarmHash
|
||||||
|
|
||||||
// Address is an alias for chunk.Address for backward compatibility.
|
// Address is an alias for chunk.Address for backward compatibility.
|
||||||
type Address = ch.Address
|
type Address = chunk.Address
|
||||||
|
|
||||||
// Proximity is the same as chunk.Proximity for backward compatibility.
|
// Proximity is the same as chunk.Proximity for backward compatibility.
|
||||||
var Proximity = ch.Proximity
|
var Proximity = chunk.Proximity
|
||||||
|
|
||||||
// ZeroAddr is the same as chunk.ZeroAddr for backward compatibility.
|
// ZeroAddr is the same as chunk.ZeroAddr for backward compatibility.
|
||||||
var ZeroAddr = ch.ZeroAddr
|
var ZeroAddr = chunk.ZeroAddr
|
||||||
|
|
||||||
func MakeHashFunc(hash string) SwarmHasher {
|
func MakeHashFunc(hash string) SwarmHasher {
|
||||||
switch hash {
|
switch hash {
|
||||||
|
|
@ -56,7 +56,7 @@ func MakeHashFunc(hash string) SwarmHasher {
|
||||||
return func() SwarmHash {
|
return func() SwarmHash {
|
||||||
hasher := sha3.NewLegacyKeccak256
|
hasher := sha3.NewLegacyKeccak256
|
||||||
hasherSize := hasher().Size()
|
hasherSize := hasher().Size()
|
||||||
segmentCount := ch.DefaultSize / hasherSize
|
segmentCount := chunk.DefaultSize / hasherSize
|
||||||
pool := bmt.NewTreePool(hasher, segmentCount, bmt.PoolSize)
|
pool := bmt.NewTreePool(hasher, segmentCount, bmt.PoolSize)
|
||||||
return bmt.New(pool)
|
return bmt.New(pool)
|
||||||
}
|
}
|
||||||
|
|
@ -83,10 +83,10 @@ func (c AddressCollection) Swap(i, j int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chunk is an alias for chunk.Chunk for backward compatibility.
|
// Chunk is an alias for chunk.Chunk for backward compatibility.
|
||||||
type Chunk = ch.Chunk
|
type Chunk = chunk.Chunk
|
||||||
|
|
||||||
// NewChunk is the same as chunk.NewChunk for backward compatibility.
|
// NewChunk is the same as chunk.NewChunk for backward compatibility.
|
||||||
var NewChunk = ch.NewChunk
|
var NewChunk = chunk.NewChunk
|
||||||
|
|
||||||
func GenerateRandomChunk(dataSize int64) Chunk {
|
func GenerateRandomChunk(dataSize int64) Chunk {
|
||||||
hasher := MakeHashFunc(DefaultHash)()
|
hasher := MakeHashFunc(DefaultHash)()
|
||||||
|
|
@ -196,9 +196,9 @@ func NewContentAddressValidator(hasher SwarmHasher) *ContentAddressValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate that the given key is a valid content address for the given data
|
// Validate that the given key is a valid content address for the given data
|
||||||
func (v *ContentAddressValidator) Validate(chunk Chunk) bool {
|
func (v *ContentAddressValidator) Validate(ch Chunk) bool {
|
||||||
data := chunk.Data()
|
data := ch.Data()
|
||||||
if l := len(data); l < 9 || l > ch.DefaultSize+8 {
|
if l := len(data); l < 9 || l > chunk.DefaultSize+8 {
|
||||||
// log.Error("invalid chunk size", "chunk", addr.Hex(), "size", l)
|
// log.Error("invalid chunk size", "chunk", addr.Hex(), "size", l)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -208,7 +208,7 @@ func (v *ContentAddressValidator) Validate(chunk Chunk) bool {
|
||||||
hasher.Write(data[8:])
|
hasher.Write(data[8:])
|
||||||
hash := hasher.Sum(nil)
|
hash := hasher.Sum(nil)
|
||||||
|
|
||||||
return bytes.Equal(hash, chunk.Address())
|
return bytes.Equal(hash, ch.Address())
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChunkStore interface {
|
type ChunkStore interface {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue