Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
8154c61f
You need to sign in or sign up before continuing.
Commit
8154c61f
authored
Mar 16, 2026
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了验证1s一次,减少了部分bug
parent
8cd573f4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
4 deletions
+15
-4
main
build/main
+0
-0
mylog.h
modules/logger/mylog.h
+1
-1
mqtt_verify.c
modules/mqtt/mqtt_verify.c
+13
-2
zlog.conf
zlog.conf
+1
-1
No files found.
build/main
View file @
8154c61f
No preview for this file type
modules/logger/mylog.h
View file @
8154c61f
...
...
@@ -6,7 +6,7 @@ int mylog_init();
#ifdef LOG_PRODUCTION
#define my_zlog_debug(...) ((void)0)
#define my_zlog_info(...) ((void)0)
#define my_zlog
_info(...) ((void)0)
#else
void
my_zlog_debug
(
const
char
*
format
,
...)
;
void
my_zlog_info
(
const
char
*
format
,
...)
;
...
...
modules/mqtt/mqtt_verify.c
View file @
8154c61f
...
...
@@ -29,7 +29,9 @@ static bool s_secret_key_index = TRUE;//用于判断是否对比topic
static
char
s_pending_verify_token
[
1024
];
static
char
s_last_seen_token
[
1024
];
/* 用于判断token是否变化(首次启动默认全0) */
static
int
s_verify_retry_count
=
0
;
static
time_t
s_verify_retry_after_time
=
0
;
/* 允许发起重试的时间戳,0 表示无待重试 */
#define VERIFY_RETRY_MAX 3
#define VERIFY_RETRY_INTERVAL_SEC 1
int
g_verify_index
=
0
;
//判断是否验证成功
pthread_mutex_t
g_verify_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
//线程锁
...
...
@@ -111,6 +113,14 @@ int receive_jwt(cJSON *body) {
return
1
;
}
/* 有待重试且已过 1s:等有消息进来时再发重试,不阻塞 */
if
(
s_verify_retry_count
>
0
&&
s_verify_retry_count
<
VERIFY_RETRY_MAX
&&
s_verify_retry_after_time
>
0
&&
time
(
NULL
)
>=
s_verify_retry_after_time
)
{
s_verify_retry_after_time
=
0
;
send_jwtser
(
s_pending_verify_token
);
my_zlog_notice
(
"距上次失败已过%d秒,发起第%d次重试验证"
,
VERIFY_RETRY_INTERVAL_SEC
,
s_verify_retry_count
+
1
);
}
/*
* token 变化触发验证策略:
* - 首次启动(s_last_seen_token 为空)只保存,不验证,确保下一次必定“有变化”再验证
...
...
@@ -208,13 +218,14 @@ int message2006_verify(cJSON *body){
strcpy
(
s_secret_key
,
s_pending_verify_token
);
s_secret_key_index
=
FALSE
;
s_verify_retry_count
=
0
;
s_verify_retry_after_time
=
0
;
}
else
{
/* 仅当 onlyid 匹配时视为本次验证的回复,否则可能是旧包 */
if
(
strcmp
(
onlyid
,
s_only_id_middle
)
==
0
)
{
s_verify_retry_count
++
;
if
(
s_verify_retry_count
<
VERIFY_RETRY_MAX
)
{
my_zlog_notice
(
"验证不通过,第%d次
重试"
,
s_verify_retry_count
);
s
end_jwtser
(
s_pending_verify_token
)
;
my_zlog_notice
(
"验证不通过,第%d次
,将在下次收到消息且距本次超过%ds后重试"
,
s_verify_retry_count
,
VERIFY_RETRY_INTERVAL_SEC
);
s
_verify_retry_after_time
=
time
(
NULL
)
+
VERIFY_RETRY_INTERVAL_SEC
;
}
else
{
my_zlog_warn
(
"topic验证超过%d次不通过,禁止使用"
,
VERIFY_RETRY_MAX
);
g_verify_index
=
1
;
...
...
zlog.conf
View file @
8154c61f
...
...
@@ -9,4 +9,4 @@ file perms = 600
millisecond
=
"%d(%Y-%m-%d %H:%M:%S).%ms [%V] %m%n"
[
rules
]
my_log
.*
"/home/orangepi/car/master/log/log_2026-03-1
4
.log"
;
millisecond
my_log
.*
"/home/orangepi/car/master/log/log_2026-03-1
6
.log"
;
millisecond
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment