Add comprehensive godoc documentation to handler.go

Expand documentation comments for SimpleHandler type and its methods
to better explain their purpose, parameters, and behavior.
This commit is contained in:
2025-12-27 12:24:36 +07:00
parent e1d0ab5ea6
commit c292fef0ac
7 changed files with 52 additions and 19 deletions
+5 -1
View File
@@ -171,7 +171,11 @@ func (h *ASHandler) flushBatchLocked() {
h.lastFlush = time.Now()
}
// Stop gracefully stops the handler and flushes remaining batches
// Stop gracefully shuts down the ASHandler by signaling the background flush
// goroutine to terminate and waiting for it to complete. Any pending ASN
// operations in the current batch are flushed to the database before Stop
// returns. This method should be called during application shutdown to ensure
// no data is lost.
func (h *ASHandler) Stop() {
close(h.stopCh)
h.wg.Wait()
+7 -2
View File
@@ -47,7 +47,10 @@ type peerUpdate struct {
timestamp time.Time
}
// NewPeerHandler creates a new batched peer tracking handler
// NewPeerHandler creates a new PeerHandler with the given database store and logger.
// It initializes the peer batch buffer and starts a background goroutine that
// periodically flushes accumulated peer updates to the database. The handler
// should be stopped by calling Stop when it is no longer needed.
func NewPeerHandler(db database.Store, logger *logger.Logger) *PeerHandler {
h := &PeerHandler{
db: db,
@@ -64,7 +67,9 @@ func NewPeerHandler(db database.Store, logger *logger.Logger) *PeerHandler {
return h
}
// WantsMessage returns true for all message types since we track peers from all messages
// WantsMessage returns true for all message types since peer information
// is extracted from every RIS message regardless of type. This satisfies
// the MessageHandler interface.
func (h *PeerHandler) WantsMessage(_ string) bool {
return true
}
+10 -3
View File
@@ -72,18 +72,25 @@ func NewPeeringHandler(db database.Store, logger *logger.Logger) *PeeringHandler
return h
}
// WantsMessage returns true if this handler wants to process messages of the given type
// WantsMessage reports whether the handler should receive messages of the
// given type. PeeringHandler only processes UPDATE messages, as these contain
// the AS path information needed to extract peering relationships.
func (h *PeeringHandler) WantsMessage(messageType string) bool {
// We only care about UPDATE messages that have AS paths
return messageType == "UPDATE"
}
// QueueCapacity returns the desired queue capacity for this handler
// QueueCapacity returns the buffer size for the handler's message queue.
// This value is used by the message dispatcher to allocate the channel
// buffer when registering the handler.
func (h *PeeringHandler) QueueCapacity() int {
return peeringHandlerQueueSize
}
// HandleMessage processes a message to extract AS paths
// HandleMessage processes a BGP UPDATE message by storing its AS path
// in memory for later batch processing. Messages with AS paths shorter
// than minPathLengthForPeering are ignored as they cannot contain valid
// peering information.
func (h *PeeringHandler) HandleMessage(msg *ristypes.RISMessage) {
// Skip if no AS path or only one AS
if len(msg.Path) < minPathLengthForPeering {