drachtio / drachtio-srf

drachtio signaling resource framework
https://drachtio.org
MIT License
167 stars 58 forks source link

Incorrect socket selected in outbound mode #117

Open jonastelzio opened 2 years ago

jonastelzio commented 2 years ago

When running SRF in outbound connection mode, in functions like 'createB2BUA', the default socket selected is basically 'the first socket' it can find. The code workaround to this is forwarding the _socket parameter like this:

srf.createB2BUA(req, res, destSipUri, {
    headers: forwardHeaders,
    passFailure: false,
    localSdpB: rtpOffer.sdp,
    localSdpA: async (remoteSdp, res) => await this.getSdpAnswer(remoteSdp, res),
    _socket: req.socket  // <- pass on the incoming req.socket here
})

This workaround works, but it's interacting with a _prefixed parameter, and is completely undocumented. If I don't set the _socket parameter, SRF will automatically just pick the first socket in the sockets collection, which can (and will in most cases), belong to a completely unrelated SRF session.

davehorton commented 2 years ago

Good point, would you agree that Srf.createB2BUA should set _socket for you? If so I can make that change

jonastelzio commented 2 years ago

@davehorton Yeah, I think it would make sense that it picks whatever socket is associated with the passed in Request? I can't really think of a use case for ever having it belong to another connection, at least in outbound mode. In "inbound mode" it could make sense I suppose, maybe?