diff options
author | Janos Guljas <janos@resenje.org> | 2018-09-25 22:57:31 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2018-09-25 22:57:31 +0800 |
commit | 24349144b6c0642755569268bab56b9033743212 (patch) | |
tree | 9d9d2b6659fd8a56512dfc807aafe4b733165ae1 /swarm/storage | |
parent | 7d56602391e155e2ce9ba7c261300a1804ab9972 (diff) | |
parent | d3441ebb563439bac0837d70591f92e2c6080303 (diff) | |
download | dexon-24349144b6c0642755569268bab56b9033743212.tar dexon-24349144b6c0642755569268bab56b9033743212.tar.gz dexon-24349144b6c0642755569268bab56b9033743212.tar.bz2 dexon-24349144b6c0642755569268bab56b9033743212.tar.lz dexon-24349144b6c0642755569268bab56b9033743212.tar.xz dexon-24349144b6c0642755569268bab56b9033743212.tar.zst dexon-24349144b6c0642755569268bab56b9033743212.zip |
Merge branch 'master' into max-stream-peer-servers
Diffstat (limited to 'swarm/storage')
-rw-r--r-- | swarm/storage/mru/testutil.go | 5 | ||||
-rw-r--r-- | swarm/storage/netstore.go | 18 | ||||
-rw-r--r-- | swarm/storage/netstore_test.go | 11 |
3 files changed, 17 insertions, 17 deletions
diff --git a/swarm/storage/mru/testutil.go b/swarm/storage/mru/testutil.go index a30baaa1d..936132d40 100644 --- a/swarm/storage/mru/testutil.go +++ b/swarm/storage/mru/testutil.go @@ -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 { diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index de2d82d2b..a3a552232 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -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 @@ -52,6 +51,8 @@ type NetStore struct { closeC chan struct{} } +var fetcherTimeout = 2 * time.Minute // timeout to cancel the fetcher even if requests are coming in + // NewNetStore creates a new NetStore object using the given local store. newFetchFunc is a // constructor function that can create a fetch function for a specific chunk address. func NewNetStore(store SyncChunkStore, nnf NewNetFetcherFunc) (*NetStore, error) { @@ -168,7 +169,7 @@ func (n *NetStore) getOrCreateFetcher(ref Address) *fetcher { // no fetcher for the given address, we have to create a new one key := hex.EncodeToString(ref) // create the context during which fetching is kept alive - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), fetcherTimeout) // destroy is called when all requests finish destroy := func() { // remove fetcher from fetchers @@ -263,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) } diff --git a/swarm/storage/netstore_test.go b/swarm/storage/netstore_test.go index f08968f0e..b734c117b 100644 --- a/swarm/storage/netstore_test.go +++ b/swarm/storage/netstore_test.go @@ -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) } |