From 996755c4a832afce8629a771cab8879c88c98355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jano=C5=A1=20Gulja=C5=A1?= Date: Wed, 10 Apr 2019 16:50:58 +0200 Subject: cmd/swarm, swarm: LocalStore storage integration --- swarm/api/inspector.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'swarm/api/inspector.go') diff --git a/swarm/api/inspector.go b/swarm/api/inspector.go index ea3c4c049..2ae6b4da8 100644 --- a/swarm/api/inspector.go +++ b/swarm/api/inspector.go @@ -60,7 +60,11 @@ func (inspector *Inspector) Has(chunkAddresses []storage.Address) []HasInfo { for _, addr := range chunkAddresses { res := HasInfo{} res.Addr = addr.String() - res.Has = inspector.netStore.Has(context.Background(), addr) + has, err := inspector.netStore.Has(context.Background(), addr) + if err != nil { + has = false + } + res.Has = has results = append(results, res) } return results -- cgit v1.2.3 From 993b145f25845e50e8af41ffb1116eaee381d693 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 11 Apr 2019 10:26:52 +0200 Subject: swarm/storage/localstore: fix export db.Put signature cmd/swarm/swarm-smoke: improve smoke tests (#1337) swarm/network: remove dead code (#1339) swarm/network: remove FetchStore and SyncChunkStore in favor of NetStore (#1342) --- swarm/api/inspector.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'swarm/api/inspector.go') diff --git a/swarm/api/inspector.go b/swarm/api/inspector.go index 2ae6b4da8..c4151bf20 100644 --- a/swarm/api/inspector.go +++ b/swarm/api/inspector.go @@ -19,7 +19,11 @@ package api import ( "context" "fmt" + "strings" + "time" + "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/swarm/log" "github.com/ethereum/go-ethereum/swarm/network" "github.com/ethereum/go-ethereum/swarm/storage" ) @@ -47,25 +51,34 @@ func (inspector *Inspector) ListKnown() []string { return res } -type HasInfo struct { - Addr string `json:"address"` - Has bool `json:"has"` +func (inspector *Inspector) IsSyncing() bool { + lastReceivedChunksMsg := metrics.GetOrRegisterGauge("network.stream.received_chunks", nil) + + // last received chunks msg time + lrct := time.Unix(0, lastReceivedChunksMsg.Value()) + + // if last received chunks msg time is after now-15sec. (i.e. within the last 15sec.) then we say that the node is still syncing + // technically this is not correct, because this might have been a retrieve request, but for the time being it works for our purposes + // because we know we are not making retrieve requests on the node while checking this + return lrct.After(time.Now().Add(-15 * time.Second)) } // Has checks whether each chunk address is present in the underlying datastore, // the bool in the returned structs indicates if the underlying datastore has // the chunk stored with the given address (true), or not (false) -func (inspector *Inspector) Has(chunkAddresses []storage.Address) []HasInfo { - results := make([]HasInfo, 0) +func (inspector *Inspector) Has(chunkAddresses []storage.Address) string { + hostChunks := []string{} for _, addr := range chunkAddresses { - res := HasInfo{} - res.Addr = addr.String() has, err := inspector.netStore.Has(context.Background(), addr) if err != nil { - has = false + log.Error(err.Error()) + } + if has { + hostChunks = append(hostChunks, "1") + } else { + hostChunks = append(hostChunks, "0") } - res.Has = has - results = append(results, res) } - return results + + return strings.Join(hostChunks, "") } -- cgit v1.2.3