sm: add OnCEA/OnDWA server-side handshake hooks (follow-up to #233)#253
Open
gergogera wants to merge 1 commit into
Open
sm: add OnCEA/OnDWA server-side handshake hooks (follow-up to #233)#253gergogera wants to merge 1 commit into
gergogera wants to merge 1 commit into
Conversation
) PR fiorix#233 added Settings.OnCER and Settings.OnDWR pre-hooks for server-side inbound CER and DWR. This adds the symmetric outbound pair: - OnCEA — fires on the server immediately before a CEA is sent, on the fully-constructed answer. Fires for both the success CEA (successCEA) and the error CEA (errorCEA). - OnDWA — fires immediately before a DWA is sent in response to a peer DWR (handleDWR). CEA and DWA are built and sent by the state machine internally, and HandleFunc/HandleIdx refuse CER/CEA/DWR handler registration, so a call-site hook is the only interception point for these outbound answers (the same rationale fiorix#233 used for inbound CER/DWR; chainPreHook only applies to received messages on the mux). Both are nil-guarded diam.HandlerFunc fields on Settings; default behaviour is unchanged when nil (existing tests pass unmodified). Tests added to hooks_test.go (TestOnCEAHook, TestOnCEAHookErrorCEA, TestOnDWAHook) mirror the TestOnCERHook/TestOnDWRHook template.
fiorix
approved these changes
Jun 26, 2026
fiorix
left a comment
Owner
There was a problem hiding this comment.
Thanks, this looks well scoped. I reviewed the call sites for success CEA, error CEA, and DWA, and the focused checks pass locally:
go test ./diam/sm/...go test -race ./diam/sm/...go vet ./diam/sm/...
No blocking comments from my pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #233 added
Settings.OnCERandSettings.OnDWRpre-hooks for server-side inbound CER and DWR. This adds the symmetric outbound pair:OnCEA— invoked immediately before a CEA is sent, on the fully-constructed answer. Fires for both the success CEA (successCEA) and the error CEA (errorCEA).OnDWA— invoked immediately before a DWA is sent in response to a peer DWR (handleDWR).Both are nil-guarded
diam.HandlerFuncfields onSettings. Default behaviour is unchanged when nil — pure additive, no signature changes, no behaviour change for existing users.Why a call-site hook (not
chainPreHook)CEA and DWA are built and sent by the state machine internally, and
sm.HandleFunc/HandleIdxexplicitly refuseCER/CEA/DWRhandler registration to protect the handshake. So the server's outbound handshake answers have no user interception point — exactly the situation #233 solved for inbound CER/DWR.chainPreHookonly applies to received messages dispatched on the mux; for an answer the SM constructs and writes itself, a nil-guarded call-site insert beforea.WriteTo(c)is the minimal mechanism.Changes
diam/sm/sm.goOnCEA/OnDWAfields onSettings(paired withOnCER/OnDWR), doc comments in the same stylediam/sm/cer.goOnCEAcall before send insuccessCEAanderrorCEAdiam/sm/dwr.goOnDWAcall before send inhandleDWRdiam/sm/hooks_test.goTestOnCEAHook,TestOnCEAHookErrorCEA,TestOnDWAHook— mirroring theTestOnCERHook/TestOnDWRHooktemplateTesting
go test -race ./diam/sm/passes; the three new tests cover the success-CEA, error-CEA (forced via an unsupportedAcct-Application-Id→DIAMETER_NO_COMMON_APPLICATION), and DWA paths.go vet ./...clean;gofmtclean.