Browse code

dispatcher: check reload delta in functions building new routing structure

Daniel-Constantin Mierla authored on 24/01/2022 10:32:31
Showing 1 changed files
... ...
@@ -952,6 +952,16 @@ static int ds_warn_fixup(void **param, int param_no)
952 952
 
953 953
 static int ds_reload(sip_msg_t *msg)
954 954
 {
955
+	if(ds_rpc_reload_time==NULL) {
956
+		LM_ERR("not ready for reload\n");
957
+		return -1;
958
+	}
959
+	if(*ds_rpc_reload_time!=0 && *ds_rpc_reload_time > time(NULL) - ds_reload_delta) {
960
+		LM_ERR("ongoing reload\n");
961
+		return -1;
962
+	}
963
+	*ds_rpc_reload_time = time(NULL);
964
+
955 965
 	if(!ds_db_url.s) {
956 966
 		if(ds_load_list(dslistfile) != 0)
957 967
 			LM_ERR("Error reloading from list\n");
... ...
@@ -1859,6 +1869,18 @@ static void dispatcher_rpc_add(rpc_t *rpc, void *ctx)
1859 1869
 	str dest;
1860 1870
 	str attrs = STR_NULL;
1861 1871
 
1872
+	if(ds_rpc_reload_time==NULL) {
1873
+		LM_ERR("Not ready for rebuilding destinations list\n");
1874
+		rpc->fault(ctx, 500, "Not ready for reload");
1875
+		return;
1876
+	}
1877
+	if(*ds_rpc_reload_time!=0 && *ds_rpc_reload_time > time(NULL) - ds_reload_delta) {
1878
+		LM_ERR("ongoing reload\n");
1879
+		rpc->fault(ctx, 500, "Ongoing reload");
1880
+		return;
1881
+	}
1882
+	*ds_rpc_reload_time = time(NULL);
1883
+
1862 1884
 	flags = 0;
1863 1885
 
1864 1886
 	nparams = rpc->scan(ctx, "dS*dS", &group, &dest, &flags, &attrs);
... ...
@@ -1890,6 +1912,18 @@ static void dispatcher_rpc_remove(rpc_t *rpc, void *ctx)
1890 1912
 	int group;
1891 1913
 	str dest;
1892 1914
 
1915
+	if(ds_rpc_reload_time==NULL) {
1916
+		LM_ERR("Not ready for rebuilding destinations list\n");
1917
+		rpc->fault(ctx, 500, "Not ready for reload");
1918
+		return;
1919
+	}
1920
+	if(*ds_rpc_reload_time!=0 && *ds_rpc_reload_time > time(NULL) - ds_reload_delta) {
1921
+		LM_ERR("ongoing reload\n");
1922
+		rpc->fault(ctx, 500, "Ongoing reload");
1923
+		return;
1924
+	}
1925
+	*ds_rpc_reload_time = time(NULL);
1926
+
1893 1927
 	if(rpc->scan(ctx, "dS", &group, &dest) < 2) {
1894 1928
 		rpc->fault(ctx, 500, "Invalid Parameters");
1895 1929
 		return;