mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
swarm/storage: port to p2p/enode
This commit is contained in:
parent
7b009fa0c3
commit
6b32109e5e
3 changed files with 14 additions and 16 deletions
|
|
@ -22,8 +22,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -43,7 +42,7 @@ type mockNetFetcher struct{}
|
||||||
|
|
||||||
func (m *mockNetFetcher) Request(ctx context.Context) {
|
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 {
|
func newFakeNetFetcher(context.Context, storage.Address, *sync.Map) storage.NetFetcher {
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,8 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/swarm/log"
|
"github.com/ethereum/go-ethereum/swarm/log"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -36,7 +35,7 @@ type (
|
||||||
|
|
||||||
type NetFetcher interface {
|
type NetFetcher interface {
|
||||||
Request(ctx context.Context)
|
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
|
// 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
|
// If there is a source in the context then it is an offer, otherwise a request
|
||||||
sourceIF := rctx.Value("source")
|
sourceIF := rctx.Value("source")
|
||||||
if sourceIF != nil {
|
if sourceIF != nil {
|
||||||
var source *discover.NodeID
|
var source enode.ID
|
||||||
id := discover.MustHexID(sourceIF.(string))
|
if err := source.UnmarshalText([]byte(sourceIF.(string))); err != nil {
|
||||||
source = &id
|
return nil, err
|
||||||
f.netFetcher.Offer(rctx, source)
|
}
|
||||||
|
f.netFetcher.Offer(rctx, &source)
|
||||||
} else {
|
} else {
|
||||||
f.netFetcher.Request(rctx)
|
f.netFetcher.Request(rctx)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,17 +25,16 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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/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 {
|
type mockNetFetcher struct {
|
||||||
peers *sync.Map
|
peers *sync.Map
|
||||||
sources []*discover.NodeID
|
sources []*enode.ID
|
||||||
peersPerRequest [][]Address
|
peersPerRequest [][]Address
|
||||||
requestCalled bool
|
requestCalled bool
|
||||||
offerCalled bool
|
offerCalled bool
|
||||||
|
|
@ -43,7 +42,7 @@ type mockNetFetcher struct {
|
||||||
ctx context.Context
|
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.offerCalled = true
|
||||||
m.sources = append(m.sources, source)
|
m.sources = append(m.sources, source)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue