@@ -40,6 +40,7 @@ use tdn::{
40
40
} ,
41
41
} ;
42
42
use tokio:: sync:: { mpsc:: Sender , RwLock } ;
43
+ use tokio:: time:: { sleep, Duration } ;
43
44
44
45
use crate :: {
45
46
account:: { get_indexer, indexer_healthy} ,
@@ -57,7 +58,9 @@ pub static P2P_SENDER: Lazy<RwLock<Vec<ChannelRpcSender>>> = Lazy::new(|| RwLock
57
58
pub async fn send ( method : & str , params : Vec < RpcParam > , gid : GroupId ) {
58
59
let senders = P2P_SENDER . read ( ) . await ;
59
60
if !senders. is_empty ( ) {
60
- senders[ 0 ] . send ( rpc_request ( 0 , method, params, gid) ) . await ;
61
+ senders[ 0 ]
62
+ . send_timeout ( rpc_request ( 0 , method, params, gid) , 100 )
63
+ . await ;
61
64
}
62
65
}
63
66
@@ -69,44 +72,53 @@ pub async fn stop_network() {
69
72
debug ! ( "RESTART NEW P2P NETWORK" ) ;
70
73
senders[ 0 ] . send ( rpc_request ( 0 , "p2p-stop" , vec ! [ ] , 0 ) ) . await ;
71
74
drop ( senders) ;
72
- tokio :: time :: sleep ( std :: time :: Duration :: from_secs ( P2P_RESTART_TIME ) ) . await ;
75
+ sleep ( Duration :: from_secs ( P2P_RESTART_TIME ) ) . await ;
73
76
}
74
77
}
75
78
76
- pub async fn report_conflict ( deployment : & str , channel : & str , conflict : i32 , start : i64 , end : i64 ) {
79
+ pub async fn report_conflict (
80
+ deployment : String ,
81
+ channel : String ,
82
+ conflict : i32 ,
83
+ start : i64 ,
84
+ end : i64 ,
85
+ ) {
77
86
let senders = P2P_SENDER . read ( ) . await ;
78
87
if senders. is_empty ( ) {
79
88
warn ! ( "NONE NETWORK WHEN REPORT CONFLICT" ) ;
80
89
} else {
81
90
senders[ 0 ]
82
- . send ( rpc_request (
83
- 0 ,
84
- "payg-report-conflict" ,
85
- vec ! [
86
- deployment. into( ) ,
87
- channel. into( ) ,
88
- conflict. into( ) ,
89
- start. into( ) ,
90
- end. into( ) ,
91
- ] ,
92
- 0 ,
93
- ) )
91
+ . send_timeout (
92
+ rpc_request (
93
+ 0 ,
94
+ "payg-report-conflict" ,
95
+ vec ! [
96
+ deployment. into( ) ,
97
+ channel. into( ) ,
98
+ conflict. into( ) ,
99
+ start. into( ) ,
100
+ end. into( ) ,
101
+ ] ,
102
+ 0 ,
103
+ ) ,
104
+ 100 ,
105
+ )
94
106
. await ;
95
107
drop ( senders) ;
96
108
}
97
109
}
98
110
99
111
async fn check_stable ( ) {
100
112
loop {
101
- tokio :: time :: sleep ( std :: time :: Duration :: from_secs ( P2P_STABLE_TIME ) ) . await ;
113
+ sleep ( Duration :: from_secs ( P2P_STABLE_TIME ) ) . await ;
102
114
let senders = P2P_SENDER . read ( ) . await ;
103
115
if senders. is_empty ( ) {
104
116
drop ( senders) ;
105
117
continue ;
106
118
} else {
107
119
debug ! ( "Check stable connections" ) ;
108
120
senders[ 0 ]
109
- . send ( rpc_request ( 0 , "p2p-stable" , vec ! [ ] , 0 ) )
121
+ . send_timeout ( rpc_request ( 0 , "p2p-stable" , vec ! [ ] , 0 ) , 100 )
110
122
. await ;
111
123
}
112
124
drop ( senders) ;
@@ -115,7 +127,7 @@ async fn check_stable() {
115
127
116
128
async fn report_metrics ( ) {
117
129
loop {
118
- tokio :: time :: sleep ( std :: time :: Duration :: from_secs ( P2P_METRICS_TIME ) ) . await ;
130
+ sleep ( Duration :: from_secs ( P2P_METRICS_TIME ) ) . await ;
119
131
let senders = P2P_SENDER . read ( ) . await ;
120
132
if senders. is_empty ( ) {
121
133
drop ( senders) ;
@@ -132,15 +144,15 @@ async fn report_metrics() {
132
144
133
145
async fn report_status ( ) {
134
146
loop {
135
- tokio :: time :: sleep ( std :: time :: Duration :: from_secs ( P2P_METRICS_STATUS_TIME ) ) . await ;
147
+ sleep ( Duration :: from_secs ( P2P_METRICS_STATUS_TIME ) ) . await ;
136
148
let senders = P2P_SENDER . read ( ) . await ;
137
149
if senders. is_empty ( ) {
138
150
drop ( senders) ;
139
151
continue ;
140
152
} else {
141
153
debug ! ( "Report projects status" ) ;
142
154
senders[ 0 ]
143
- . send ( rpc_request ( 0 , "project-report-status" , vec ! [ ] , 0 ) )
155
+ . send_timeout ( rpc_request ( 0 , "project-report-status" , vec ! [ ] , 0 ) , 100 )
144
156
. await ;
145
157
}
146
158
drop ( senders) ;
@@ -149,15 +161,15 @@ async fn report_status() {
149
161
150
162
async fn broadcast_healthy ( ) {
151
163
loop {
152
- tokio :: time :: sleep ( std :: time :: Duration :: from_secs ( P2P_BROADCAST_HEALTHY_TIME ) ) . await ;
164
+ sleep ( Duration :: from_secs ( P2P_BROADCAST_HEALTHY_TIME ) ) . await ;
153
165
let senders = P2P_SENDER . read ( ) . await ;
154
166
if senders. is_empty ( ) {
155
167
drop ( senders) ;
156
168
continue ;
157
169
} else {
158
170
debug ! ( "Report projects healthy" ) ;
159
171
senders[ 0 ]
160
- . send ( rpc_request ( 0 , "project-broadcast-healthy" , vec ! [ ] , 0 ) )
172
+ . send_timeout ( rpc_request ( 0 , "project-broadcast-healthy" , vec ! [ ] , 0 ) , 100 )
161
173
. await ;
162
174
}
163
175
drop ( senders) ;
0 commit comments