Skip to content

Commit

Permalink
feat(core): Add Republish method to Full Node
Browse files Browse the repository at this point in the history
  • Loading branch information
rolysr committed Jun 10, 2023
1 parent b04e788 commit 887fc7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions core/fullNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func (fn *FullNode) CreateGRPCServer(grpcServerAddress string) {
pb.RegisterFullNodeServer(grpcServer, fn)
reflection.Register(grpcServer)

go fn.Republish()

listener, err := net.Listen("tcp", grpcServerAddress)
if err != nil {
log.Fatal("cannot create grpc server: ", err)
Expand Down Expand Up @@ -634,3 +636,21 @@ func (fn *FullNode) PrintRoutingTable() {
}
}
}

///////////////////////////////////////////////////////
////// //////
////// REPLICATION //////
////// //////
///////////////////////////////////////////////////////

func (fn *FullNode) Republish() {
for {
<-time.After(time.Hour)
for _, key range fn.dht.Storage.GetKeys() {
data := fn.dht.Storage.Read(key, 0, 0)
go func() {
fn.StoreValue(key, data)
}()
}
}
}
2 changes: 2 additions & 0 deletions interfaces/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ type Persistence interface {
Read(key []byte, start int64, end int64) (data *[]byte, err error)

Delete(key []byte) error

GetKeys(key []byte) [][]byte
}

0 comments on commit 887fc7e

Please sign in to comment.