Skip to content

sm: add OnCEA/OnDWA server-side handshake hooks (follow-up to #233)#253

Open
gergogera wants to merge 1 commit into
fiorix:mainfrom
gergogera:sm-oncea-ondwa-hooks
Open

sm: add OnCEA/OnDWA server-side handshake hooks (follow-up to #233)#253
gergogera wants to merge 1 commit into
fiorix:mainfrom
gergogera:sm-oncea-ondwa-hooks

Conversation

@gergogera

@gergogera gergogera commented Jun 24, 2026

Copy link
Copy Markdown

Summary

PR #233 added Settings.OnCER and Settings.OnDWR pre-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.HandlerFunc fields on Settings. 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/HandleIdx explicitly refuse CER/CEA/DWR handler 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. chainPreHook only applies to received messages dispatched on the mux; for an answer the SM constructs and writes itself, a nil-guarded call-site insert before a.WriteTo(c) is the minimal mechanism.

Changes

File Change
diam/sm/sm.go OnCEA/OnDWA fields on Settings (paired with OnCER/OnDWR), doc comments in the same style
diam/sm/cer.go nil-guarded OnCEA call before send in successCEA and errorCEA
diam/sm/dwr.go nil-guarded OnDWA call before send in handleDWR
diam/sm/hooks_test.go TestOnCEAHook, TestOnCEAHookErrorCEA, TestOnDWAHook — mirroring the TestOnCERHook/TestOnDWRHook template

Testing

  • go test -race ./diam/sm/ passes; the three new tests cover the success-CEA, error-CEA (forced via an unsupported Acct-Application-IdDIAMETER_NO_COMMON_APPLICATION), and DWA paths.
  • go vet ./... clean; gofmt clean.
  • Default-behaviour-unchanged is covered by the existing handshake tests passing unmodified.

)

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 fiorix left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants