Skip to content

Commit

Permalink
ppc_model adapt to gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Oct 21, 2024
1 parent da1632d commit fcadc50
Show file tree
Hide file tree
Showing 64 changed files with 3,548 additions and 1,542 deletions.
5 changes: 3 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ set(TRANSPORT_SDK_SOURCE_LIST

set(ALL_SOURCE_LIST
${SDK_SOURCE_LIST}
${TRANSPORT_SDK_SOURCE_LIST}
wedpr-crypto/ppc-crypto
wedpr-protocol
wedpr-helper/libhelper wedpr-helper/ppc-tools
wedpr-storage/ppc-io wedpr-storage/ppc-storage
wedpr-transport/ppc-gateway wedpr-transport/ppc-front
wedpr-transport/ppc-http wedpr-transport/ppc-rpc wedpr-transport/sdk
wedpr-transport/ppc-gateway
wedpr-transport/ppc-http
wedpr-computing/ppc-psi wedpr-computing/ppc-mpc wedpr-computing/ppc-pir ${CEM_SOURCE}
wedpr-initializer wedpr-main)

Expand Down
14 changes: 12 additions & 2 deletions cpp/ppc-framework/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ inline std::string_view printP2PIDElegantly(std::string_view p2pId) noexcept
template <typename T>
inline std::string_view printNodeID(T const& nodeID)
{
size_t offset = nodeID.size() >= 15 ? 15 : nodeID.size();
return std::string_view((const char*)nodeID.data(), offset);
return std::string_view((const char*)nodeID.data(), nodeID.size());
}

template <typename T>
inline std::string printCollection(T const& collection)
{
std::ostringstream oss;
for (auto const& it : collection)
{
oss << it << ",";
}
return oss.str();
}
} // namespace ppc
5 changes: 3 additions & 2 deletions cpp/wedpr-transport/ppc-gateway/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ file(GLOB_RECURSE SRCS ppc-gateway/*.cpp)


add_library(${GATEWAY_TARGET} ${SRCS})
target_link_libraries(${GATEWAY_TARGET} PUBLIC ${TOOLS_TARGET} jsoncpp_static Boost::filesystem ${BCOS_BOOSTSSL_TARGET} ${BCOS_UTILITIES_TARGET}
${HTTP_TARGET} ${PROTOCOL_TARGET}
target_link_libraries(${GATEWAY_TARGET} PUBLIC ${TOOLS_TARGET} jsoncpp_static Boost::filesystem
${BCOS_BOOSTSSL_TARGET} ${BCOS_UTILITIES_TARGET}
${PROTOCOL_TARGET}
${TARS_PROTOCOL_TARGET} ${PB_PROTOCOL_TARGET} TBB::tbb)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ std::vector<std::string> PeerRouterTable::selectTargetNodes(
targetNodeList.insert(std::string(it.first.begin(), it.first.end()));
}
}
PEER_ROUTER_LOG(INFO) << LOG_DESC("selectTargetNodes, result: ")
<< printCollection(targetNodeList);
return std::vector<std::string>(targetNodeList.begin(), targetNodeList.end());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import com.webank.wedpr.sdk.jni.transport.handlers.MessageCallback;
import com.webank.wedpr.sdk.jni.transport.handlers.MessageDispatcherCallback;
import com.webank.wedpr.sdk.jni.transport.handlers.MessageErrorCallback;
import com.webank.wedpr.sdk.jni.transport.impl.RouteType;
import com.webank.wedpr.sdk.jni.transport.impl.TransportImpl;
import com.webank.wedpr.sdk.jni.transport.model.TransportEndPoint;
import java.util.List;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;

public class TransportDemo {
public static class MessageDispatcherCallbackImpl extends MessageDispatcherCallback {
Expand Down Expand Up @@ -140,8 +143,9 @@ public static void main(String[] args) throws Exception {
WeDPRTransport transport = TransportImpl.build(transportConfig);

transport.start();
String component = "WEDPR_COMPONENT_TEST";
transport.registerComponent(component);
System.out.println("####### start the transport success");

// send Message to the gateway
String topic = "testTopic";
MessageDispatcherCallback messageDispatcherCallback =
Expand Down Expand Up @@ -179,6 +183,12 @@ public static void main(String[] args) throws Exception {
+ ", payload: "
+ new String(msg.getPayload())
+ "####");
// selectNodeListByPolicy
List<String> nodeList =
transport.selectNodeListByPolicy(
RouteType.ROUTE_THROUGH_COMPONENT, null, component, null);
System.out.println(
"###### selectNodeListByPolicy result: " + StringUtils.join(nodeList, ","));
i++;
} catch (Exception e) {
System.out.println("#### exception: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ public SWIGTYPE_p_ppc__protocol__INodeInfo__Ptr generateNodeInfo() {
wedpr_java_transportJNI.FrontConfig_generateNodeInfo(swigCPtr, this), true);
}

public SWIGTYPE_p_std__vectorT_std__string_t getComponents() {
return new SWIGTYPE_p_std__vectorT_std__string_t(
public StringVec getComponents() {
return new StringVec(
wedpr_java_transportJNI.FrontConfig_getComponents(swigCPtr, this), false);
}

public void setComponents(SWIGTYPE_p_std__vectorT_std__string_t components) {
public void setComponents(StringVec components) {
wedpr_java_transportJNI.FrontConfig_setComponents(
swigCPtr, this, SWIGTYPE_p_std__vectorT_std__string_t.getCPtr(components));
swigCPtr, this, StringVec.getCPtr(components), components);
}

public void addComponent(String component) {
wedpr_java_transportJNI.FrontConfig_addComponent(swigCPtr, this, component);
}

public SWIGTYPE_p_std__vectorT_std__string_t mutableComponents() {
return new SWIGTYPE_p_std__vectorT_std__string_t(
public StringVec mutableComponents() {
return new StringVec(
wedpr_java_transportJNI.FrontConfig_mutableComponents(swigCPtr, this), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,15 @@ public void registerComponent(String component) {
public void unRegisterComponent(String component) {
wedpr_java_transportJNI.IFront_unRegisterComponent(swigCPtr, this, component);
}

public StringVec selectNodesByRoutePolicy(short routeType, MessageOptionalHeader routeInfo) {
return new StringVec(
wedpr_java_transportJNI.IFront_selectNodesByRoutePolicy(
swigCPtr,
this,
routeType,
MessageOptionalHeader.getCPtr(routeInfo),
routeInfo),
true);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (https://www.swig.org).
* Version 4.2.1
*
* Do not make changes to this file unless you know what you are doing - modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */

package com.webank.wedpr.sdk.jni.generated;

public class StringVec extends java.util.AbstractList<String> implements java.util.RandomAccess {
private transient long swigCPtr;
protected transient boolean swigCMemOwn;

protected StringVec(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}

protected static long getCPtr(StringVec obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}

protected static long swigRelease(StringVec obj) {
long ptr = 0;
if (obj != null) {
if (!obj.swigCMemOwn)
throw new RuntimeException("Cannot release ownership as memory is not owned");
ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.delete();
}
return ptr;
}

@SuppressWarnings({"deprecation", "removal"})
protected void finalize() {
delete();
}

public synchronized void delete() {
if (swigCPtr != 0) {
if (swigCMemOwn) {
swigCMemOwn = false;
wedpr_java_transportJNI.delete_StringVec(swigCPtr);
}
swigCPtr = 0;
}
}

public StringVec(String[] initialElements) {
this();
reserve(initialElements.length);

for (String element : initialElements) {
add(element);
}
}

public StringVec(Iterable<String> initialElements) {
this();
for (String element : initialElements) {
add(element);
}
}

public String get(int index) {
return doGet(index);
}

public String set(int index, String e) {
return doSet(index, e);
}

public boolean add(String e) {
modCount++;
doAdd(e);
return true;
}

public void add(int index, String e) {
modCount++;
doAdd(index, e);
}

public String remove(int index) {
modCount++;
return doRemove(index);
}

protected void removeRange(int fromIndex, int toIndex) {
modCount++;
doRemoveRange(fromIndex, toIndex);
}

public int size() {
return doSize();
}

public int capacity() {
return doCapacity();
}

public void reserve(int n) {
doReserve(n);
}

public StringVec() {
this(wedpr_java_transportJNI.new_StringVec__SWIG_0(), true);
}

public StringVec(StringVec other) {
this(wedpr_java_transportJNI.new_StringVec__SWIG_1(StringVec.getCPtr(other), other), true);
}

public boolean isEmpty() {
return wedpr_java_transportJNI.StringVec_isEmpty(swigCPtr, this);
}

public void clear() {
wedpr_java_transportJNI.StringVec_clear(swigCPtr, this);
}

public StringVec(int count, String value) {
this(wedpr_java_transportJNI.new_StringVec__SWIG_2(count, value), true);
}

private int doCapacity() {
return wedpr_java_transportJNI.StringVec_doCapacity(swigCPtr, this);
}

private void doReserve(int n) {
wedpr_java_transportJNI.StringVec_doReserve(swigCPtr, this, n);
}

private int doSize() {
return wedpr_java_transportJNI.StringVec_doSize(swigCPtr, this);
}

private void doAdd(String x) {
wedpr_java_transportJNI.StringVec_doAdd__SWIG_0(swigCPtr, this, x);
}

private void doAdd(int index, String x) {
wedpr_java_transportJNI.StringVec_doAdd__SWIG_1(swigCPtr, this, index, x);
}

private String doRemove(int index) {
return wedpr_java_transportJNI.StringVec_doRemove(swigCPtr, this, index);
}

private String doGet(int index) {
return wedpr_java_transportJNI.StringVec_doGet(swigCPtr, this, index);
}

private String doSet(int index, String val) {
return wedpr_java_transportJNI.StringVec_doSet(swigCPtr, this, index, val);
}

private void doRemoveRange(int fromIndex, int toIndex) {
wedpr_java_transportJNI.StringVec_doRemoveRange(swigCPtr, this, fromIndex, toIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,40 @@ public static final native void ibytes_doRemoveRange(

public static final native void delete_ibytes(long jarg1);

public static final native long new_StringVec__SWIG_0();

public static final native long new_StringVec__SWIG_1(long jarg1, StringVec jarg1_);

public static final native boolean StringVec_isEmpty(long jarg1, StringVec jarg1_);

public static final native void StringVec_clear(long jarg1, StringVec jarg1_);

public static final native long new_StringVec__SWIG_2(int jarg1, String jarg2);

public static final native int StringVec_doCapacity(long jarg1, StringVec jarg1_);

public static final native void StringVec_doReserve(long jarg1, StringVec jarg1_, int jarg2);

public static final native int StringVec_doSize(long jarg1, StringVec jarg1_);

public static final native void StringVec_doAdd__SWIG_0(
long jarg1, StringVec jarg1_, String jarg2);

public static final native void StringVec_doAdd__SWIG_1(
long jarg1, StringVec jarg1_, int jarg2, String jarg3);

public static final native String StringVec_doRemove(long jarg1, StringVec jarg1_, int jarg2);

public static final native String StringVec_doGet(long jarg1, StringVec jarg1_, int jarg2);

public static final native String StringVec_doSet(
long jarg1, StringVec jarg1_, int jarg2, String jarg3);

public static final native void StringVec_doRemoveRange(
long jarg1, StringVec jarg1_, int jarg2, int jarg3);

public static final native void delete_StringVec(long jarg1);

public static final native long Error_buildError__SWIG_0(
byte[] jarg1, byte[] jarg2, int jarg3, int jarg4, String jarg5);

Expand Down Expand Up @@ -239,7 +273,7 @@ public static final native void FrontConfig_setGrpcConfig(
public static final native long FrontConfig_getComponents(long jarg1, FrontConfig jarg1_);

public static final native void FrontConfig_setComponents(
long jarg1, FrontConfig jarg1_, long jarg2);
long jarg1, FrontConfig jarg1_, long jarg2, StringVec jarg2_);

public static final native void FrontConfig_addComponent(
long jarg1, FrontConfig jarg1_, String jarg2);
Expand Down Expand Up @@ -748,6 +782,9 @@ public static final native void IFront_registerComponent(
public static final native void IFront_unRegisterComponent(
long jarg1, IFront jarg1_, String jarg2);

public static final native long IFront_selectNodesByRoutePolicy(
long jarg1, IFront jarg1_, short jarg2, long jarg3, MessageOptionalHeader jarg3_);

public static final native void delete_IFrontBuilder(long jarg1);

public static final native long IFrontBuilder_buildClient(
Expand Down
Loading

0 comments on commit fcadc50

Please sign in to comment.