diff --git a/fw/executor/yanfd.go b/fw/executor/yanfd.go index 45b38e87..dfaf0892 100644 --- a/fw/executor/yanfd.go +++ b/fw/executor/yanfd.go @@ -47,6 +47,7 @@ func NewYaNFD(config *core.Config) *YaNFD { // Initialize all modules here core.OpenLogger() + face.Initialize() table.Initialize() return &YaNFD{ diff --git a/fw/face/config.go b/fw/face/config.go index 797301a4..65af9316 100644 --- a/fw/face/config.go +++ b/fw/face/config.go @@ -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 { diff --git a/fw/face/table.go b/fw/face/table.go index 44750d0f..242b48e3 100644 --- a/fw/face/table.go +++ b/fw/face/table.go @@ -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 { @@ -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