Skip to content

refactor: consolidate call parameters into callCtx struct - #47

Open
thorsager wants to merge 1 commit into
mainfrom
41-refactor-extract-callctx-struct-to-eliminate-long-parameter-lists-in-b2bua-response-loops
Open

refactor: consolidate call parameters into callCtx struct#47
thorsager wants to merge 1 commit into
mainfrom
41-refactor-extract-callctx-struct-to-eliminate-long-parameter-lists-in-b2bua-response-loops

Conversation

@thorsager

Copy link
Copy Markdown
Owner

Closes #41

Refactor internal/b2bua/handler.go to eliminate the long parameter lists in the B2BUA response loops.

  • Added serverPort field to Handler, initialized in NewHandler.
  • Replaced all net.SplitHostPort(h.serverAddr) recomputations with h.serverPort.
  • Introduced unexported callCtx struct holding the shared call state.
  • Refactored b2buaResponseLoop, handleBob200OK, trunkResponseLoop, and handleTrunk200OK to accept *callCtx plus path-specific parameters.
  • Updated callers in handleInternalInvite and handleTrunkInvite.

The optional visitor-pattern / shared finalizeCall helper is intentionally left for a follow-up (see #46).

  • make test
  • make lint
  • make integrationtest

Introduce a callCtx struct to group the many parameters passed through the
call handling functions. This improves readability and maintainability.

Also cache the server port in the Handler struct to avoid repeated parsing.
@github-actions

Copy link
Copy Markdown

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/thorsager/trecs/internal/b2bua 3.80% (+0.21%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/thorsager/trecs/internal/b2bua/handler.go 3.01% (+0.21%) 996 (-5) 30 (+2) 966 (-7) 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the B2BUA call-bridging flow in internal/b2bua/handler.go by consolidating the shared per-call state that previously had to be threaded through long parameter lists, and by caching the server’s SIP listen port on the Handler to avoid repeated parsing.

Changes:

  • Added Handler.serverPort, initialized once in NewHandler, and replaced repeated net.SplitHostPort(...) call sites with h.serverPort.
  • Introduced an unexported callCtx struct to hold shared call state (req/tx/targets, RTP conns, tags/Call-IDs, SDP state, etc.).
  • Refactored trunkResponseLoop/handleTrunk200OK and b2buaResponseLoop/handleBob200OK to accept *callCtx plus only path-specific parameters, updating the invite handlers accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: extract callCtx struct to eliminate long parameter lists in B2BUA response loops

2 participants