swarm/storage: port to p2p/enode

This commit is contained in:
Felix Lange 2018-09-13 15:39:30 +02:00
parent 7b009fa0c3
commit 6b32109e5e
3 changed files with 14 additions and 16 deletions

View file

@ -22,8 +22,7 @@ import (
"path/filepath"
"sync"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/swarm/storage"
)
@ -43,7 +42,7 @@ type mockNetFetcher struct{}
func (m *mockNetFetcher) Request(ctx context.Context) {
}
func (m *mockNetFetcher) Offer(ctx context.Context, source *discover.NodeID) {
func (m *mockNetFetcher) Offer(ctx context.Context, source *enode.ID) {
}
func newFakeNetFetcher(context.Context, storage.Address, *sync.Map) storage.NetFetcher {

View file

@ -24,9 +24,8 @@ import (
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/swarm/log"
lru "github.com/hashicorp/golang-lru"
)
@ -36,7 +35,7 @@ type (
type NetFetcher interface {
Request(ctx context.Context)
Offer(ctx context.Context, source *discover.NodeID)
Offer(ctx context.Context, source *enode.ID)
}
// NetStore is an extension of local storage
@ -265,10 +264,11 @@ func (f *fetcher) Fetch(rctx context.Context) (Chunk, error) {
// If there is a source in the context then it is an offer, otherwise a request
sourceIF := rctx.Value("source")
if sourceIF != nil {
var source *discover.NodeID
id := discover.MustHexID(sourceIF.(string))
source = &id
f.netFetcher.Offer(rctx, source)
var source enode.ID
if err := source.UnmarshalText([]byte(sourceIF.(string))); err != nil {
return nil, err
}
f.netFetcher.Offer(rctx, &source)
} else {
f.netFetcher.Request(rctx)
}

View file

@ -25,17 +25,16 @@ import (
"testing"
"time"
"github.com/ethereum/go-ethereum/p2p/discover"
ch "github.com/ethereum/go-ethereum/swarm/chunk"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/p2p/enode"
ch "github.com/ethereum/go-ethereum/swarm/chunk"
)
var sourcePeerID = discover.MustHexID("2dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439")
var sourcePeerID = enode.HexID("99d8594b52298567d2ca3f4c441a5ba0140ee9245e26460d01102a52773c73b9")
type mockNetFetcher struct {
peers *sync.Map
sources []*discover.NodeID
sources []*enode.ID
peersPerRequest [][]Address
requestCalled bool
offerCalled bool
@ -43,7 +42,7 @@ type mockNetFetcher struct {
ctx context.Context
}
func (m *mockNetFetcher) Offer(ctx context.Context, source *discover.NodeID) {
func (m *mockNetFetcher) Offer(ctx context.Context, source *enode.ID) {
m.offerCalled = true
m.sources = append(m.sources, source)
}