Skip to content

Commit

Permalink
fw: prevent goroutine in non fw apps
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jan 15, 2025
1 parent d9794b2 commit 5c67391
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions fw/executor/yanfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func NewYaNFD(config *core.Config) *YaNFD {

// Initialize all modules here
core.OpenLogger()
face.Initialize()
table.Initialize()

return &YaNFD{
Expand Down
6 changes: 6 additions & 0 deletions fw/face/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"github.com/named-data/ndnd/fw/core"
)

// Initialize initializes the face module.
func Initialize() {
FaceTable.nextFaceID.Store(1)
go FaceTable.expirationHandler()
}

// CfgFaceQueueSize returns the maximum number of packets that can be buffered
// to be sent or received on a face.
func CfgFaceQueueSize() int {
Expand Down
8 changes: 2 additions & 6 deletions fw/face/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ var FaceTable Table
// Table hold all faces used by the forwarder.
type Table struct {
faces sync.Map
nextFaceID atomic.Uint64
}

func init() {
FaceTable.nextFaceID.Store(1)
go FaceTable.expirationHandler()
nextFaceID atomic.Uint64 // starts at 1
}

func (t *Table) String() string {
Expand Down Expand Up @@ -87,6 +82,7 @@ func (t *Table) Remove(id uint64) {
}

// expirationHandler stops the faces that have expired
// Runs in a separate goroutine called from Initialize()
func (t *Table) expirationHandler() {
for !core.ShouldQuit {
// Check for expired faces every 10 seconds
Expand Down

0 comments on commit 5c67391

Please # to comment.