aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/inspector.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-05-10 19:09:01 +0800
committerGitHub <noreply@github.com>2019-05-10 19:09:01 +0800
commit494f5d448a1685d5de4cb1524b863cd1fc9a13b0 (patch)
tree4db9d1afe4910c888f3488cd93e8537501d88314 /swarm/api/inspector.go
parentc94d582aa781b26412ba7d570f6707d193303a02 (diff)
parent9b1543c282f39d452f611eeee0307bdf828e8bc2 (diff)
downloadgo-tangerine-494f5d448a1685d5de4cb1524b863cd1fc9a13b0.tar
go-tangerine-494f5d448a1685d5de4cb1524b863cd1fc9a13b0.tar.gz
go-tangerine-494f5d448a1685d5de4cb1524b863cd1fc9a13b0.tar.bz2
go-tangerine-494f5d448a1685d5de4cb1524b863cd1fc9a13b0.tar.lz
go-tangerine-494f5d448a1685d5de4cb1524b863cd1fc9a13b0.tar.xz
go-tangerine-494f5d448a1685d5de4cb1524b863cd1fc9a13b0.tar.zst
go-tangerine-494f5d448a1685d5de4cb1524b863cd1fc9a13b0.zip
Merge pull request #19550 from ethersphere/swarm-rather-stable
swarm v0.4-rc1
Diffstat (limited to 'swarm/api/inspector.go')
-rw-r--r--swarm/api/inspector.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/swarm/api/inspector.go b/swarm/api/inspector.go
index ea3c4c049..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,21 +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()
- res.Has = inspector.netStore.Has(context.Background(), addr)
- results = append(results, res)
+ has, err := inspector.netStore.Has(context.Background(), addr)
+ if err != nil {
+ log.Error(err.Error())
+ }
+ if has {
+ hostChunks = append(hostChunks, "1")
+ } else {
+ hostChunks = append(hostChunks, "0")
+ }
}
- return results
+
+ return strings.Join(hostChunks, "")
}