Skip to content

Optionally add Record-Route for inbound, better errors #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

dennwc
Copy link
Contributor

@dennwc dennwc commented Mar 17, 2025

No description provided.

@dennwc dennwc self-assigned this Mar 17, 2025
@dennwc dennwc requested a review from a team as a code owner March 17, 2025 11:41
@@ -548,19 +548,19 @@ func (c *inboundCall) runMediaConn(offerData []byte, conf *config.Config, featur
EnableJitterBuffer: c.s.conf.EnableJitterBuffer,
}, RoomSampleRate)
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot create media port: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use some error wrapping utility or psrpc.NewError here (and below) instead, to allow extracting the original error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's mostly for debugging for now. I'll need to annotate all errors this way if we want to propagate them.

@@ -1150,6 +1150,16 @@ func (c *sipInbound) Accept(ctx context.Context, sdpData []byte, headers map[str
// This will effectively redirect future SIP requests to this server instance (if host address is not LB).
r.AppendHeader(c.contact)

// Other in-dialog requests should be sent to this instance as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure this isn't the right way to do it. I reviewed the inbound SIP logic, and it looks like it's just imitating the SIP handling used in the existing setup. It needs a major overhaul—something I'd like to do when I find the time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why do you think it's incorrect? Also, this is not for OSS version.

Copy link
Contributor

Choose a reason for hiding this comment

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

In-dialog requests are sent to the Contact header if there's no Record-Route (RR) header. So, copying the Contact to the RR doesn't make sense to me. Also, RR handling should be managed by the proxy—doing it on the UA side feels a bit hacky.

Copy link
Contributor

Choose a reason for hiding this comment

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

And if the INVITE contains Record-Route headers, they must also be present in the 200 OK response—which I believe is currently handled by the sipgo library automatically. Interfering with this process could break routing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added config flag for this behavior.

@zusrut As I understand it, ideally SIP server should drop Contact header in case it wants all signaling to go through proxy and set Record-Route then.

But for now we want both paths to work - if server is hit through the proxy and if it's hit directly (through LB). Proxy will use Route and non-proxy path will use either Record or Contact. I guess we could drop Contact and always add Record-Route instead to achieve the same result. Do you think that would be better?

Copy link
Contributor

@zusrut zusrut Apr 21, 2025

Choose a reason for hiding this comment

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

@dennwc The SIP Proxy does not drop the Contact header. Instead, it simply adds a Record-Route header and forwards the request to the UAS. When the UAS needs to send a request within the dialog, it sets the Request-URI based on the received Contact header and Route headers according received RR headers. If no Record-Route headers were present, the request will be sent using the Request-URI derived from the Contact header. If there are Route headers, the request will be sent to the first Route, and the proxy will remove any Route headers that refer to itself before forwarding the request to the next hop or to the Request-URI if no more Route headers are present.
So Contact header is used in every ineraction at the last step and cannot be dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The SIP Proxy does not drop the Contact header.

I don't mean that the server should drop it. That must not happen.

What I mean is that if we want the signaling to always go through the proxy, LiveKit SIP should not set Contact, but could set Record-Route instead.

@dennwc dennwc force-pushed the update branch 2 times, most recently from ad100dd to 77b7ccc Compare April 21, 2025 09:57
@dennwc dennwc changed the title Update sipgo parser, Record-Route for inbound, better errors Optionally add Record-Route for inbound, better errors Apr 21, 2025
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.

3 participants