swarm: cleanup, comment and tidy up for PR

This commit is contained in:
Fabio Barone 2019-02-01 10:23:23 -05:00
parent b15960d933
commit fc919f562c
5 changed files with 10 additions and 4 deletions

View file

@ -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",

View file

@ -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()

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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))