Skip to content

Commit

Permalink
Add node refresh and blacklist clear method call (#140)
Browse files Browse the repository at this point in the history
* add breakpoint resume upload function

* upgrade chunks upload

* update upload file handle

* updade deoss

* add cacher and node selector config for user

* clean up the code

* update go mod

* solve all bugs found during debugging

* update save peer decorator method

* add node refresh and blacklist clear method call

---------

Co-authored-by: AstaFrode <frode@cess.one>
  • Loading branch information
jiuquxzy and AstaFrode authored Apr 25, 2024
1 parent f5bfdcf commit 5fe13a8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
13 changes: 12 additions & 1 deletion cmd/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import (
sconfig "github.com/CESSProject/cess-go-sdk/config"
"github.com/CESSProject/cess-go-sdk/core/pattern"
sutils "github.com/CESSProject/cess-go-sdk/utils"
"github.com/CESSProject/cess-go-tools/scheduler"
p2pgo "github.com/CESSProject/p2p-go"
"github.com/CESSProject/p2p-go/core"
"github.com/CESSProject/p2p-go/out"
"github.com/howeyc/gopass"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -120,7 +122,16 @@ func cmd_run_func(cmd *cobra.Command, args []string) {
}
defer n.PeerNode.Close()

go node.Subscribe(ctx, n.PeerNode.GetHost(), peerRecord, n.PeerNode.GetBootnode())
go node.Subscribe(
ctx, n.PeerNode.GetHost(),
n.PeerNode.GetBootnode(),
func(p peer.AddrInfo) {
peerRecord.SavePeer(p)
if n.HasStoragePeer(p.ID.String()) {
n.FlushPeerNodes(scheduler.DEFAULT_TIMEOUT, p)
}
},
)
time.Sleep(time.Second)

out.Tip(fmt.Sprintf("chain network: %s", n.GetNetworkEnv()))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240423020530-5725d75be835
github.com/CESSProject/cess-go-tools v0.1.15
github.com/CESSProject/cess-go-tools v0.2.6
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde
github.com/CESSProject/p2p-go v0.3.14
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240423020530-5725d75be835 h1:5Fvw7kqstXZQ41F89zXEig/mKVnnLPR6Lg127GU64ZI=
github.com/CESSProject/cess-go-sdk v0.5.1-0.20240423020530-5725d75be835/go.mod h1:Y78g1FHZ02S1KDbf0NCHZQ/CELJkQ/Ti45hMaIO3HNM=
github.com/CESSProject/cess-go-tools v0.1.15 h1:fhLuXYPZoNEetvdQ16DWS96VhcbHxl1CdXfHan/qY+M=
github.com/CESSProject/cess-go-tools v0.1.15/go.mod h1:g86Xkq1+FZHg1srAvkwGqD3WoG+EIdeA2JHQAhhtKqQ=
github.com/CESSProject/cess-go-tools v0.2.6 h1:kZjqHN8uIyExTu8EEQApLN4qsmpWaWQfgBQD/0wF2+A=
github.com/CESSProject/cess-go-tools v0.2.6/go.mod h1:g86Xkq1+FZHg1srAvkwGqD3WoG+EIdeA2JHQAhhtKqQ=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde h1:5MDRjjtg6PEhqyVjupwaapN96cOZiddOGAYwKQeaTu0=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde/go.mod h1:RUXBd3ROP98MYepEEa0Y0l/T0vQlIKqFJxI/ocdnRLM=
github.com/CESSProject/p2p-go v0.3.14 h1:t7xLWTC8C+tuELtD6f2k4Ds6Z0zulMA0v83ONTDTthw=
Expand Down
4 changes: 2 additions & 2 deletions node/discoverMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/libp2p/go-libp2p/p2p/discovery/mdns"
)

func Subscribe(ctx context.Context, h host.Host, peerRecord PeerRecord, bootnode string) {
func Subscribe(ctx context.Context, h host.Host, bootnode string, callback func(p peer.AddrInfo)) {
var (
err error
room string
Expand Down Expand Up @@ -87,7 +87,7 @@ func Subscribe(ctx context.Context, h host.Host, peerRecord PeerRecord, bootnode
continue
}
log.Println("got a peer: ", findpeer.ID.String())
peerRecord.SavePeer(findpeer)
callback(findpeer)
}
}

Expand Down
7 changes: 6 additions & 1 deletion node/taskMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (n *Node) TaskMgt() {

task_10S := time.NewTicker(time.Duration(time.Second * 10))
defer task_10S.Stop()

count := 0
for {
select {
case <-task_10S.C:
Expand All @@ -37,6 +37,11 @@ func (n *Node) TaskMgt() {
n.Log("err", pattern.ERR_RPC_CONNECTION.Error())
out.Err(pattern.ERR_RPC_CONNECTION.Error())
}
count++
if count >= 4320 { //blacklist released every 12 hours
count = 0
n.ClearBlackList()
}

case <-ch_trackFile:
go n.tracker(ch_trackFile)
Expand Down

0 comments on commit 5fe13a8

Please sign in to comment.