@@ -1773,75 +1773,139 @@ static void redis_update_call_codec_handlers(struct call_media *media) {
1773
1773
}
1774
1774
}
1775
1775
1776
- static int redis_update_call_payloads (struct call * c , redis_call_t * redis_call ) {
1777
- unsigned updated = 0 , media_updates = 0 ;
1778
- struct call_media * m = NULL ;
1779
- redis_call_media_t * media ;
1776
+ static int redis_update_call_payloads (struct call_media * m , redis_call_media_t * media ) {
1777
+ unsigned updated = 0 ;
1778
+
1779
+ /* replace codec prefs with those loaded from the database. */
1780
+ /* TODO: ATM the database does not encode them correctly, so we lose some data. */
1781
+ /* maybe convert codec prefs cleanup code to use __delete_x_codec (which is currently static) */
1782
+ if (g_queue_get_length (media -> codec_prefs_recv ) != g_queue_get_length (& m -> codecs_prefs_recv )) {
1783
+ rlog (LOG_INFO , "['" STR_FORMAT_M "'] media %u: replacing %d local codec prefs recv with %d remote codec prefs" ,
1784
+ STR_FMT_M (& m -> call -> callid ), m -> unique_id , g_queue_get_length (& m -> codecs_prefs_recv ),
1785
+ g_queue_get_length (media -> codec_prefs_recv ));
1786
+ g_hash_table_remove_all (m -> codecs_recv );
1787
+ g_hash_table_remove_all (m -> codec_names_recv );
1788
+ g_queue_clear_full (& m -> codecs_prefs_recv , (GDestroyNotify ) payload_type_free );
1789
+ updated += redis_update_call_media_codecs (m , media -> codec_prefs_recv , __rtp_payload_type_add_recv );
1790
+ }
1791
+ if (g_queue_get_length (media -> codec_prefs_send ) != g_queue_get_length (& m -> codecs_prefs_send )) {
1792
+ rlog (LOG_INFO , "['" STR_FORMAT_M "'] media %u: replacing %d local codec prefs send with %d remote codec prefs" ,
1793
+ STR_FMT_M (& m -> call -> callid ), m -> unique_id , g_queue_get_length (& m -> codecs_prefs_send ),
1794
+ g_queue_get_length (media -> codec_prefs_send ));
1795
+ g_hash_table_remove_all (m -> codecs_send );
1796
+ g_hash_table_remove_all (m -> codec_names_send );
1797
+ g_queue_clear_full (& m -> codecs_prefs_send , (GDestroyNotify ) payload_type_free );
1798
+ updated += redis_update_call_media_codecs (m , media -> codec_prefs_send , __rtp_payload_type_add_send );
1799
+ }
1800
+ if (updated ) {
1801
+ redis_update_call_codec_handlers (m );
1802
+ rlog (LOG_INFO , "Updated media %u codecs from Redis" , m -> unique_id );
1803
+ }
1804
+ return 0 ;
1805
+ }
1780
1806
1781
- GList * l ;
1782
- for (l = c -> medias .head ; l ; l = l -> next ) {
1783
- m = l -> data ;
1784
- media = g_queue_peek_nth (redis_call -> media , m -> unique_id );
1785
- if (!media )
1786
- continue ; /* weird... */
1787
- media_updates = updated ;
1788
- /* replace codec prefs with those loaded from the database. */
1789
- /* TODO: ATM the database does not encode them correctly, so we lose some data. */
1790
- /* maybe convert codec prefs cleanup code to use __delete_x_codec (which is currently static) */
1791
- if (g_queue_get_length (media -> codec_prefs_recv ) != g_queue_get_length (& m -> codecs_prefs_recv )) {
1792
- rlog (LOG_DEBUG , "['" STR_FORMAT_M "'] media %u: replacing %d local codec prefs recv with %d remote codec prefs" ,
1793
- STR_FMT_M (& c -> callid ), m -> unique_id , g_queue_get_length (& m -> codecs_prefs_recv ),
1794
- g_queue_get_length (media -> codec_prefs_recv ));
1795
- g_hash_table_remove_all (m -> codecs_recv );
1796
- g_hash_table_remove_all (m -> codec_names_recv );
1797
- g_queue_clear_full (& m -> codecs_prefs_recv , (GDestroyNotify ) payload_type_free );
1798
- updated += redis_update_call_media_codecs (m , media -> codec_prefs_recv , __rtp_payload_type_add_recv );
1807
+ static int redis_update_call_maps (struct call_media * m , redis_call_media_t * media ) {
1808
+ struct endpoint_map * ep ;
1809
+ redis_call_media_endpoint_map_t * rcep ;
1810
+ GList * epl , * rcepl ;
1811
+
1812
+ for (epl = m -> endpoint_maps .head ; epl ; epl = epl -> next ) {
1813
+ ep = epl -> data ;
1814
+ for (rcepl = media -> endpoint_maps -> head ; rcepl ; rcepl = rcepl -> next ) {
1815
+ rcep = rcepl -> data ;
1816
+ if (rcep -> unique_id != ep -> unique_id )
1817
+ continue ;
1818
+ ep -> wildcard = rcep -> wildcard ;
1819
+ endpoint_parse_any (& ep -> endpoint , rcep -> endpoint -> s );
1799
1820
}
1800
- if (g_queue_get_length (media -> codec_prefs_send ) != g_queue_get_length (& m -> codecs_prefs_send )) {
1801
- rlog (LOG_DEBUG , "['" STR_FORMAT_M "'] media %u: replacing %d local codec prefs send with %d remote codec prefs" ,
1802
- STR_FMT_M (& c -> callid ), m -> unique_id , g_queue_get_length (& m -> codecs_prefs_send ),
1803
- g_queue_get_length (media -> codec_prefs_send ));
1804
- g_hash_table_remove_all (m -> codecs_send );
1805
- g_hash_table_remove_all (m -> codec_names_send );
1806
- g_queue_clear_full (& m -> codecs_prefs_send , (GDestroyNotify ) payload_type_free );
1807
- updated += redis_update_call_media_codecs (m , media -> codec_prefs_send , __rtp_payload_type_add_send );
1821
+ }
1822
+ /* update some media fields here, while we have the media */
1823
+ if (!m -> ptime )
1824
+ m -> ptime = media -> ptime ;
1825
+ m -> media_flags = media -> media_flags ;
1826
+ return 0 ;
1827
+ }
1828
+
1829
+ static void redis_update_call_crypto_sync_sdes_params (GQueue * m_sdes_q , GQueue * redis_sdes_q ) {
1830
+ redis_call_media_sdes_t * redis_sdes ;
1831
+
1832
+ crypto_params_sdes_queue_clear (m_sdes_q );
1833
+ for (GList * l = redis_sdes_q -> head ; l ; l = l -> next ) {
1834
+ redis_sdes = l -> data ;
1835
+ /** copied and modified from sdp.c:sdp_streams() */
1836
+ struct crypto_params_sdes * cps = g_slice_alloc0 (sizeof (* cps ));
1837
+ g_queue_push_tail (m_sdes_q , cps );
1838
+
1839
+ if (redis_sdes -> crypto_suite_name )
1840
+ cps -> params .crypto_suite = crypto_find_suite (redis_sdes -> crypto_suite_name );
1841
+ if (redis_sdes -> mki ) {
1842
+ cps -> params .mki_len = redis_sdes -> mki -> len ;
1843
+ if (cps -> params .mki_len ) {
1844
+ cps -> params .mki = malloc (cps -> params .mki_len );
1845
+ memcpy (cps -> params .mki , redis_sdes -> mki -> s , cps -> params .mki_len );
1846
+ }
1808
1847
}
1809
- if (updated != media_updates ) {
1810
- redis_update_call_codec_handlers (m );
1848
+ cps -> tag = redis_sdes -> tag ;
1849
+ if (redis_sdes -> master_key )
1850
+ memcpy (cps -> params .master_key , redis_sdes -> master_key -> s , redis_sdes -> master_key -> len );
1851
+ if (redis_sdes -> master_salt )
1852
+ memcpy (cps -> params .master_salt , redis_sdes -> master_salt -> s , redis_sdes -> master_salt -> len );
1853
+ cps -> params .session_params = redis_sdes -> session_params ;
1854
+ }
1855
+ }
1856
+
1857
+ static int redis_update_call_crypto (struct call_media * m , redis_call_media_t * media ) {
1858
+ const struct dtls_hash_func * found_hash_func ;
1859
+
1860
+ if (media -> fingerprint .hash_func_name && !m -> fingerprint .hash_func ) {
1861
+ /* json_restore_call() doesn't do this - should we? */
1862
+ found_hash_func = dtls_find_hash_func (media -> fingerprint .hash_func_name );
1863
+ if (found_hash_func ) {
1864
+ rlog (LOG_DEBUG , "Updating crypto for call ID '" STR_FORMAT_M "', media %u from Redis" ,
1865
+ STR_FMT_M (& m -> call -> callid ), m -> unique_id );
1866
+ m -> fingerprint .hash_func = found_hash_func ;
1867
+ memcpy (m -> fingerprint .digest , media -> fingerprint .fingerprint -> s , media -> fingerprint .fingerprint -> len );
1811
1868
}
1812
1869
}
1813
- if (updated )
1814
- rlog (LOG_INFO , "Updated media codecs from Redis" );
1870
+
1871
+ if (media -> sdes_in && m -> sdes_in .length != media -> sdes_in -> length )
1872
+ redis_update_call_crypto_sync_sdes_params (& m -> sdes_in , media -> sdes_in );
1873
+ if (media -> sdes_out && m -> sdes_out .length != media -> sdes_out -> length )
1874
+ redis_update_call_crypto_sync_sdes_params (& m -> sdes_in , media -> sdes_in );
1875
+
1815
1876
return 0 ;
1816
1877
}
1817
1878
1818
- static int redis_update_call_maps (struct call * c , redis_call_t * redis_call ) {
1879
+ static int redis_update_call_media (struct call * c , redis_call_t * redis_call ) {
1819
1880
struct call_media * m = NULL ;
1820
- struct endpoint_map * ep ;
1821
1881
redis_call_media_t * media ;
1822
- redis_call_media_endpoint_map_t * rcep ;
1823
- GList * ml , * epl , * rcepl ;
1882
+ GList * ml ;
1824
1883
1825
1884
for (ml = c -> medias .head ; ml ; ml = ml -> next ) {
1826
1885
m = ml -> data ;
1827
1886
media = g_queue_peek_nth (redis_call -> media , m -> unique_id );
1828
- if (!media )
1887
+ if (!media ) {
1888
+ rlog (LOG_WARNING , "Failed to update data for call ID '" STR_FORMAT_M "' from Redis: missing media %u" ,
1889
+ STR_FMT_M (& c -> callid ), m -> unique_id );
1829
1890
continue ; /* weird... */
1830
- for (epl = m -> endpoint_maps .head ; epl ; epl = epl -> next ) {
1831
- ep = epl -> data ;
1832
- for (rcepl = media -> endpoint_maps -> head ; rcepl ; rcepl = rcepl -> next ) {
1833
- rcep = rcepl -> data ;
1834
- if (rcep -> unique_id != ep -> unique_id )
1835
- continue ;
1836
- ep -> wildcard = rcep -> wildcard ;
1837
- endpoint_parse_any (& ep -> endpoint , rcep -> endpoint -> s );
1838
- }
1839
1891
}
1840
- /* update some media fields here, while we have the media */
1841
- if (!m -> ptime )
1842
- m -> ptime = media -> ptime ;
1843
- m -> media_flags = media -> media_flags ;
1892
+ if (redis_update_call_maps (m , media )) {
1893
+ rlog (LOG_WARNING , "Failed to update data for call ID '" STR_FORMAT_M "' from Redis: error in update maps" ,
1894
+ STR_FMT_M (& c -> callid ));
1895
+ return -1 ;
1896
+ }
1897
+ if (redis_update_call_payloads (m , media )) {
1898
+ rlog (LOG_WARNING , "Failed to update data for call ID '" STR_FORMAT_M "' from Redis: error in update payloads" ,
1899
+ STR_FMT_M (& c -> callid ));
1900
+ return -1 ;
1901
+ }
1902
+ if (redis_update_call_crypto (m , media )) {
1903
+ rlog (LOG_WARNING , "Failed to update data for call ID '" STR_FORMAT_M "' from Redis: error in update crypto" ,
1904
+ STR_FMT_M (& c -> callid ));
1905
+ return -1 ;
1906
+ }
1844
1907
}
1908
+
1845
1909
return 0 ;
1846
1910
}
1847
1911
@@ -1880,12 +1944,8 @@ static void redis_update_call_details(struct redis *r, struct call *c) {
1880
1944
if (redis_update_call_tags (c , redis_call ))
1881
1945
goto fail ;
1882
1946
1883
- err = "failed to update maps" ;
1884
- if (redis_update_call_maps (c , redis_call ))
1885
- goto fail ;
1886
-
1887
1947
err = "failed to update payload data" ;
1888
- if (redis_update_call_payloads (c , redis_call ))
1948
+ if (redis_update_call_media (c , redis_call ))
1889
1949
goto fail ;
1890
1950
1891
1951
goto done ;
0 commit comments