diff options
author | Anton Evangelatov <anton.evangelatov@gmail.com> | 2019-04-11 16:26:52 +0800 |
---|---|---|
committer | Anton Evangelatov <anton.evangelatov@gmail.com> | 2019-05-10 18:26:30 +0800 |
commit | 993b145f25845e50e8af41ffb1116eaee381d693 (patch) | |
tree | 47a88eec27f66b7237512c862d7ab2f8e9f314d3 /swarm/api/inspector.go | |
parent | 996755c4a832afce8629a771cab8879c88c98355 (diff) | |
download | go-tangerine-993b145f25845e50e8af41ffb1116eaee381d693.tar go-tangerine-993b145f25845e50e8af41ffb1116eaee381d693.tar.gz go-tangerine-993b145f25845e50e8af41ffb1116eaee381d693.tar.bz2 go-tangerine-993b145f25845e50e8af41ffb1116eaee381d693.tar.lz go-tangerine-993b145f25845e50e8af41ffb1116eaee381d693.tar.xz go-tangerine-993b145f25845e50e8af41ffb1116eaee381d693.tar.zst go-tangerine-993b145f25845e50e8af41ffb1116eaee381d693.zip |
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)
Diffstat (limited to 'swarm/api/inspector.go')
-rw-r--r-- | swarm/api/inspector.go | 35 |
1 files changed, 24 insertions, 11 deletions
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, "") } |