@@ -4,6 +4,7 @@ use crate::filter::Context;
4
4
use crate :: handler:: Handler ;
5
5
use crate :: protocol:: { Flags , Message , RCode } ;
6
6
use crate :: { Error as ZError , Result } ;
7
+ use std:: net:: SocketAddr ;
7
8
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
8
9
use std:: sync:: Arc ;
9
10
@@ -85,18 +86,25 @@ fn convert_error_to_message(
85
86
}
86
87
87
88
#[ inline]
88
- async fn handle_ < H > ( req : & Message , h : Arc < H > ) -> Result < Message >
89
+ async fn handle_ < H > ( peer : SocketAddr , req : & Message , h : Arc < H > ) -> Result < Message >
89
90
where
90
91
H : Handler ,
91
92
{
92
93
let mut req = Clone :: clone ( req) ;
93
94
let mut ctx = Context :: default ( ) ;
95
+ ctx. peer . replace ( peer) ;
96
+
94
97
h. handle ( & mut ctx, & mut req)
95
98
. await ?
96
99
. ok_or_else ( || anyhow ! ( ZError :: ResolveNothing ) )
97
100
}
98
101
99
- pub ( super ) async fn handle < H , C > ( req : Message , h : Arc < H > , cache : Option < Arc < C > > ) -> ( Message , bool )
102
+ pub ( super ) async fn handle < H , C > (
103
+ peer : SocketAddr ,
104
+ req : Message ,
105
+ h : Arc < H > ,
106
+ cache : Option < Arc < C > > ,
107
+ ) -> ( Message , bool )
100
108
where
101
109
H : Handler ,
102
110
C : LoadingCache ,
@@ -106,7 +114,7 @@ where
106
114
}
107
115
108
116
let ( res, cached) = match cache. as_deref ( ) {
109
- None => ( handle_ ( & req, h) . await , false ) ,
117
+ None => ( handle_ ( peer , & req, h) . await , false ) ,
110
118
Some ( lc) => {
111
119
let cached = Arc :: new ( AtomicBool :: new ( true ) ) ;
112
120
@@ -115,7 +123,7 @@ where
115
123
let cached = Clone :: clone ( & cached) ;
116
124
lc. try_get_with_fixed ( req, move |req| {
117
125
cached. store ( false , Ordering :: SeqCst ) ;
118
- async move { handle_ ( & req, h) . await }
126
+ async move { handle_ ( peer , & req, h) . await }
119
127
} )
120
128
. await
121
129
} ;
0 commit comments