diff --git a/src/internal/protocol/clock.go b/src/internal/protocol/clock.go index a8c077d..8d82953 100644 --- a/src/internal/protocol/clock.go +++ b/src/internal/protocol/clock.go @@ -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" @@ -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") } diff --git a/src/internal/server/server.go b/src/internal/server/server.go index 47a49d8..5a575db 100644 --- a/src/internal/server/server.go +++ b/src/internal/server/server.go @@ -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)