This is an automated email from the ASF dual-hosted git repository.
songxiaosheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git
The following commit(s) were added to refs/heads/master by this push:
new b1360ac [ISSUE dubbo#11900] part6 init dubbo-wasm-remoting-api module
(#295)
b1360ac is described below
commit b1360ac89c8f5b6c66b2c49f4d69c56138b585c8
Author: loongs-zhang <[email protected]>
AuthorDate: Mon Mar 25 20:31:59 2024 +0800
[ISSUE dubbo#11900] part6 init dubbo-wasm-remoting-api module (#295)
* [ISSUE dubbo#11900] part6 init dubbo-wasm-remoting-api module
* fix test
* fix import
---------
Co-authored-by: xiaosheng <[email protected]>
---
dubbo-wasm/dubbo-wasm-remoting-api/pom.xml | 62 +++++
.../remoting/transport/AbstractWasmChannel.java | 275 +++++++++++++++++++++
.../transport/AbstractWasmChannelTest.java | 106 ++++++++
.../org/apache/dubbo/wasm/test/TestHelper.java | 4 +
.../src/main/resources/rust_extensions.wasm | Bin 1685184 -> 1687720
bytes
.../src/main/rust-extensions/src/lib.rs | 87 +++++++
dubbo-wasm/pom.xml | 1 +
7 files changed, 535 insertions(+)
diff --git a/dubbo-wasm/dubbo-wasm-remoting-api/pom.xml
b/dubbo-wasm/dubbo-wasm-remoting-api/pom.xml
new file mode 100644
index 0000000..4335dde
--- /dev/null
+++ b/dubbo-wasm/dubbo-wasm-remoting-api/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>dubbo-wasm</artifactId>
+ <groupId>org.apache.dubbo.extensions</groupId>
+ <version>${revision}</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-wasm-remoting-api</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-api</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo.extensions</groupId>
+ <artifactId>dubbo-wasm-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo.extensions</groupId>
+ <artifactId>dubbo-wasm-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>../dubbo-wasm-test/src/main/resources</directory>
+ <includes>
+ <include>rust_extensions.wasm</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+</project>
diff --git
a/dubbo-wasm/dubbo-wasm-remoting-api/src/main/java/org/apache/dubbo/wasm/remoting/transport/AbstractWasmChannel.java
b/dubbo-wasm/dubbo-wasm-remoting-api/src/main/java/org/apache/dubbo/wasm/remoting/transport/AbstractWasmChannel.java
new file mode 100644
index 0000000..3d21818
--- /dev/null
+++
b/dubbo-wasm/dubbo-wasm-remoting-api/src/main/java/org/apache/dubbo/wasm/remoting/transport/AbstractWasmChannel.java
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.wasm.remoting.transport;
+
+import io.github.kawamuray.wasmtime.Extern;
+import io.github.kawamuray.wasmtime.Func;
+import io.github.kawamuray.wasmtime.Store;
+import io.github.kawamuray.wasmtime.WasmFunctions;
+import io.github.kawamuray.wasmtime.WasmValType;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.remoting.ChannelHandler;
+import org.apache.dubbo.remoting.RemotingException;
+import org.apache.dubbo.remoting.transport.AbstractChannel;
+import org.apache.dubbo.wasm.WasmLoader;
+import org.apache.dubbo.wasm.exception.DubboWasmException;
+
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+
+/**
+ * Channels implemented in other languages should extend this class, we still
need to write Java subclasses,
+ * so we can reuse the convenient/powerful control of dubbo, such as {@link
org.apache.dubbo.common.extension.Activate}.
+ *
+ * @see WasmLoader
+ */
+public abstract class AbstractWasmChannel extends AbstractChannel {
+
+ private static final Logger logger =
LoggerFactory.getLogger(AbstractWasmChannel.class);
+
+ private static final String SEND_METHOD_NAME = "send";
+
+ private static final String CLOSE_METHOD_NAME = "closeChannel";
+
+ private static final String GET_REMOTE_ADDRESS_HOST_METHOD_NAME =
"getRemoteAddressHost";
+
+ private static final String GET_REMOTE_ADDRESS_PORT_METHOD_NAME =
"getRemoteAddressPort";
+
+ private static final String IS_CONNECTED_METHOD_NAME = "isConnected";
+
+ private static final String HAS_ATTRIBUTE_METHOD_NAME = "hasAttribute";
+
+ private static final String GET_ATTRIBUTE_METHOD_NAME = "getAttribute";
+
+ private static final String SET_ATTRIBUTE_METHOD_NAME = "setAttribute";
+
+ private static final String REMOVE_ATTRIBUTE_METHOD_NAME =
"removeAttribute";
+
+ private static final String GET_LOCAL_ADDRESS_HOST_METHOD_NAME =
"getLocalAddressHost";
+
+ private static final String GET_LOCAL_ADDRESS_PORT_METHOD_NAME =
"getLocalAddressPort";
+
+ protected static final Map<Long, SendArgument> SEND_ARGUMENT_MAP = new
ConcurrentHashMap<>();
+
+ protected static final Map<Long, String> GET_REMOTE_ADDRESS_RESULTS = new
ConcurrentHashMap<>();
+
+ protected static final Map<Long, String> HAS_ATTRIBUTE_ARGUMENTS = new
ConcurrentHashMap<>();
+
+ protected static final Map<Long, String> GET_ATTRIBUTE_ARGUMENTS = new
ConcurrentHashMap<>();
+
+ protected static final Map<Long, SetAttributeArgument>
SET_ATTRIBUTE_ARGUMENT_MAP = new ConcurrentHashMap<>();
+
+ protected static final Map<Long, String> REMOVE_ATTRIBUTE_ARGUMENTS = new
ConcurrentHashMap<>();
+
+ protected static final Map<Long, String> GET_LOCAL_ADDRESS_RESULTS = new
ConcurrentHashMap<>();
+
+ private final WasmLoader wasmLoader;
+
+ public AbstractWasmChannel(URL url, ChannelHandler handler) {
+ super(url, handler);
+ this.wasmLoader = new WasmLoader(this.getClass(), this::buildWasmName,
this::initWasmCallJavaFunc);
+ }
+
+ protected String buildWasmName(final Class<?> clazz) {
+ return clazz.getName() + ".wasm";
+ }
+
+ protected Map<String, Func> initWasmCallJavaFunc(final Store<Void> store,
Supplier<ByteBuffer> buf) {
+ Map<String, Func> funcMap = new HashMap<>();
+ funcMap.put("setRemoteAddressHost", WasmFunctions.wrap(store,
WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
+ (respId, addr, len) -> {
+ ByteBuffer buffer = buf.get();
+ byte[] bytes = new byte[len];
+ for (int i = 0; i < len; i++) {
+ bytes[i] = buffer.get(addr.intValue() + i);
+ }
+ GET_REMOTE_ADDRESS_RESULTS.put(respId, new String(bytes,
StandardCharsets.UTF_8));
+ return 0;
+ }));
+ funcMap.put("setLocalAddressHost", WasmFunctions.wrap(store,
WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
+ (respId, addr, len) -> {
+ ByteBuffer buffer = buf.get();
+ byte[] bytes = new byte[len];
+ for (int i = 0; i < len; i++) {
+ bytes[i] = buffer.get(addr.intValue() + i);
+ }
+ GET_LOCAL_ADDRESS_RESULTS.put(respId, new String(bytes,
StandardCharsets.UTF_8));
+ return 0;
+ }));
+ return funcMap;
+ }
+
+ @Override
+ public void send(Object message, boolean sent) throws RemotingException {
+ super.send(message, sent);
+ Optional<Extern> func = wasmLoader.getWasmExtern(SEND_METHOD_NAME);
+ if (!func.isPresent()) {
+ throw new DubboWasmException(SEND_METHOD_NAME + " function not
found in " + wasmLoader.getWasmName());
+ }
+ final Long argumentId = sendArgumentId(message, sent);
+ SEND_ARGUMENT_MAP.put(argumentId, new SendArgument(message, sent));
+ WasmFunctions.consumer(wasmLoader.getStore(), func.get().func(),
WasmValType.I64).accept(argumentId);
+ SEND_ARGUMENT_MAP.remove(argumentId);
+ }
+
+ protected abstract Long sendArgumentId(Object message, boolean sent);
+
+ @Override
+ public void close() {
+ try {
+ super.close();
+ } catch (Exception e) {
+ logger.warn(e.getMessage(), e);
+ }
+ Optional<Extern> func = wasmLoader.getWasmExtern(CLOSE_METHOD_NAME);
+ if (!func.isPresent()) {
+ throw new DubboWasmException(CLOSE_METHOD_NAME + " function not
found in " + wasmLoader.getWasmName());
+ }
+ WasmFunctions.consumer(wasmLoader.getStore(),
func.get().func()).accept();
+ }
+
+ @Override
+ public InetSocketAddress getRemoteAddress() {
+ Optional<Extern> hostFunc =
wasmLoader.getWasmExtern(GET_REMOTE_ADDRESS_HOST_METHOD_NAME);
+ if (!hostFunc.isPresent()) {
+ throw new DubboWasmException(GET_REMOTE_ADDRESS_HOST_METHOD_NAME +
" function not found in " + wasmLoader.getWasmName());
+ }
+ Optional<Extern> portFunc =
wasmLoader.getWasmExtern(GET_REMOTE_ADDRESS_PORT_METHOD_NAME);
+ if (!portFunc.isPresent()) {
+ throw new DubboWasmException(GET_REMOTE_ADDRESS_PORT_METHOD_NAME +
" function not found in " + wasmLoader.getWasmName());
+ }
+ final Long respId = WasmFunctions.func(wasmLoader.getStore(),
hostFunc.get().func(), WasmValType.I64).call();
+ final Integer port = WasmFunctions.func(wasmLoader.getStore(),
portFunc.get().func(), WasmValType.I32).call();
+ return
InetSocketAddress.createUnresolved(GET_REMOTE_ADDRESS_RESULTS.get(respId),
port);
+ }
+
+ @Override
+ public boolean isConnected() {
+ Optional<Extern> func =
wasmLoader.getWasmExtern(IS_CONNECTED_METHOD_NAME);
+ if (!func.isPresent()) {
+ throw new DubboWasmException(IS_CONNECTED_METHOD_NAME + " function
not found in " + wasmLoader.getWasmName());
+ }
+ Integer result = WasmFunctions.func(wasmLoader.getStore(),
func.get().func(), WasmValType.I32).call();
+ return result != 0;
+ }
+
+ @Override
+ public boolean hasAttribute(String key) {
+ Optional<Extern> func =
wasmLoader.getWasmExtern(HAS_ATTRIBUTE_METHOD_NAME);
+ if (!func.isPresent()) {
+ throw new DubboWasmException(HAS_ATTRIBUTE_METHOD_NAME + "
function not found in " + wasmLoader.getWasmName());
+ }
+ final Long argumentId = hasAttributeArgumentId(key);
+ HAS_ATTRIBUTE_ARGUMENTS.put(argumentId, key);
+ Integer result = WasmFunctions.func(wasmLoader.getStore(),
func.get().func(), WasmValType.I64, WasmValType.I32)
+ .call(argumentId);
+ HAS_ATTRIBUTE_ARGUMENTS.remove(argumentId);
+ return result != 0;
+ }
+
+ protected abstract Long hasAttributeArgumentId(String key);
+
+ @Override
+ public Object getAttribute(String key) {
+ Optional<Extern> func =
wasmLoader.getWasmExtern(GET_ATTRIBUTE_METHOD_NAME);
+ if (!func.isPresent()) {
+ throw new DubboWasmException(GET_ATTRIBUTE_METHOD_NAME + "
function not found in " + wasmLoader.getWasmName());
+ }
+ final Long argumentId = getAttributeArgumentId(key);
+ GET_ATTRIBUTE_ARGUMENTS.put(argumentId, key);
+ WasmFunctions.consumer(wasmLoader.getStore(), func.get().func(),
WasmValType.I64).accept(argumentId);
+ GET_ATTRIBUTE_ARGUMENTS.remove(argumentId);
+ return getAttribute(key, argumentId);
+ }
+
+ protected abstract Long getAttributeArgumentId(String key);
+
+ protected abstract Object getAttribute(String key, Long argumentId);
+
+ @Override
+ public void setAttribute(String key, Object value) {
+ Optional<Extern> func =
wasmLoader.getWasmExtern(SET_ATTRIBUTE_METHOD_NAME);
+ if (!func.isPresent()) {
+ throw new DubboWasmException(SET_ATTRIBUTE_METHOD_NAME + "
function not found in " + wasmLoader.getWasmName());
+ }
+ final Long argumentId = setAttributeArgumentId(key, value);
+ SET_ATTRIBUTE_ARGUMENT_MAP.put(argumentId, new
SetAttributeArgument(key, value));
+ WasmFunctions.consumer(wasmLoader.getStore(), func.get().func(),
WasmValType.I64).accept(argumentId);
+ SET_ATTRIBUTE_ARGUMENT_MAP.remove(argumentId);
+ }
+
+ protected abstract Long setAttributeArgumentId(String key, Object value);
+
+ @Override
+ public void removeAttribute(String key) {
+ Optional<Extern> func =
wasmLoader.getWasmExtern(REMOVE_ATTRIBUTE_METHOD_NAME);
+ if (!func.isPresent()) {
+ throw new DubboWasmException(REMOVE_ATTRIBUTE_METHOD_NAME + "
function not found in " + wasmLoader.getWasmName());
+ }
+ final Long argumentId = removeAttributeArgumentId(key);
+ REMOVE_ATTRIBUTE_ARGUMENTS.put(argumentId, key);
+ WasmFunctions.consumer(wasmLoader.getStore(), func.get().func(),
WasmValType.I64).accept(argumentId);
+ REMOVE_ATTRIBUTE_ARGUMENTS.remove(argumentId);
+ }
+
+ protected abstract Long removeAttributeArgumentId(String key);
+
+ @Override
+ public InetSocketAddress getLocalAddress() {
+ Optional<Extern> hostFunc =
wasmLoader.getWasmExtern(GET_LOCAL_ADDRESS_HOST_METHOD_NAME);
+ if (!hostFunc.isPresent()) {
+ throw new DubboWasmException(GET_LOCAL_ADDRESS_HOST_METHOD_NAME +
" function not found in " + wasmLoader.getWasmName());
+ }
+ Optional<Extern> portFunc =
wasmLoader.getWasmExtern(GET_LOCAL_ADDRESS_PORT_METHOD_NAME);
+ if (!portFunc.isPresent()) {
+ throw new DubboWasmException(GET_LOCAL_ADDRESS_PORT_METHOD_NAME +
" function not found in " + wasmLoader.getWasmName());
+ }
+ final Long respId = WasmFunctions.func(wasmLoader.getStore(),
hostFunc.get().func(), WasmValType.I64).call();
+ final Integer port = WasmFunctions.func(wasmLoader.getStore(),
portFunc.get().func(), WasmValType.I32).call();
+ return
InetSocketAddress.createUnresolved(GET_LOCAL_ADDRESS_RESULTS.get(respId), port);
+ }
+
+ protected static class SendArgument {
+ protected Object message;
+ protected boolean sent;
+
+ private SendArgument(Object message, boolean sent) {
+ this.message = message;
+ this.sent = sent;
+ }
+ }
+
+ protected static class SetAttributeArgument {
+ protected String key;
+ protected Object value;
+
+ private SetAttributeArgument(String key, Object value) {
+ this.key = key;
+ this.value = value;
+ }
+ }
+}
diff --git
a/dubbo-wasm/dubbo-wasm-remoting-api/src/test/java/org/apache/dubbo/wasm/remoting/transport/AbstractWasmChannelTest.java
b/dubbo-wasm/dubbo-wasm-remoting-api/src/test/java/org/apache/dubbo/wasm/remoting/transport/AbstractWasmChannelTest.java
new file mode 100644
index 0000000..72852d6
--- /dev/null
+++
b/dubbo-wasm/dubbo-wasm-remoting-api/src/test/java/org/apache/dubbo/wasm/remoting/transport/AbstractWasmChannelTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.wasm.remoting.transport;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.remoting.transport.ChannelHandlerAdapter;
+import org.apache.dubbo.wasm.test.TestHelper;
+
+import io.github.kawamuray.wasmtime.Func;
+import io.github.kawamuray.wasmtime.Store;
+import org.junit.jupiter.api.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import java.util.function.Supplier;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * see dubbo-wasm/dubbo-wasm-test/src/main/rust-extensions/README.md
+ */
+public class AbstractWasmChannelTest {
+
+ @Test
+ void test() {
+ RustChannel channel = new RustChannel();
+ try {
+ channel.send("key");
+ channel.getRemoteAddress();
+ channel.isConnected();
+ channel.hasAttribute("key");
+ channel.getAttribute("key");
+ channel.setAttribute("key", "value");
+ channel.removeAttribute("key");
+ channel.getLocalAddress();
+ } catch (Exception ignored) {
+ } finally {
+ channel.close();
+ }
+ }
+
+ static class RustChannel extends AbstractWasmChannel {
+ public RustChannel() {
+
super(URL.valueOf("dubbo://127.0.0.1:12345?timeout=1234&default.timeout=5678"),
new ChannelHandlerAdapter());
+ }
+
+ @Override
+ protected String buildWasmName(Class<?> clazz) {
+ return TestHelper.WASM_NAME;
+ }
+
+ @Override
+ protected Map<String, Func> initWasmCallJavaFunc(Store<Void> store,
Supplier<ByteBuffer> supplier) {
+ Map<String, Func> funcs = TestHelper.initWasmCallJavaFunc(store,
supplier);
+ funcs.putAll(super.initWasmCallJavaFunc(store, supplier));
+ return funcs;
+ }
+
+ @Override
+ protected Long sendArgumentId(Object message, boolean sent) {
+ return 9L;
+ }
+
+ @Override
+ protected Long hasAttributeArgumentId(String key) {
+ return 9L;
+ }
+
+ @Override
+ protected Long getAttributeArgumentId(String key) {
+ return 9L;
+ }
+
+ @Override
+ protected Object getAttribute(String key, Long argumentId) {
+ String result = TestHelper.getResult(argumentId);
+ assertEquals("rust result", result);
+ return result;
+ }
+
+ @Override
+ protected Long setAttributeArgumentId(String key, Object value) {
+ return 9L;
+ }
+
+ @Override
+ protected Long removeAttributeArgumentId(String key) {
+ return 9L;
+ }
+ }
+}
diff --git
a/dubbo-wasm/dubbo-wasm-test/src/main/java/org/apache/dubbo/wasm/test/TestHelper.java
b/dubbo-wasm/dubbo-wasm-test/src/main/java/org/apache/dubbo/wasm/test/TestHelper.java
index ee72d24..a019831 100644
---
a/dubbo-wasm/dubbo-wasm-test/src/main/java/org/apache/dubbo/wasm/test/TestHelper.java
+++
b/dubbo-wasm/dubbo-wasm-test/src/main/java/org/apache/dubbo/wasm/test/TestHelper.java
@@ -59,6 +59,10 @@ public class TestHelper {
System.out.println("java side->" + result);
return 0;
}));
+ funcMap.put("setRemoteAddressHost", WasmFunctions.wrap(store,
WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
+ (respId, addr, len) -> 0));
+ funcMap.put("setLocalAddressHost", WasmFunctions.wrap(store,
WasmValType.I64, WasmValType.I64, WasmValType.I32, WasmValType.I32,
+ (respId, addr, len) -> 0));
return funcMap;
}
diff --git a/dubbo-wasm/dubbo-wasm-test/src/main/resources/rust_extensions.wasm
b/dubbo-wasm/dubbo-wasm-test/src/main/resources/rust_extensions.wasm
index 41e3c41..156cb4a 100755
Binary files
a/dubbo-wasm/dubbo-wasm-test/src/main/resources/rust_extensions.wasm and
b/dubbo-wasm/dubbo-wasm-test/src/main/resources/rust_extensions.wasm differ
diff --git a/dubbo-wasm/dubbo-wasm-test/src/main/rust-extensions/src/lib.rs
b/dubbo-wasm/dubbo-wasm-test/src/main/rust-extensions/src/lib.rs
index 10c4bdf..90d23e3 100644
--- a/dubbo-wasm/dubbo-wasm-test/src/main/rust-extensions/src/lib.rs
+++ b/dubbo-wasm/dubbo-wasm-test/src/main/rust-extensions/src/lib.rs
@@ -20,6 +20,10 @@ extern "C" {
fn get_args(arg_id: i64, addr: i64, len: i32) -> i32;
fn put_result(arg_id: i64, addr: i64, len: i32) -> i32;
+
+ fn setRemoteAddressHost(arg_id: i64, addr: i64, len: i32) -> i32;
+
+ fn setLocalAddressHost(arg_id: i64, addr: i64, len: i32) -> i32;
}
pub unsafe extern "C" fn impls(arg_id: i64) {
@@ -230,3 +234,86 @@ pub unsafe extern "C" fn publishConfigCas(arg_id: i64) ->
i32 {
impls(arg_id);
1
}
+
+/// 9
+
+#[no_mangle]
+pub unsafe extern "C" fn send(arg_id: i64) {
+ eprintln!("rust side-> send");
+ impls(arg_id);
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn getRemoteAddressHost()->i64 {
+ eprintln!("rust side-> getRemoteAddressHost");
+ impls(9);
+ let rust_result = "localhost".as_bytes();
+ let result_ptr = rust_result.as_ptr() as i64;
+ _ = setRemoteAddressHost(9, result_ptr, rust_result.len() as i32);
+ 9
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn getRemoteAddressPort()->i32 {
+ eprintln!("rust side-> getRemoteAddressPort");
+ impls(9);
+ 9999
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn isConnected()->i32 {
+ eprintln!("rust side-> isConnected");
+ impls(9);
+ 1
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn hasAttribute(arg_id: i64) -> i32 {
+ eprintln!("rust side-> hasAttribute");
+ impls(arg_id);
+ 1
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn getAttribute(arg_id: i64) -> i32 {
+ eprintln!("rust side-> getAttribute");
+ impls(arg_id);
+ 1
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn setAttribute(arg_id: i64) -> i32 {
+ eprintln!("rust side-> setAttribute");
+ impls(arg_id);
+ 1
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn removeAttribute(arg_id: i64) -> i32 {
+ eprintln!("rust side-> removeAttribute");
+ impls(arg_id);
+ 1
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn getLocalAddressHost()->i64 {
+ eprintln!("rust side-> getLocalAddressHost");
+ impls(9);
+ let rust_result = "localhost".as_bytes();
+ let result_ptr = rust_result.as_ptr() as i64;
+ _ = setLocalAddressHost(9, result_ptr, rust_result.len() as i32);
+ 9
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn getLocalAddressPort()->i32 {
+ eprintln!("rust side-> getLocalAddressPort");
+ impls(9);
+ 9999
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn closeChannel() {
+ eprintln!("rust side-> closeChannel");
+ impls(9);
+}
diff --git a/dubbo-wasm/pom.xml b/dubbo-wasm/pom.xml
index 75301c4..785daa0 100644
--- a/dubbo-wasm/pom.xml
+++ b/dubbo-wasm/pom.xml
@@ -36,6 +36,7 @@
<module>dubbo-wasm-rpc-api</module>
<module>dubbo-wasm-cluster-api</module>
<module>dubbo-wasm-registry-api</module>
+ <module>dubbo-wasm-remoting-api</module>
<module>dubbo-wasm-test</module>
</modules>