Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

help understanding types in proxy_on_* functions #356

Closed
nilslice opened this issue Jan 2, 2020 · 2 comments
Closed

help understanding types in proxy_on_* functions #356

nilslice opened this issue Jan 2, 2020 · 2 comments

Comments

@nilslice
Copy link

nilslice commented Jan 2, 2020

In my attempts to get a basic Rust wasm filter running, I found it difficult to see how the C++ examples translated to what the WIP Rust sdk would look like - at the very least to know what are some VM functions I can hook into from Rust. Aside from the functions defined in api/wasm/rust/src/lib.rs, I was able to find the following (and a few more from module env imports) by disassembling both my Rust wasm and the example C++ wasm output.

Is there any reference material where I can get more specific information about how to translate the i32 params into some data I can work with in Rust? I have been able to start the compiled wasm in envoy, and see the logs from these Rust stubs below, but the proxy_on_request_headers call seems to hang with the return value I'm sending back. This is where I've hit a wall.. I'm not sure what the next hook / VM is expecting to get back.

The stubs I've got in Rust:

#[no_mangle]
fn proxy_on_queue_ready(p0: i32, p1: i32) {
    log::info!("rust: `proxy_on_queue_ready` called, params: p0={} p1={}", p0, p1);
}

#[no_mangle]
fn proxy_on_grpc_close(p0: i32, p1: i32, p2: i32) {
    log::info!("rust: `proxy_on_grpc_close` called, params: p0={} p1={} p2={}", p0, p1, p2);
}

#[no_mangle]
fn proxy_on_grpc_receive(p0: i32, p1: i32, p2: i32) {
    log::info!("rust: `proxy_on_grpc_receive` called, params: p0={} p1={} p2={}", p0, p1, p2);
}

#[no_mangle]
fn proxy_on_grpc_receive_trailing_metadata(p0: i32, p1: i32, p2: i32) {
    log::info!(
        "rust: `proxy_on_grpc_receive_trailing_metadata` called, params: p0={} p1={} p2={}",
        p0, p1, p2
    );
}

#[no_mangle]
fn proxy_on_grpc_receive_initial_metadata(p0: i32, p1: i32, p2: i32) {
    log::info!(
        "rust: `proxy_on_grpc_receive_initial_metadata` called, params: p0={} p1={} p2={}",
        p0, p1, p2
    );
}

#[no_mangle]
fn proxy_on_grpc_create_initial_metadata(p0: i32, p1: i32, p2: i32) {
    log::info!(
        "rust: `proxy_on_grpc_create_initial_metadata` called, params: p0={} p1={} p2={}",
        p0, p1, p2
    );
}

#[no_mangle]
fn proxy_on_http_call_response(p0: i32, p1: i32, p2: i32, p3: i32, p4: i32) {
    log::info!(
        "rust: `proxy_on_http_call_response` calledcalled, params: p0={} p1={} p2={} p3={} p4={}",
        p0, p1, p2, p3, p4
    );
}

#[no_mangle]
fn proxy_on_delete(p0: i32) {
    log::info!("rust: `proxy_on_delete` called");
}

#[no_mangle]
fn proxy_on_log(p0: i32) {
    log::info!("rust: `proxy_on_log` called, params: p0={}", p0);
}

#[no_mangle]
fn proxy_on_done(p0: i32) -> i32 {
    log::info!("rust: `proxy_on_done` called, params: p0={}", p0);
    -999
}

#[no_mangle]
fn proxy_on_response_trailers(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_response_trailers` called, params: p0={} p1={}", p0, p1);
    -999
}

#[no_mangle]
fn proxy_on_response_body(p0: i32, p1: i32, p2: i32) -> i32 {
    log::info!("rust: `proxy_on_response_body` called, params: p0={} p1={} p2={}", p0, p1, p2);
    -999
}

#[no_mangle]
fn proxy_on_response_metadata(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_response_metadata` called, params: p0={} p1={}", p0, p1);
    -999
}

#[no_mangle]
fn proxy_on_response_headers(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_response_headers` called, params: p0={} p1={}", p0, p1);
    -999
}

#[no_mangle]
fn proxy_on_request_trailers(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_request_trailers` called, params: p0={} p1={}", p0, p1);
    -999
}

#[no_mangle]
fn proxy_on_request_body(p0: i32, p1: i32, p2: i32) -> i32 {
    log::info!("rust: `proxy_on_request_body` called, params: p0={} p1={} p2={}", p0, p1, p2);
    -999
}

#[no_mangle]
fn proxy_on_request_metadata(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_request_metadata` called, params: p0={} p1={}", p0, p1);
    -999
}

#[no_mangle]
fn proxy_on_request_headers(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_request_headers` called, params: p0={} p1={}", p0, p1);
    -999
}

#[no_mangle]
fn proxy_on_upstream_connection_close(p0: i32, p1: i32) {
    log::info!("rust: `proxy_on_upstream_connection_close` called, params: p0={} p1={}", p0, p1);
}

#[no_mangle]
fn proxy_on_downstream_connection_close(p0: i32, p1: i32) {
    log::info!("rust: `proxy_on_downstream_connection_close` called, params: p0={} p1={}", p0, p1);
}

#[no_mangle]
fn proxy_on_upstream_data(p0: i32, p1: i32, p2: i32) -> i32 {
    log::info!("rust: `proxy_on_upstream_data` called, params: p0={} p1={} p2={}", p0, p1, p2);
    -999
}

#[no_mangle]
fn proxy_on_downstream_data(p0: i32, p1: i32, p2: i32) -> i32 {
    log::info!("rust: `proxy_on_downstream_data` called, params: p0={} p1={} p2={}", p0, p1, p2);
    -999
}

#[no_mangle]
fn proxy_on_new_connection(p0: i32) -> i32 {
    log::info!("rust: `proxy_on_new_connection` called, params: p0={}", p0);
    -999
}

#[no_mangle]
fn proxy_on_create(p0: i32, p1: i32) {
    log::info!("rust: `proxy_on_create` called, params: p0={} p1={}", p0, p1);
}

#[no_mangle]
fn proxy_on_tick(p0: i32) {
    log::info!("rust: `proxy_on_tick` called, params: p0={}", p0);
}

#[no_mangle]
fn proxy_on_configure(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_configure` called, params: p0={} p1={}", p0, p1);
    -999
}

#[no_mangle]
fn proxy_on_start(p0: i32, p1: i32) -> i32 {
    log::info!("rust: `proxy_on_start` called, params: p0={} p1={}", p0, p1);
    -999
}

Any tips/pointers to discovering what the i32 mean would be greatly appreciated!

Btw, if there hasn't yet been a design set for the Rust SDK, i'd be happy to share some ideas. Thanks again for the work thus far.

Edit:
Ok, I see proxy_wasm_api.h & proxy_wasm_externs.h and can make some assumptions... still, any pointers appreciated 👍

@nilslice
Copy link
Author

nilslice commented Jan 3, 2020

I've made a bit of progress on the Rust side of things, though admittedly only through hacking around. If there is a chance to get a bit of a review or a quick check if this is useful to continue on, I'd appreciate it.

Thanks @PiotrSikora!

@jplevyak
Copy link
Contributor

The spec is under review at proxy-wasm/spec#1
Comments and requests for clarification welcome!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants