From 24097e70ba65748e127b6de1008627a690a2090a Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Wed, 18 Sep 2024 11:50:09 +0800 Subject: [PATCH 1/2] update build.gradle --- cpp/wedpr-transport/sdk-wrapper/java/bindings/build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/wedpr-transport/sdk-wrapper/java/bindings/build.gradle b/cpp/wedpr-transport/sdk-wrapper/java/bindings/build.gradle index 362b0ba3..c703444d 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/bindings/build.gradle +++ b/cpp/wedpr-transport/sdk-wrapper/java/bindings/build.gradle @@ -24,6 +24,7 @@ ext { junitVersion = "4.13.2" log4jVersion = "2.23.0" jmhVersion = "1.36" + println("*ossrhUsername: " + ossrhUsername) } println("Notice: current gradle version is " + gradle.gradleVersion) @@ -199,8 +200,8 @@ publishing { url = !version.endsWith("SNAPSHOT") ? releasesRepoURL : snapshotsRepoURL credentials { - username 'deployment' - password 'deployment123' + username ossrhUsername + password ossrhPassword } } signing { From 83ce372fe871fda354044f8f47e16874e06cc4a9 Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Wed, 18 Sep 2024 12:24:10 +0800 Subject: [PATCH 2/2] update async_send_response interface --- cpp/ppc-framework/front/IFront.h | 9 +- .../wedpr/sdk/jni/generated/IFront.java | 12 +- .../wedpr/sdk/jni/generated/IFrontClient.java | 2 + .../generated/wedpr_java_transportJNI.java | 16 +-- .../sdk/jni/transport/WeDPRTransport.java | 16 +++ .../sdk/jni/transport/impl/TransportImpl.java | 19 +++ .../src/wedpr_java_transportJAVA_wrap.cxx | 117 +++++++++++++----- 7 files changed, 145 insertions(+), 46 deletions(-) diff --git a/cpp/ppc-framework/front/IFront.h b/cpp/ppc-framework/front/IFront.h index da46c575..fd0c10cc 100644 --- a/cpp/ppc-framework/front/IFront.h +++ b/cpp/ppc-framework/front/IFront.h @@ -183,11 +183,14 @@ class IFront : virtual public IFrontClient // !!! Note: the 'payload ' type(char*) should not been changed, since it used to pass-in java // byte[] data - virtual void async_send_response(bcos::bytes const& dstNode, std::string const& traceID, - bcos::bytes&& payload, int seq, ErrorCallback::Ptr errorCallback) + virtual void async_send_response(char* dstNode, uint64_t dstNodeSize, std::string const& traceID, + char* payload, uint64_t payloadSize, int seq, ErrorCallback::Ptr errorCallback) { + // TODO: optimize here + bcos::bytes copiedDstNode(dstNode, dstNode + dstNodeSize); + bcos::bytes copyedPayload(payload, payload + payloadSize); asyncSendResponse( - dstNode, traceID, std::move(payload), seq, populateErrorCallback(errorCallback)); + copiedDstNode, traceID, std::move(copyedPayload), seq, populateErrorCallback(errorCallback)); } // the sync interface for async_send_message diff --git a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFront.java b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFront.java index ce4d2352..bc5aac7c 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFront.java +++ b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFront.java @@ -99,15 +99,21 @@ public void async_send_message( } public void async_send_response( - ubytes dstNode, String traceID, ubytes payload, int seq, ErrorCallback errorCallback) { + byte[] dstNode, + java.math.BigInteger dstNodeSize, + String traceID, + byte[] payload, + java.math.BigInteger payloadSize, + int seq, + ErrorCallback errorCallback) { wedpr_java_transportJNI.IFront_async_send_response( swigCPtr, this, - ubytes.getCPtr(dstNode), dstNode, + dstNodeSize, traceID, - ubytes.swigRelease(payload), payload, + payloadSize, seq, ErrorCallback.getCPtr(errorCallback), errorCallback); diff --git a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFrontClient.java b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFrontClient.java index a9d97546..ac777ec8 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFrontClient.java +++ b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/IFrontClient.java @@ -43,6 +43,8 @@ public synchronized void delete() { /** * : receive message from gateway, call by gateway
*
+ * + * @return void */ public void onReceiveMessage( Message _msg, diff --git a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/wedpr_java_transportJNI.java b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/wedpr_java_transportJNI.java index 121320fd..8418644a 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/wedpr_java_transportJNI.java +++ b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/generated/wedpr_java_transportJNI.java @@ -677,14 +677,14 @@ public static final native void IFront_async_send_message( public static final native void IFront_async_send_response( long jarg1, IFront jarg1_, - long jarg2, - ubytes jarg2_, - String jarg3, - long jarg4, - ubytes jarg4_, - int jarg5, - long jarg6, - ErrorCallback jarg6_); + byte[] jarg2, + java.math.BigInteger jarg3, + String jarg4, + byte[] jarg5, + java.math.BigInteger jarg6, + int jarg7, + long jarg8, + ErrorCallback jarg8_); public static final native long IFront_push__SWIG_0( long jarg1, diff --git a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/WeDPRTransport.java b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/WeDPRTransport.java index 97146fde..5a716f6b 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/WeDPRTransport.java +++ b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/WeDPRTransport.java @@ -132,6 +132,22 @@ void asyncSendMessageByTopic( MessageErrorCallback errorCallback, MessageCallback msgCallback); + /** + * send response to given node + * + * @param dstNode the node that should receive the response + * @param traceID the traceID of the response + * @param payload the payload + * @param seq the seq + * @param errorCallback the error callback + */ + void asyncSendResponse( + byte[] dstNode, + String traceID, + byte[] payload, + int seq, + MessageErrorCallback errorCallback); + /** @param topic the topic to remove */ void removeTopic(String topic) throws WeDPRSDKException; diff --git a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java index ebc36f26..46420d94 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java +++ b/cpp/wedpr-transport/sdk-wrapper/java/bindings/src/main/java/com/webank/wedpr/sdk/jni/transport/impl/TransportImpl.java @@ -243,6 +243,25 @@ public void asyncSendMessageByTopic( msgCallback); } + @Override + public void asyncSendResponse( + byte[] dstNode, + String traceID, + byte[] payload, + int seq, + MessageErrorCallback errorCallback) { + this.transport + .getFront() + .async_send_response( + dstNode, + BigInteger.valueOf(dstNode.length), + traceID, + payload, + BigInteger.valueOf(payload.length), + seq, + errorCallback); + } + /** @param topic the topic to remove */ @Override public void removeTopic(String topic) throws WeDPRSDKException { diff --git a/cpp/wedpr-transport/sdk-wrapper/java/src/wedpr_java_transportJAVA_wrap.cxx b/cpp/wedpr-transport/sdk-wrapper/java/src/wedpr_java_transportJAVA_wrap.cxx index 66ff9162..e103bfd8 100644 --- a/cpp/wedpr-transport/sdk-wrapper/java/src/wedpr_java_transportJAVA_wrap.cxx +++ b/cpp/wedpr-transport/sdk-wrapper/java/src/wedpr_java_transportJAVA_wrap.cxx @@ -6080,51 +6080,104 @@ SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1tra } -SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1async_1send_1response(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jstring jarg3, jlong jarg4, jobject jarg4_, jint jarg5, jlong jarg6, jobject jarg6_) { +SWIGEXPORT void JNICALL Java_com_webank_wedpr_sdk_jni_generated_wedpr_1java_1transportJNI_IFront_1async_1send_1response(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2, jobject jarg3, jstring jarg4, jbyteArray jarg5, jobject jarg6, jint jarg7, jlong jarg8, jobject jarg8_) { ppc::front::IFront *arg1 = (ppc::front::IFront *) 0 ; - bcos::bytes *arg2 = 0 ; - std::string *arg3 = 0 ; - bcos::bytes *arg4 = 0 ; - int arg5 ; - ppc::front::ErrorCallback::Ptr arg6 ; + char *arg2 = (char *) 0 ; + uint64_t arg3 ; + std::string *arg4 = 0 ; + char *arg5 = (char *) 0 ; + uint64_t arg6 ; + int arg7 ; + ppc::front::ErrorCallback::Ptr arg8 ; std::shared_ptr< ppc::front::IFront > *smartarg1 = 0 ; - std::unique_ptr< bcos::bytes > rvrdeleter4 ; - ppc::front::ErrorCallback::Ptr *argp6 ; + ppc::front::ErrorCallback::Ptr *argp8 ; (void)jenv; (void)jcls; (void)jarg1_; - (void)jarg2_; - (void)jarg4_; - (void)jarg6_; + (void)jarg8_; smartarg1 = *(std::shared_ptr< ppc::front::IFront > **)&jarg1; arg1 = (ppc::front::IFront *)(smartarg1 ? smartarg1->get() : 0); - - arg2 = (bcos::bytes *)((*(std::shared_ptr< const bcos::bytes > **)&jarg2) ? (*(std::shared_ptr< const bcos::bytes > **)&jarg2)->get() : 0); - if (!arg2) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "bcos::bytes const & reference is null"); - return ; - } - if(!jarg3) { + { + arg2 = (char *) jenv->GetByteArrayElements(jarg2, 0); + } + { + jclass clazz; + jmethodID mid; + jbyteArray ba; + jbyte* bae; + jsize sz; + int i; + + if (!jarg3) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null"); + return ; + } + clazz = jenv->GetObjectClass(jarg3); + mid = jenv->GetMethodID(clazz, "toByteArray", "()[B"); + ba = (jbyteArray)jenv->CallObjectMethod(jarg3, mid); + bae = jenv->GetByteArrayElements(ba, 0); + sz = jenv->GetArrayLength(ba); + arg3 = 0; + if (sz > 0) { + arg3 = (uint64_t)(signed char)bae[0]; + for(i=1; iReleaseByteArrayElements(ba, bae, 0); + } + if(!jarg4) { SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); return ; } - const char *arg3_pstr = (const char *)jenv->GetStringUTFChars(jarg3, 0); - if (!arg3_pstr) return ; - std::string arg3_str(arg3_pstr); - arg3 = &arg3_str; - jenv->ReleaseStringUTFChars(jarg3, arg3_pstr); - arg4 = *(bcos::bytes **)&jarg4; - if (!arg4) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "bcos::bytes && is null"); - return ; + const char *arg4_pstr = (const char *)jenv->GetStringUTFChars(jarg4, 0); + if (!arg4_pstr) return ; + std::string arg4_str(arg4_pstr); + arg4 = &arg4_str; + jenv->ReleaseStringUTFChars(jarg4, arg4_pstr); + { + arg5 = (char *) jenv->GetByteArrayElements(jarg5, 0); } - rvrdeleter4.reset(arg4); - arg5 = (int)jarg5; - argp6 = *(ppc::front::ErrorCallback::Ptr **)&jarg6; - if (argp6) arg6 = *argp6; - (arg1)->async_send_response((bcos::bytes const &)*arg2,(std::string const &)*arg3,(bcos::bytes &&)*arg4,arg5,arg6); + { + jclass clazz; + jmethodID mid; + jbyteArray ba; + jbyte* bae; + jsize sz; + int i; + + if (!jarg6) { + SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null"); + return ; + } + clazz = jenv->GetObjectClass(jarg6); + mid = jenv->GetMethodID(clazz, "toByteArray", "()[B"); + ba = (jbyteArray)jenv->CallObjectMethod(jarg6, mid); + bae = jenv->GetByteArrayElements(ba, 0); + sz = jenv->GetArrayLength(ba); + arg6 = 0; + if (sz > 0) { + arg6 = (uint64_t)(signed char)bae[0]; + for(i=1; iReleaseByteArrayElements(ba, bae, 0); + } + arg7 = (int)jarg7; + argp8 = *(ppc::front::ErrorCallback::Ptr **)&jarg8; + if (argp8) arg8 = *argp8; + (arg1)->async_send_response(arg2,arg3,(std::string const &)*arg4,arg5,arg6,arg7,arg8); + { + jenv->ReleaseByteArrayElements(jarg2, (jbyte *) arg2, 0); + } + { + jenv->ReleaseByteArrayElements(jarg5, (jbyte *) arg5, 0); + } + + }