Skip to content

Commit

Permalink
feat(worker): drop expired nodes when they are announced
Browse files Browse the repository at this point in the history
  • Loading branch information
whereswaldon committed Oct 12, 2020
1 parent a0a4a97 commit 884e341
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module git.sr.ht/~whereswaldon/sprout-go
go 1.14

require (
git.sr.ht/~athorp96/forest-ex v0.0.0-20201011211837-c16617613aa2
git.sr.ht/~whereswaldon/forest-go v0.0.0-20201011203633-e3b60d5a8e86
github.com/fsnotify/fsnotify v1.4.7
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 // indirect
)

replace golang.org/x/crypto => github.com/ProtonMail/crypto v0.0.0-20200420072808-71bec3603bf3

replace git.sr.ht/~athorp96/forest-ex => git.sr.ht/~whereswaldon/forest-ex v0.0.0-20201012002222-096b725746a3
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
git.sr.ht/~whereswaldon/forest-ex v0.0.0-20201012002222-096b725746a3 h1:v+k9duU/s9TNpQtwDKcDP50Xq3b+YLxt7UCY7h0MnYg=
git.sr.ht/~whereswaldon/forest-ex v0.0.0-20201012002222-096b725746a3/go.mod h1:N2PwWOB4JHluCAc9pRmd+78OEqWTw3wYgDQnCCrrQ/Q=
git.sr.ht/~whereswaldon/forest-go v0.0.0-20201011203633-e3b60d5a8e86 h1:skl5CR7Na2FyoA0xowlsIbhtYSMrxMwQN8awbgVxQHY=
git.sr.ht/~whereswaldon/forest-go v0.0.0-20201011203633-e3b60d5a8e86/go.mod h1:aGmm4R7ifFBvJWOHINDvZcKVOu+ODkD75NmNm/O0zME=
github.com/ProtonMail/crypto v0.0.0-20200420072808-71bec3603bf3 h1:JW27/kGLQzeM1Fxg5YQhdkTEAU7HIAHMgSag35zVTnY=
Expand Down
8 changes: 8 additions & 0 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"
"time"

"git.sr.ht/~athorp96/forest-ex/expiration"
"git.sr.ht/~whereswaldon/forest-go"
"git.sr.ht/~whereswaldon/forest-go/fields"
"git.sr.ht/~whereswaldon/forest-go/store"
Expand Down Expand Up @@ -276,6 +277,13 @@ func (c *Worker) IngestNode(node forest.Node) error {
func (c *Worker) OnAnnounce(s *Conn, messageID MessageID, nodes []forest.Node) error {
c.Printf("Received announce: id:%d quantity:%d", messageID, len(nodes))
for _, node := range nodes {
if expired, err := expiration.IsExpired(node); err != nil {
log.Printf("failed checking %v for expiration; dropping: %v", node.ID(), err)
continue
} else if expired {
log.Printf("dropping expired node %v", node.ID())
continue
}
// if we already have it, don't worry about it
// This ensures that we don't announce it again to our peers and create
// an infinite cycle of announcements
Expand Down

0 comments on commit 884e341

Please sign in to comment.