A lexicon-driven AppView for ATProto. happyview.dev
backfill firehose jetstream atproto appview oauth lexicon
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: use async calls to get host secrets

Trezy effa3677 760faafe

+15 -38
+15 -38
src/plugin/host/bindings.rs
··· 34 34 pub fn register_host_functions(linker: &mut Linker<PluginState>) -> Result<(), wasmtime::Error> { 35 35 // Sync functions 36 36 linker.func_wrap("env", "host_log", host_log)?; 37 - linker.func_wrap("env", "host_get_secret", host_get_secret)?; 37 + 38 + // host_get_secret must be async because it calls alloc on an async store 39 + linker.func_wrap_async( 40 + "env", 41 + "host_get_secret", 42 + |mut caller: wasmtime::Caller<'_, PluginState>, (name_ptr, name_len): (i32, i32)| { 43 + Box::new(async move { host_get_secret_impl(&mut caller, name_ptr, name_len).await }) 44 + }, 45 + )?; 38 46 39 47 // Async functions - HTTP 40 48 linker.func_wrap_async( ··· 174 182 175 183 /// Host function: get a secret value by name 176 184 /// Returns a packed i64: (ptr << 32) | len, or 0 on error 177 - fn host_get_secret( 178 - mut caller: wasmtime::Caller<'_, PluginState>, 185 + async fn host_get_secret_impl( 186 + caller: &mut wasmtime::Caller<'_, PluginState>, 179 187 name_ptr: i32, 180 188 name_len: i32, 181 189 ) -> i64 { 182 - let memory = match caller.data().memory { 183 - Some(m) => m, 184 - None => return 0, 185 - }; 186 - let alloc = match &caller.data().alloc { 187 - Some(a) => a.clone(), 190 + let name = match read_guest_string(caller, name_ptr, name_len) { 191 + Some(n) => n, 188 192 None => return 0, 189 193 }; 190 194 191 - let mem_data = memory.data(&caller); 192 - let mem_size = mem_data.len(); 193 - 194 - let (name_start, name_end) = match check_bounds(name_ptr as usize, name_len as usize, mem_size) 195 - { 196 - Ok(bounds) => bounds, 197 - Err(_) => return 0, 198 - }; 199 - 200 - let name = match std::str::from_utf8(&mem_data[name_start..name_end]) { 201 - Ok(s) => s, 202 - Err(_) => return 0, 203 - }; 204 - 205 - let value = match caller.data().secrets.get(name) { 195 + let value = match caller.data().secrets.get(&name) { 206 196 Some(v) => v.clone(), 207 197 None => return 0, 208 198 }; 209 199 210 - let len = value.len() as u32; 211 - let ptr = match alloc.call(&mut caller, len) { 212 - Ok(p) if p != 0 => p, 213 - _ => return 0, 214 - }; 215 - 216 - let mem_data = memory.data_mut(&mut caller); 217 - if check_bounds(ptr as usize, len as usize, mem_data.len()).is_err() { 218 - return 0; 219 - } 220 - 221 - mem_data[ptr as usize..(ptr as usize + len as usize)].copy_from_slice(value.as_bytes()); 222 - 223 - ((ptr as i64) << 32) | (len as i64) 200 + write_guest_response(caller, value.as_bytes()).await 224 201 } 225 202 226 203 // ============================================================================