Skip to content

Commit

Permalink
proactive cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyaoi committed Jun 4, 2024
1 parent 124c2a4 commit 5c0d0b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/internal/protocol/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"math/rand"
"ocf/internal/common"

ds "github.com/ipfs/go-datastore"
"github.com/jasonlvhit/gocron"
"github.com/libp2p/go-libp2p/core/network"
)

// var verificationKey = "ocf-verification-key"
Expand All @@ -20,6 +22,18 @@ func StartTicker() {
Reconnect()
}
})
common.ReportError(err, "Error while creating verification ticker")
err = gocron.Every(30).Second().Do(func() {
host, _ := GetP2PNode(nil)
peers := host.Peerstore().Peers()
for _, peer := range peers {
// check if peer is still connected
if host.Network().Connectedness(peer) != network.Connected {
// delete peer from table
DeleteNodeTableHook(ds.NewKey(peer.String()))
}
}
})
common.ReportError(err, "Error while creating cleaning ticker")
<-gocron.Start()
common.ReportError(err, "Error while starting ticker")
}
2 changes: 1 addition & 1 deletion src/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func StartServer() {

_, cancelCtx := protocol.GetCRDTStore()
defer cancelCtx()
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
defer stop()

// gin.SetMode(gin.ReleaseMode)
Expand Down

0 comments on commit 5c0d0b5

Please sign in to comment.