Skip to content

Commit

Permalink
feat: add bandwidth stats
Browse files Browse the repository at this point in the history
  • Loading branch information
myml committed Feb 17, 2023
1 parent d96db3f commit fa00d5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"syscall"
"time"

"github.com/dustin/go-humanize"
"github.com/ipfs/go-cid"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
Expand Down Expand Up @@ -103,21 +104,32 @@ func pinHotData(ctx context.Context, node *core.IpfsNode) {
log.Println("get current peers:", err)
continue
}
log.Println("peers count", len(peers))
stats := node.Reporter.GetBandwidthTotals()
log.Printf("Peers count: %v\tTotal Up: %v\tTotal Down: %v\n", len(peers), humanize.Bytes(uint64(stats.TotalOut)), humanize.Bytes(uint64(stats.TotalIn)))

hotCid, err := resolveIPNS(ctx, node, HotData)
if err != nil {
log.Println("resolve hotdata:", err)
continue
}
path := path.New(HotData)
exists := false
ch, err := api.Pin().Ls(ctx, options.Pin.Ls.Recursive())
for info := range ch {
if info.Path().Cid().Equals(*hotCid) {
api.Pin().Rm(ctx, info.Path())
if !info.Path().Cid().Equals(*hotCid) {
err = api.Pin().Rm(ctx, info.Path())
log.Println("resolve hotdata:", err)
if err != nil {
log.Println("rm pin:", err)
continue
}
} else {
exists = true
}
}
log.Println("pin hot data", hotCid, api.Pin().Add(ctx, path, options.Pin.Recursive(true)))
if !exists {
log.Println("pin hot data", hotCid, api.Pin().Add(ctx, path, options.Pin.Recursive(true)))
}
}
}

Expand Down Expand Up @@ -193,6 +205,7 @@ func initConfig() (*config.Config, error) {
cfg.Swarm.ConnMgr.GracePeriod = config.NewOptionalDuration(time.Minute)
cfg.Swarm.ConnMgr.HighWater = config.NewOptionalInteger(40)
cfg.Swarm.ConnMgr.LowWater = config.NewOptionalInteger(20)
cfg.Datastore.GCPeriod = "240h"
cfg.Bootstrap = Bootstrap
err = fsrepo.Init(RepoPath, cfg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name: "apt-ipfs"
arch: "amd64"
platform: "linux"
version: "v0.0.7"
version: "v0.0.8"
section: "default"
priority: "extra"
maintainer: "wurongjie <wurongjie@deepin.org>"
Expand Down

0 comments on commit fa00d5b

Please sign in to comment.