@@ -19,13 +19,15 @@ pub struct Limiter {
1919 internal : StoreLimits ,
2020}
2121
22- impl Default for Limiter {
23- fn default ( ) -> Self {
24- Limiter :: new ( 1 , 1 , 1 )
22+ impl Limiter {
23+ pub fn for_wasip2 ( ) -> Self {
24+ Self :: new ( 100 , 100 , 100 )
25+ }
26+
27+ pub fn for_wasip1 ( ) -> Self {
28+ Self :: new ( 1 , 1 , 1 )
2529 }
26- }
2730
28- impl Limiter {
2931 fn new ( max_instances : usize , max_memories : usize , max_tables : usize ) -> Self {
3032 Limiter {
3133 memory_allocated : 0 ,
@@ -99,7 +101,6 @@ pub struct ComponentCtx {
99101 pub wasi_random : wasmtime_wasi:: random:: WasiRandomCtx ,
100102 pub ( crate ) session : Session ,
101103 guest_profiler : Option < Box < GuestProfiler > > ,
102- limiter : Limiter ,
103104}
104105
105106/// An extension trait for users of `ComponentCtx` to access the session.
@@ -132,7 +133,7 @@ impl ComponentCtx {
132133 }
133134
134135 pub fn limiter ( & self ) -> & Limiter {
135- & self . limiter
136+ self . session . limiter ( )
136137 }
137138
138139 pub fn close_downstream_response_sender ( & mut self , resp : Response < Body > ) {
@@ -159,7 +160,6 @@ impl ComponentCtx {
159160 wasi_random : wasmtime_wasi:: random:: WasiRandomCtx :: default ( ) ,
160161 session,
161162 guest_profiler : guest_profiler. map ( Box :: new) ,
162- limiter : Limiter :: new ( 100 , 100 , 100 ) ,
163163 } ;
164164 let mut store = Store :: new ( ctx. engine ( ) , wasm_ctx) ;
165165 store. set_epoch_deadline ( 1 ) ;
@@ -182,7 +182,7 @@ impl ComponentCtx {
182182 Ok ( UpdateDeadline :: Yield ( 1 ) )
183183 } ) ;
184184
185- store. limiter ( |ctx| & mut ctx. limiter ) ;
185+ store. limiter ( |ctx| ctx. session . limiter_mut ( ) ) ;
186186 Ok ( store)
187187 }
188188}
@@ -207,7 +207,6 @@ pub struct WasmCtx {
207207 wasi_nn : WasiNnCtx ,
208208 session : Session ,
209209 guest_profiler : Option < Box < GuestProfiler > > ,
210- limiter : Limiter ,
211210}
212211
213212impl WasmCtx {
@@ -228,7 +227,7 @@ impl WasmCtx {
228227 }
229228
230229 pub fn limiter ( & self ) -> & Limiter {
231- & self . limiter
230+ self . session . limiter ( )
232231 }
233232}
234233
@@ -260,7 +259,6 @@ pub(crate) fn create_store(
260259 wasi_nn,
261260 session,
262261 guest_profiler : guest_profiler. map ( Box :: new) ,
263- limiter : Limiter :: default ( ) ,
264262 } ;
265263 let mut store = Store :: new ( ctx. engine ( ) , wasm_ctx) ;
266264 store. set_epoch_deadline ( 1 ) ;
@@ -283,7 +281,7 @@ pub(crate) fn create_store(
283281 Ok ( UpdateDeadline :: Yield ( 1 ) )
284282 } ) ;
285283
286- store. limiter ( |ctx| & mut ctx. limiter ) ;
284+ store. limiter ( |ctx| ctx. session . limiter_mut ( ) ) ;
287285 Ok ( store)
288286}
289287
0 commit comments