Juha,
Function t_loads contacts in tm/t_serial.c encodes the Request-URI and all branches of the SIP message into an AVP. At the end the function calls clear_branches to remove all branches from the SIP request, so that a subsequent call to t_next_contacts can only restore those with highest q number.
I am wondering if calling clear_branches is enough. Shouldn't the function also call reset_dst_uri to reset the value of the dst_uri (which is now also stored in the AVP), and perhaps also clear the send socket, the branch flags and the path vector for the Request-URI?
All these values are encoded into the AVP, but they are only cleared for additional branches (in clear_branches), but not for the Request-URI "branch".
I also considered doing that in clear_branches, but then I realized that this function is called from other places and modules and it could break them.
Any thoughts on this? How thorough should t_load_contacts be when it resets variables whose values are stored in the AVP?
-- Jan
Jan Janak writes:
I am wondering if calling clear_branches is enough. Shouldn't the function also call reset_dst_uri to reset the value of the dst_uri (which is now also stored in the AVP), and perhaps also clear the send socket, the branch flags and the path vector for the Request-URI?
jan,
may be so, but i have thought that script writer would not have set dst_uri or send socket if script is calling next_contacts(). so i would consider it a bug in the script if those things are set when next_contacts() is called. on the other hand, it might not hurt to clear them.
All these values are encoded into the AVP, but they are only cleared for additional branches (in clear_branches), but not for the Request-URI "branch".
if r-uri and all branches (if any) have the same q, then load_contacts() does nothing and branches should not be cleared, because they are used "as is" without loading them from contacts_avp.
Any thoughts on this? How thorough should t_load_contacts be when it resets variables whose values are stored in the AVP?
see above. by the way, thanks for reading t_serial.c.
-- juha
On Sat, Oct 17, 2009 at 9:41 AM, Juha Heinanen jh@tutpro.com wrote:
Jan Janak writes:
> I am wondering if calling clear_branches is enough. Shouldn't the > function also call reset_dst_uri to reset the value of the dst_uri > (which is now also stored in the AVP), and perhaps also clear the send > socket, the branch flags and the path vector for the Request-URI?
jan,
may be so, but i have thought that script writer would not have set dst_uri or send socket if script is calling next_contacts(). so i would consider it a bug in the script if those things are set when next_contacts() is called. on the other hand, it might not hurt to clear them.
I wasn't actually thinking that the script writer would set them explicitly, but I though that it might be a good idea to have them cleared when t_load_contact finishes. But after reading your reply I realized that this is in fact not necessary, because a subsequent call to t_next_contacts rewrites them anyway. We just have to make sure that t_next_contacts properly clears those fields that have empty values in the AVP.
This makes sense, because if t_load_contacts was successful then there is at least one contact stored in the AVP and it is guaranteed that at least the Request-URI will be updated when t_next_contacts is called for the first time. But it is not guaranteed that any of the branches will be updated, this can happen if we have just one contact with the highest q value, therefore we have to clear them.
I also wonder if t_load_contacts is the right place to clear branches. I think that it would be better to do that in the first call to t_next_contacts. However, figuring out whether we call t_next_contacts for the fist time can be difficult. We would probably need to store this information in the contacts AVP somehow. At least for me personally, having the branches cleared in t_load_contacts is kinda unexpected side-effect. We should probably document it in the README (I can take care of that, I want to update the README anyway).
> All these values are encoded into the AVP, but they are only cleared > for additional branches (in clear_branches), but not for the > Request-URI "branch".
if r-uri and all branches (if any) have the same q, then load_contacts() does nothing and branches should not be cleared, because they are used "as is" without loading them from contacts_avp.
Yes, that's how it works, I checked that. t_load_contacts clears branches only if it produces something that can actually by used by t_next_contacts. And because t_load_contacts clears branches, the script writer has to call t_next_contacts in this case, otherwise some of the contacts could be lost.
Things could break if the script writer calls t_load_contacts and does not call t_next_contacts. I suggest that we change this after the release and make t_next_contacts to clear the branches if needed. Then nothing bad would happen if the script writer only calls t_load_contacts, it will just create the AVP but if you do not call t_next_contacts then things would work as usual, the request will be forked to all branches in parallel.
This way it would be also possible to fill the AVP with contacs from other sources than t_load_contacts (i.e. the database). That is not possible right now, because t_next_contacts does not clear branches for itself--t_load_contacts has to be called first.
-- Jan
Jan Janak writes:
At least for me personally, having the branches cleared in t_load_contacts is kinda unexpected side-effect. We should probably document it in the README (I can take care of that, I want to update the README anyway).
there has been no effort to somehow merge the existing branches with load_contacts branches. when you call load_contacts(), you start from scratch.
Yes, that's how it works, I checked that. t_load_contacts clears branches only if it produces something that can actually by used by t_next_contacts. And because t_load_contacts clears branches, the script writer has to call t_next_contacts in this case, otherwise some of the contacts could be lost.
yes, no branches exist after load_contacts() is called and if you don't call next_contacts(), you will not have anything. this is the intended behavior.
Things could break if the script writer calls t_load_contacts and does not call t_next_contacts.
this is how it is supposed to work.
I suggest that we change this after the release and make t_next_contacts to clear the branches if needed. Then nothing bad would happen if the script writer only calls t_load_contacts, it will just create the AVP but if you do not call t_next_contacts then things would work as usual, the request will be forked to all branches in parallel.
i don't know if that kind of change is necessary, because next_contacts() is supposed to be called after load_contacts(). if script writer does not do that, it is his/her fault. in that case better not to call load_contacts() either.
This way it would be also possible to fill the AVP with contacs from other sources than t_load_contacts (i.e. the database). That is not possible right now, because t_next_contacts does not clear branches for itself--t_load_contacts has to be called first.
you get contacts from wherever, e.g. database, and append them as branches before calling load_contacts().
while we are at this, i suggest that also sr simplifies r-uri/branch handling as described in this message:
http://lists.opensips.org/pipermail/users/2009-January/002365.html
-- juha