聊一聊当前radius 配置更新

目前在写radius 相关c代码的时候,整理了一份基本逻辑

1、初始化log,读取系统配置文件,

message sql_gorm
{
	required uint32 db_count = 1[default=10];
	required uint32 db_point = 2[default=2];
}
Eagle_SqlGorm *cfgsqlgorm = NULL                                       			  
system_conf_get((const ProtobufCMessage **)&cfgsqlgorm){
	desc = Eagle__sql_gorm__descriptor
	file = "/home/3party/" + name + ".system.xml"
	xml2pb(file, desc, cfgsqlgorm_tmp)//读取system.xml文件里面的配置,如果没有就是用proto的默认配置
	*cfgsqlgorm = cfgsqlgorm_tmp
}

2、signal_setup_callback()注册信号 terminal exit等函数; 读取容易变化的配置

bug_signal(SIGSEGV,SIGABRT,SIGFPE, SIGILL,SIGBUS,SIGINT,SIGQUIT,SIGTERM,SIGPIPE)

zSIGTERM SIGINT  SIGQUIT 对应terminal函数

SIGSEGV SIGFPE SIGBUS 对应执行执行exit函数,记住 一开始需要将signalreset  signal(sig, SIG_DFL);

3、初始化网络事件库以及ipc消息回调初始化

ipc_context.comm_init = s_udp_init;
ipc_context.comm_send = s_udp_send;
ipc_context.comm_handle = s_udp_handle_fd

ipc_context.comm_init(modid, inst_id)


ipc_context.modid = modid;
ipc_context.inst_id = inst_id;
ipc_context.dev_type = client;

对于 modid 一般使用端口号,每个进程一个端口号
定义一个全局的modid conf文件,每个进程一个端口号
所以初始化时,当前进程的modid需要和配置文件里面运行的进行对比。


对于s_udp_init 初始化的时候注册此modid的回调函数

ipc_callcb读取数据报文,根据hdr头部数据来进行
ipc_frag_alloc
ipc_defrag 获取数据
直到获取的数据是符合一开始的data_len 取出data指针


当收到消息时:
根据msg_type执行对应的callback回调。
protobuf_c_message_unpack
list_node->call_func(buf, len, msg, (void *)hdr);
protobuf_c_message_free_unpacked

4、注册rpc消息回调

new_node->msg_type = type;
new_node->cb_func = func;
new_node->proto_desc = proto_desc;
new_node->opt_cfg = enable;
list_add_tail(&new_node->list, &ipc_context.ipc_callback);

5、初始化定时器任务

6、注册订阅需要关注的配置文件,数据库


1、初始化订阅节点
s_conf_ctx.diff_file = diff_alloc_files_t();

2、将file sql 假如到订阅节点中
diff_add_file(s_conf_ctx.diff_file, filename, crc_sum);

2、获取订阅到的新数据
s_conf_ctx.file_changed = diff_get_changed_files(s_conf_ctx.diff_file)

3、确认此文件是否更新
diff_query_file_state(s_conf_ctx.file_changed, filename); {
	执行对应动作
}

4、将更新的数据添加到本地缓存 更新数据
diff_merge_files(file_list, changed_file_list);

---以上核心数据结构就是一个rbtree 以及md5计算当前文件version

每个文件key为filename  data为MD5version 挂载在root上

---get_changed_files 实际上就是遍历root节点下的所有k-v,查看对应文件的MD5version是否改变。
如果改变就添加到 file-chang的root下
---- 最后merge 就是更新原始diff-file 的MD5version 等待新的订阅消息通知

7、初始化心跳

8、loop event

 

posted @ 2024-01-14 20:09  codestacklinuxer  阅读(3)  评论(0编辑  收藏  举报