From e4c9facb167bd0d0df6721ff98d39a9f3c8f4b43 Mon Sep 17 00:00:00 2001
From: Dmitriy Naidolinskiy <dmitriy.naidolinskiy@demlabs.net>
Date: Fri, 24 Dec 2021 09:47:46 +0000
Subject: [PATCH] feature 5344 1

---
 CMakeLists.txt                               |  2 +-
 modules/channel/chain/dap_stream_ch_chain.c  | 14 ++++++++++
 modules/global-db/dap_chain_global_db_hist.c | 28 ++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 04e29ccfcb..4d2044726a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ project(cellframe-sdk C)
 cmake_minimum_required(VERSION 3.10)
 
 set(CMAKE_C_STANDARD 11)
-set(CELLFRAME_SDK_NATIVE_VERSION "3.0-11")
+set(CELLFRAME_SDK_NATIVE_VERSION "3.0-12")
 
 add_definitions ("-DCELLFRAME_SDK_VERSION=\"${CELLFRAME_SDK_NATIVE_VERSION}\"")
 
diff --git a/modules/channel/chain/dap_stream_ch_chain.c b/modules/channel/chain/dap_stream_ch_chain.c
index 85bcc06fe1..7cefb1817f 100644
--- a/modules/channel/chain/dap_stream_ch_chain.c
+++ b/modules/channel/chain/dap_stream_ch_chain.c
@@ -113,6 +113,9 @@ static void s_gdb_in_pkt_error_worker_callback(dap_worker_t *a_thread, void *a_a
 static bool s_debug_more=false;
 static uint_fast16_t s_update_pack_size=100; // Number of hashes packed into the one packet
 static uint_fast16_t s_skip_in_reactor_count=50; // Number of hashes packed to skip in one reactor loop callback out packet
+static uint16_t s_size_ban_groups = 0;
+static char **s_list_ban_groups = NULL;
+
 /**
  * @brief dap_stream_ch_chain_init
  * @return
@@ -124,6 +127,7 @@ int dap_stream_ch_chain_init()
             s_stream_ch_packet_out);
     s_debug_more = dap_config_get_item_bool_default(g_config,"stream_ch_chain","debug_more",false);
     s_update_pack_size = dap_config_get_item_int16_default(g_config,"stream_ch_chain","update_pack_size",100);
+    s_list_ban_groups = dap_config_get_array_str(g_config, "general", "ban_list_sync_groups", &s_size_ban_groups);
 
     return 0;
 }
@@ -652,6 +656,16 @@ static bool s_gdb_in_pkt_proc_callback(dap_proc_thread_t *a_thread, void *a_arg)
         for (size_t i = 0; i < l_data_obj_count; i++) {
             // obj to add
             dap_store_obj_t *l_obj = l_store_obj + i;
+            if (s_list_ban_groups) {
+                int l_ret = 0;
+                for (int i = 0; i < s_size_ban_groups; i++) {
+                    if (!dap_fnmatch(s_list_ban_groups[i], l_obj->group, FNM_NOESCAPE)) {
+                        l_ret = -1;
+                        break;
+                    }
+                }
+                if (l_ret == -1) continue;
+            }
             l_group_changed = strcmp(l_last_group, l_obj->group) || l_last_type != l_obj->type;
             // Send remote side notification about received obj
             if (l_sync_request->request.node_addr.uint64 &&
diff --git a/modules/global-db/dap_chain_global_db_hist.c b/modules/global-db/dap_chain_global_db_hist.c
index 6ff0e78710..21da7d5321 100644
--- a/modules/global-db/dap_chain_global_db_hist.c
+++ b/modules/global-db/dap_chain_global_db_hist.c
@@ -28,6 +28,9 @@ typedef struct dap_tx_data{
 
 #define LOG_TAG "dap_chain_global_db_hist"
 
+static uint16_t s_size_ban_list = 0;
+static char **s_ban_list = NULL;
+
 /**
  * @brief Packs members of a_rec structure into a single string.
  * 
@@ -273,6 +276,31 @@ dap_db_log_list_t* dap_db_log_list_start(dap_chain_node_addr_t a_addr, int a_fla
     }
     dap_list_free(l_groups_masks);
 
+    static int l_try_read_ban_list = 0;
+
+        if (!l_try_read_ban_list) {
+                s_ban_list = dap_config_get_array_str(g_config, "general", "ban_list_sync_groups", &s_size_ban_list);
+                l_try_read_ban_list = 1;
+        }
+
+        /* delete groups from ban list */
+        if (s_size_ban_list > 0) {
+            for (dap_list_t *l_groups = l_dap_db_log_list->groups; l_groups; ) {
+                int found = 0;
+                for (int i = 0; i < s_size_ban_list; i++) {
+                    if (dap_fnmatch(s_ban_list[i], l_groups->data, FNM_NOESCAPE)) {
+                        dap_list_t *l_tmp = l_groups->next;
+                        dap_list_delete_link(l_dap_db_log_list->groups, l_groups);
+                        l_groups = l_tmp;
+                        found = 1;
+                        break;
+                    }
+                }
+                if (found) continue;
+                l_groups = dap_list_next(l_groups);
+            }
+        }
+
     for (dap_list_t *l_groups = l_dap_db_log_list->groups; l_groups; l_groups = dap_list_next(l_groups)) {
         dap_db_log_list_group_t *l_replace = DAP_NEW_Z(dap_db_log_list_group_t);
         l_replace->name = (char *)l_groups->data;
-- 
GitLab