sippy / rtpproxy

The RTPproxy is a high-performance software proxy for RTP streams that can work together with Sippy B2BUA, Kamailio, OpenSIPS and SER.
http://rtpproxy.org
BSD 2-Clause "Simplified" License
404 stars 114 forks source link

Difference between rtpp_weakref_obj and rtpp_hash_table #132

Closed pengwang7 closed 1 year ago

pengwang7 commented 1 year ago

Could someone tell me the difference between rtpp_weakref_obj and rtpp_hash_table, and how “weak” is reflected in rtpp_weakref_obj, thank you very much.

sobomax commented 1 year ago

Hi,

The hash_table is basically a generic hash table for storing objects that can then be efficiently retrieved via key. We use it for example to lookup session information provided the call-id/tags supplied by the OpenSIPS/Kamailio. It also integrates reference counting mechanism ensuring that once object is inserted into the hash table it cannot be deallocated until removed.

The weakref is a mechanism that is similar, in fact it builds upon hash_table, but uses internal 64-bit unique ids (UUID) as a key instead of something externally visible like call-id to index and access objects. The main use for it is to cross-reference different objects in the system without storing specific pointer to the object being referenced. As such it allows weakly linked objects to have an independent life cycles, so if object B has a reference to object A, the object A can be deallocated as needed and then if object B tries to access A via that reference it would get an proper "not found" error instead of trying to access pointer that is no longer there. It also helps to ensure there is no cycles in the reference counting so object A can have a reference to B and B to have a reference to A.

Hope it explains, if you have any more questions don't hesitate to ask.

-Max