From b4633037aeac7e412b869814b014e8285a261a78 Mon Sep 17 00:00:00 2001 From: nolash Date: Fri, 15 Nov 2019 11:51:05 +0100 Subject: [PATCH] Add unfiltered chunk retrieval API --- direct.go | 29 +++++++++++++++++++++++++++++ swarm.go | 11 +++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 direct.go diff --git a/direct.go b/direct.go new file mode 100644 index 0000000000..85fc21807d --- /dev/null +++ b/direct.go @@ -0,0 +1,29 @@ +package swarm + +import ( + "context" + + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethersphere/swarm/chunk" + "github.com/ethersphere/swarm/storage" +) + +type directAccessAPI struct { + chunkStore storage.ChunkStore +} + +func NewDirectAccessAPI(chunkStore storage.ChunkStore) *directAccessAPI { + return &directAccessAPI{ + chunkStore: chunkStore, + } +} + +func (d *directAccessAPI) GetByReference(addr storage.Address) (hexutil.Bytes, error) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + chunk, err := d.chunkStore.Get(ctx, chunk.ModeGetRequest, addr) + if err != nil { + return nil, err + } + return hexutil.Bytes(chunk.Data()), nil +} diff --git a/swarm.go b/swarm.go index 0f98387795..862710e4f2 100644 --- a/swarm.go +++ b/swarm.go @@ -559,14 +559,14 @@ func (s *Swarm) APIs() []rpc.API { // public APIs { Namespace: "bzz", - Version: "4.0", + Version: "4.1", Service: &Info{s.config}, Public: true, }, // admin APIs { Namespace: "bzz", - Version: "4.0", + Version: "4.1", Service: s.inspector, Public: false, }, @@ -582,6 +582,13 @@ func (s *Swarm) APIs() []rpc.API { Service: protocols.NewAccountingApi(s.accountingMetrics), Public: false, }, + { + + Namespace: "bzz", + Version: "4.1", + Service: NewDirectAccessAPI(storage.NewLNetStore(s.netStore)), + Public: true, + }, } apis = append(apis, s.bzz.APIs()...)