From fc919f562ce288cb8e5dc9149208bc66b04c5e24 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Fri, 1 Feb 2019 10:23:23 -0500 Subject: [PATCH] swarm: cleanup, comment and tidy up for PR --- swarm/api/testapi.go | 8 ++++---- swarm/storage/common_test.go | 1 + swarm/storage/memstore.go | 1 + swarm/storage/netstore.go | 3 +++ swarm/swarm.go | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/swarm/api/testapi.go b/swarm/api/testapi.go index 0d15da971c..6f412591c8 100644 --- a/swarm/api/testapi.go +++ b/swarm/api/testapi.go @@ -37,6 +37,7 @@ func (c *Control) Hive() string { return c.hive.String() } +// DebugAPI is a umbrella structure to provide additional debug API endpoints type DebugAPI struct { netStore *storage.NetStore } @@ -47,14 +48,13 @@ func NewDebugAPI(nstore *storage.NetStore) *DebugAPI { } } -func (dapi *DebugAPI) String() string { - return "debugapi" -} - +// HasChunk returns true if the underlying datastore has +// the chunk stored with the given address, false if it does not store it func (dapi *DebugAPI) HasChunk(chunkAddress storage.Address) bool { return dapi.netStore.HasChunk(context.Background(), chunkAddress) } +// The description for the DebugAPI to add to the APIs if the flag is set func GetDebugAPIDesc(nstore *storage.NetStore) rpc.API { return rpc.API{ Namespace: "debugapi", diff --git a/swarm/storage/common_test.go b/swarm/storage/common_test.go index 53ef94a568..74fb00c48d 100644 --- a/swarm/storage/common_test.go +++ b/swarm/storage/common_test.go @@ -266,6 +266,7 @@ func (m *MapChunkStore) Get(_ context.Context, ref Address) (Chunk, error) { return chunk, nil } +// Need to implement HasChunk from SyncChunkStore func (m *MapChunkStore) HasChunk(ctx context.Context, ref Address) bool { m.mu.RLock() defer m.mu.RUnlock() diff --git a/swarm/storage/memstore.go b/swarm/storage/memstore.go index 2fff8cb965..723bf70000 100644 --- a/swarm/storage/memstore.go +++ b/swarm/storage/memstore.go @@ -48,6 +48,7 @@ func NewMemStore(params *StoreParams, _ *LDBStore) (m *MemStore) { } } +// HasChunk needed to implement SyncChunkStore func (m *MemStore) HasChunk(_ context.Context, addr Address) bool { return m.cache.Contains(addr) } diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index 2026ff0d71..f4ea928083 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -158,6 +158,9 @@ func (n *NetStore) get(ctx context.Context, ref Address) (Chunk, func(context.Co return chunk, nil, nil } +// HasChunk is the storage layer entry point to query the underlying +// database to return if it has a chunk or not. +// Called from the DebugAPI func (n *NetStore) HasChunk(ctx context.Context, ref Address) bool { return n.store.HasChunk(ctx, ref) } diff --git a/swarm/swarm.go b/swarm/swarm.go index f2f5bd8bca..58878989a8 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -514,6 +514,7 @@ func (self *Swarm) APIs() []rpc.API { apis = append(apis, self.ps.APIs()...) } + // Only provide certain endpoints if the `debug-api` flag is set if self.config.DebugAPI { log.Info("Running node with debug APIs attached") apis = append(apis, api.GetDebugAPIDesc(self.netStore))