Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

[WIP] Push syncing pss #971

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions swarm/pss/pss.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ func (p *Pss) forward(msg *PssMsg) error {
return false // stop iterating
}
if sendFunc(p, sp, msg) {
log.Trace("forwarding", "self", label(p.BaseAddr()), "to", label(sp.Address()), "msg", msg.Payload.Hash().Hex()[:4])
sent++
if onlySendOnce {
return false
Expand Down
32 changes: 0 additions & 32 deletions swarm/storage/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,38 +237,6 @@ func benchmarkStoreGet(store ChunkStore, n int, chunksize int64, b *testing.B) {
}
}

// MapChunkStore is a very simple ChunkStore implementation to store chunks in a map in memory.
type MapChunkStore struct {
chunks map[string]Chunk
mu sync.RWMutex
}

func NewMapChunkStore() *MapChunkStore {
return &MapChunkStore{
chunks: make(map[string]Chunk),
}
}

func (m *MapChunkStore) Put(_ context.Context, ch Chunk) error {
m.mu.Lock()
defer m.mu.Unlock()
m.chunks[ch.Address().Hex()] = ch
return nil
}

func (m *MapChunkStore) Get(_ context.Context, ref Address) (Chunk, error) {
m.mu.RLock()
defer m.mu.RUnlock()
chunk := m.chunks[ref.Hex()]
if chunk == nil {
return nil, ErrChunkNotFound
}
return chunk, nil
}

func (m *MapChunkStore) Close() {
}

func chunkAddresses(chunks []Chunk) []Address {
addrs := make([]Address, len(chunks))
for i, ch := range chunks {
Expand Down
33 changes: 33 additions & 0 deletions swarm/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/binary"
"fmt"
"io"
"sync"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/swarm/bmt"
Expand Down Expand Up @@ -322,3 +323,35 @@ func (f *FakeChunkStore) Get(_ context.Context, ref Address) (Chunk, error) {
// Close doesn't store anything it is just here to implement ChunkStore
func (f *FakeChunkStore) Close() {
}

// MapChunkStore is a very simple ChunkStore implementation to store chunks in a map in memory.
type MapChunkStore struct {
chunks map[string]Chunk
mu sync.RWMutex
}

func NewMapChunkStore() *MapChunkStore {
return &MapChunkStore{
chunks: make(map[string]Chunk),
}
}

func (m *MapChunkStore) Put(_ context.Context, ch Chunk) error {
m.mu.Lock()
defer m.mu.Unlock()
m.chunks[ch.Address().Hex()] = ch
return nil
}

func (m *MapChunkStore) Get(_ context.Context, ref Address) (Chunk, error) {
m.mu.RLock()
defer m.mu.RUnlock()
chunk := m.chunks[ref.Hex()]
if chunk == nil {
return nil, ErrChunkNotFound
}
return chunk, nil
}

func (m *MapChunkStore) Close() {
}
Loading