Skip to content

Commit ba62dd6

Browse files
committed
update generated sdk
1 parent fbdba98 commit ba62dd6

File tree

31 files changed

+1274
-1021
lines changed

31 files changed

+1274
-1021
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*
16-
* @file ServiceType.h
16+
* @file Constant.h
1717
* @author: yujiechen
1818
* @date 2024-11-07
1919
*/
@@ -26,4 +26,5 @@ namespace ppc::protocol
2626
{
2727
const static std::string PSI_SERVICE_TYPE = "PSI";
2828
const static std::string MPC_SERVICE_TYPE = "MPC";
29+
const static size_t LARGE_MSG_THRESHOLD = 30 * 1024 * 1024;
2930
} // namespace ppc::protocol

cpp/ppc-framework/protocol/GrpcConfig.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,45 @@ class GrpcConfig
8989
m_compressAlgorithm = compressAlgorithm;
9090
}
9191

92+
uint64_t maxMsgSize() const { return m_maxMsgSize; }
93+
void setMaxMsgSize(uint64_t maxMsgSize)
94+
{
95+
if (maxMsgSize > c_maxMsgSize)
96+
{
97+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
98+
"The maxMsgSize limit is " + std::to_string(c_maxMsgSize)));
99+
}
100+
m_maxMsgSize = maxMsgSize;
101+
}
102+
92103
protected:
93104
bool m_enableHealthCheck = true;
94105
std::string m_loadBalancePolicy = "round_robin";
95106
bool m_enableDnslookup = false;
107+
96108
// Note: grpc use int to set the maxMsgSize
97109
uint64_t const c_maxMsgSize = INT_MAX;
98110

99111
// the max send message size in bytes
100112
uint64_t m_maxSendMessageSize = c_maxMsgSize;
101113
// the max received message size in bytes
102114
uint64_t m_maxReceivedMessageSize = c_maxMsgSize;
115+
// the max msg size
116+
uint64_t m_maxMsgSize = c_maxMsgSize;
103117
int m_compressAlgorithm = 0;
104118
};
105119

106-
class GrpcServerConfig : public GrpcConfig
120+
class GrpcServerConfig
107121
{
108122
public:
109123
using Ptr = std::shared_ptr<GrpcServerConfig>;
110-
GrpcServerConfig() = default;
111-
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck)
112-
: m_endPoint(std::move(endPoint)), m_enableHealthCheck(enableHealthCheck)
113-
{}
114-
~GrpcServerConfig() override = default;
124+
GrpcServerConfig() { m_grpcConfig = std::make_shared<GrpcConfig>(); }
125+
GrpcServerConfig(EndPoint endPoint, bool enableHealthCheck) : GrpcServerConfig()
126+
{
127+
m_endPoint = std::move(endPoint);
128+
m_enableHealthCheck = enableHealthCheck;
129+
}
130+
virtual ~GrpcServerConfig() = default;
115131

116132
std::string listenEndPoint() const { return m_endPoint.listenEndPoint(); }
117133

@@ -122,21 +138,13 @@ class GrpcServerConfig : public GrpcConfig
122138
EndPoint& mutableEndPoint() { return m_endPoint; }
123139
bool enableHealthCheck() const { return m_enableHealthCheck; }
124140

125-
uint64_t maxMsgSize() const { return m_maxMsgSize; }
126-
void setMaxMsgSize(uint64_t maxMsgSize)
127-
{
128-
if (maxMsgSize > c_maxMsgSize)
129-
{
130-
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
131-
"The maxMsgSize limit is " + std::to_string(c_maxMsgSize)));
132-
}
133-
m_maxMsgSize = maxMsgSize;
134-
}
141+
GrpcConfig::Ptr const& grpcConfig() const { return m_grpcConfig; }
135142

136143
protected:
137144
ppc::protocol::EndPoint m_endPoint;
138145
bool m_enableHealthCheck = true;
139-
uint64_t m_maxMsgSize = c_maxMsgSize;
146+
// the grpc config
147+
GrpcConfig::Ptr m_grpcConfig;
140148
};
141149

142150

cpp/ppc-framework/protocol/Message.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ class MessageHeader
187187
class Message
188188
{
189189
public:
190-
const static size_t LARGER_MSG_THRESHOLD = 30 * 1024 * 1024;
191-
192190
using Ptr = std::shared_ptr<Message>;
193191
Message() = default;
194192
virtual ~Message() {}
@@ -207,7 +205,14 @@ class Message
207205

208206
bool isRespPacket() const { return m_header->isRespPacket(); }
209207
void setRespPacket() { m_header->setRespPacket(); }
210-
void setPayload(std::shared_ptr<bcos::bytes> _payload) { m_payload = std::move(_payload); }
208+
void setPayload(std::shared_ptr<bcos::bytes> _payload)
209+
{
210+
m_payload = std::move(_payload);
211+
if (m_payload)
212+
{
213+
m_payloadLen = m_payload->size();
214+
}
215+
}
211216
// for swig wrapper
212217
OutputBuffer payloadBuffer() const
213218
{
@@ -218,9 +223,18 @@ class Message
218223
return OutputBuffer{(unsigned char*)m_payload->data(), m_payload->size()};
219224
}
220225

221-
void setFrontMessage(MessagePayload::Ptr frontMessage)
226+
void setFrontMessage(MessagePayload::Ptr frontMessage, bool releasePayload = false)
222227
{
223228
m_frontMessage = std::move(frontMessage);
229+
if (!releasePayload)
230+
{
231+
return;
232+
}
233+
if (m_payload)
234+
{
235+
m_payload->clear();
236+
bcos::bytes().swap(*m_payload);
237+
}
224238
}
225239

226240
MessagePayload::Ptr const& frontMessage() const { return m_frontMessage; }
@@ -229,10 +243,7 @@ class Message
229243
virtual bool encode(bcos::bytes& _buffer) = 0;
230244
virtual int64_t decode(bcos::bytesConstRef _buffer) = 0;
231245

232-
virtual uint32_t length() const
233-
{
234-
return m_header->length() + (m_payload ? m_payload->size() : 0);
235-
}
246+
virtual uint32_t length() const { return m_header->length() + m_payloadLen; }
236247

237248
virtual std::shared_ptr<bcos::bytes> payload() const { return m_payload; }
238249

@@ -253,6 +264,9 @@ class Message
253264
MessageHeader::Ptr m_header;
254265
// Note: allocate here in case of wsService nullptr access caused coredump
255266
std::shared_ptr<bcos::bytes> m_payload = std::make_shared<bcos::bytes>();
267+
uint64_t m_payloadLen = 0;
268+
;
269+
256270
MessagePayload::Ptr m_frontMessage = nullptr;
257271
};
258272

cpp/wedpr-computing/ppc-psi/src/PSIConfig.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
#include "ppc-framework/Helper.h"
2424
#include "ppc-framework/front/FrontInterface.h"
2525
#include "ppc-framework/io/DataResourceLoader.h"
26+
#include "ppc-framework/protocol/Constant.h"
2627
#include "ppc-framework/protocol/Protocol.h"
2728
#include "psi-framework/interfaces/PSIMessageInterface.h"
29+
#include <gperftools/malloc_extension.h>
2830
#include <future>
2931
#include <utility>
3032

@@ -95,6 +97,14 @@ class PSIConfig
9597
}
9698
},
9799
_responseCallback);
100+
// release the large buffer if no-need to use
101+
if (ppcMsg->data() && ppcMsg->data()->size() > ppc::protocol::LARGE_MSG_THRESHOLD)
102+
{
103+
PSI_LOG(INFO) << LOG_DESC("sendMsg: Release large buffer since the message")
104+
<< LOG_KV("size", ppcMsg->data()->size());
105+
ppcMsg->releasePayload();
106+
MallocExtension::instance()->ReleaseFreeMemory();
107+
}
98108
}
99109

100110
void asyncSendResponse(bcos::bytes const& fromNode, std::string const& _taskID,

cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
using namespace ppc::psi;
2525
using namespace bcos;
2626

27-
void MasterCache::addCalculatorCipher(std::string _peerId,
28-
std::map<uint32_t, bcos::bytes>&& _cipherData, uint32_t seq, uint32_t dataBatchCount)
27+
void MasterCache::addCalculatorCipher(std::string _peerId, std::vector<bcos::bytes>&& _cipherData,
28+
std::vector<long> const& dataIndex, uint32_t seq, uint32_t dataBatchCount)
2929
{
3030
auto peerIndex = getPeerIndex(_peerId);
3131
if (peerIndex == -1)
@@ -39,9 +39,11 @@ void MasterCache::addCalculatorCipher(std::string _peerId,
3939
{
4040
m_calculatorDataBatchCount = dataBatchCount;
4141
}
42+
uint64_t i = 0;
4243
for (auto&& it : _cipherData)
4344
{
44-
updateMasterDataRef(peerIndex, std::move(it.second), it.first);
45+
updateMasterDataRef(peerIndex, std::move(it), dataIndex[i]);
46+
i++;
4547
}
4648
// try to merge the
4749
if (m_calculatorDataBatchCount > 0 &&
@@ -62,7 +64,7 @@ void MasterCache::addCalculatorCipher(std::string _peerId,
6264
<< LOG_KV("dataBatchCount", m_calculatorDataBatchCount);
6365
// release the cipherData
6466
_cipherData.clear();
65-
std::map<uint32_t, bcos::bytes>().swap(_cipherData);
67+
std::vector<bcos::bytes>().swap(_cipherData);
6668
MallocExtension::instance()->ReleaseFreeMemory();
6769
}
6870

@@ -184,8 +186,8 @@ bool MasterCache::tryToIntersection()
184186
}
185187
m_cacheState = CacheState::IntersectionProgressing;
186188

187-
ECDH_MULTI_LOG(INFO) << LOG_DESC("tryToIntersection ") << printCacheState()
188-
<< LOG_KV("masterData", m_masterDataRef.size());
189+
ECDH_MULTI_LOG(INFO) << LOG_DESC("* tryToIntersection ") << printCacheState()
190+
<< LOG_KV("* masterData", m_masterDataRef.size());
189191
auto startT = utcSteadyTime();
190192
// iterator the masterDataRef to obtain intersection
191193
for (auto&& it : m_masterDataRef)
@@ -208,30 +210,32 @@ bool MasterCache::tryToIntersection()
208210
}
209211
releaseCache();
210212
m_cacheState = CacheState::Intersectioned;
211-
ECDH_MULTI_LOG(INFO) << LOG_DESC("tryToIntersection success") << printCacheState()
212-
<< LOG_KV("intersectionSize", m_intersecCipher.size())
213-
<< LOG_KV("timecost", (utcSteadyTime() - startT));
213+
ECDH_MULTI_LOG(INFO) << LOG_DESC("* tryToIntersection success") << printCacheState()
214+
<< LOG_KV("* intersectionSize", m_intersecCipher.size())
215+
<< LOG_KV("* timecost", (utcSteadyTime() - startT));
214216
return true;
215217
}
216218

217-
std::vector<std::pair<uint64_t, bcos::bytes>> MasterCache::encryptIntersection(
218-
bcos::bytes const& randomKey)
219+
PSIMessageInterface::Ptr MasterCache::encryptIntersection(bcos::bytes const& randomKey)
219220
{
220-
std::vector<std::pair<uint64_t, bcos::bytes>> cipherData(m_intersecCipher.size());
221+
auto message = m_config->psiMsgFactory()->createPSIMessage(
222+
uint32_t(EcdhMultiPSIMessageType::SEND_ENCRYPTED_INTERSECTION_SET_TO_CALCULATOR));
223+
message->setFrom(m_taskState->task()->selfParty()->id());
224+
message->resizeData(m_intersecCipher.size());
221225
tbb::parallel_for(
222226
tbb::blocked_range<size_t>(0U, m_intersecCipher.size()), [&](auto const& range) {
223227
for (auto i = range.begin(); i < range.end(); i++)
224228
{
225229
auto cipherValue =
226230
m_config->eccCrypto()->ecMultiply(m_intersecCipher[i], randomKey);
227-
cipherData[i] = std::make_pair(m_intersecCipherIndex[i], cipherValue);
231+
message->setDataPair(i, m_intersecCipherIndex[i], cipherValue);
228232
}
229233
});
234+
ECDH_MULTI_LOG(INFO) << LOG_DESC("encryptIntersection")
235+
<< LOG_KV("cipherCount", m_intersecCipher.size()) << printCacheState();
230236
// Note: release the m_intersecCipher, make share it not been used after released
231237
releaseItersection();
232-
ECDH_MULTI_LOG(INFO) << LOG_DESC("encryptIntersection")
233-
<< LOG_KV("cipherCount", cipherData.size()) << printCacheState();
234-
return cipherData;
238+
return message;
235239
}
236240

237241
bcos::bytes CalculatorCache::getPlainDataByIndex(uint64_t index)
@@ -257,8 +261,8 @@ bool CalculatorCache::tryToFinalize()
257261
return false;
258262
}
259263
auto startT = utcSteadyTime();
260-
ECDH_MULTI_LOG(INFO) << LOG_DESC("tryToFinalize: compute intersection")
261-
<< LOG_KV("cipherRef", m_cipherRef.size()) << printCacheState();
264+
ECDH_MULTI_LOG(INFO) << LOG_DESC("* tryToFinalize: compute intersection")
265+
<< LOG_KV("* cipherRef", m_cipherRef.size()) << printCacheState();
262266
m_cacheState = CacheState::Finalizing;
263267
// find the intersection
264268
for (auto const& it : m_cipherRef)
@@ -273,28 +277,28 @@ bool CalculatorCache::tryToFinalize()
273277
}
274278
}
275279
m_cacheState = CacheState::Finalized;
276-
ECDH_MULTI_LOG(INFO) << LOG_DESC("tryToFinalize: compute intersection success")
277-
<< printCacheState() << LOG_KV("cipherRef", m_cipherRef.size())
278-
<< LOG_KV("intersectionSize", m_intersectionResult.size())
279-
<< LOG_KV("timecost", (utcSteadyTime() - startT));
280+
ECDH_MULTI_LOG(INFO) << LOG_DESC("* tryToFinalize: compute intersection success")
281+
<< printCacheState() << LOG_KV("* cipherRef", m_cipherRef.size())
282+
<< LOG_KV("* intersectionSize", m_intersectionResult.size())
283+
<< LOG_KV("* timecost", (utcSteadyTime() - startT));
280284

281285
releaseDataAfterFinalize();
282-
ECDH_MULTI_LOG(INFO) << LOG_DESC("tryToFinalize: syncIntersections") << printCacheState();
286+
ECDH_MULTI_LOG(INFO) << LOG_DESC("* tryToFinalize: syncIntersections") << printCacheState();
283287
m_cacheState = CacheState::Syncing;
284288
syncIntersections();
285289
m_cacheState = CacheState::Synced;
286290

287291
m_cacheState = CacheState::StoreProgressing;
288292
m_taskState->storePSIResult(m_config->dataResourceLoader(), m_intersectionResult);
289293
m_cacheState = CacheState::Stored;
290-
ECDH_MULTI_LOG(INFO) << LOG_DESC("tryToFinalize: syncIntersections and store success")
294+
ECDH_MULTI_LOG(INFO) << LOG_DESC("* tryToFinalize: syncIntersections and store success")
291295
<< printCacheState();
292296
return true;
293297
}
294298

295299
void CalculatorCache::syncIntersections()
296300
{
297-
ECDH_MULTI_LOG(INFO) << LOG_DESC("syncIntersections") << printCacheState();
301+
ECDH_MULTI_LOG(INFO) << LOG_DESC("*** syncIntersections **") << printCacheState();
298302
auto peers = m_taskState->task()->getAllPeerParties();
299303
auto taskID = m_taskState->task()->id();
300304
// notify task result
@@ -398,21 +402,24 @@ bool CalculatorCache::appendMasterCipher(
398402
return m_receiveAllMasterCipher;
399403
}
400404

401-
void CalculatorCache::setIntersectionCipher(std::map<uint32_t, bcos::bytes>&& _cipherData)
405+
void CalculatorCache::setIntersectionCipher(
406+
std::vector<bcos::bytes>&& _cipherData, std::vector<long> const& dataIndex)
402407
{
403408
ECDH_MULTI_LOG(INFO) << LOG_DESC("setIntersectionCipher")
404409
<< LOG_KV("dataSize", _cipherData.size())
405410
<< LOG_KV("cipherRefSize", m_cipherRef.size()) << printCacheState();
406411
bcos::Guard lock(m_mutex);
412+
uint64_t i = 0;
407413
for (auto&& it : _cipherData)
408414
{
409-
updateCipherRef(std::move(it.second), it.first);
415+
updateCipherRef(std::move(it), dataIndex[i]);
416+
i++;
410417
}
411418
m_receiveIntersection = true;
412419
ECDH_MULTI_LOG(INFO) << LOG_DESC("setIntersectionCipher finshed")
413420
<< LOG_KV("cipherRefSize", m_cipherRef.size()) << printCacheState();
414421
// release the cipherData
415422
_cipherData.clear();
416-
std::map<uint32_t, bcos::bytes>().swap(_cipherData);
423+
std::vector<bcos::bytes>().swap(_cipherData);
417424
MallocExtension::instance()->ReleaseFreeMemory();
418425
}

cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiCache.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class MasterCache
6767
<< LOG_KV("taskID", m_taskState->task()->id());
6868
}
6969

70-
void addCalculatorCipher(std::string _peerId, std::map<uint32_t, bcos::bytes>&& _cipherData,
71-
uint32_t seq, uint32_t dataBatchCount);
70+
void addCalculatorCipher(std::string _peerId, std::vector<bcos::bytes>&& _cipherData,
71+
std::vector<long> const& dataIndex, uint32_t seq, uint32_t dataBatchCount);
7272

7373
void addPartnerCipher(std::string _peerId, std::vector<bcos::bytes>&& _cipherData, uint32_t seq,
7474
uint32_t parternerDataCount);
@@ -83,7 +83,7 @@ class MasterCache
8383
return stringstream.str();
8484
}
8585

86-
std::vector<std::pair<uint64_t, bcos::bytes>> encryptIntersection(bcos::bytes const& randomKey);
86+
PSIMessageInterface::Ptr encryptIntersection(bcos::bytes const& randomKey);
8787

8888
private:
8989
bool shouldIntersection()
@@ -218,7 +218,8 @@ class CalculatorCache
218218
bool appendMasterCipher(
219219
std::vector<bcos::bytes>&& _cipherData, uint32_t seq, uint32_t dataBatchSize);
220220

221-
void setIntersectionCipher(std::map<uint32_t, bcos::bytes>&& _cipherData);
221+
void setIntersectionCipher(
222+
std::vector<bcos::bytes>&& _cipherData, std::vector<long> const& dataIndex);
222223

223224
void appendPlainData(ppc::io::DataBatch::Ptr const& data)
224225
{

cpp/wedpr-computing/ppc-psi/src/ecdh-multi-psi/EcdhMultiPSIImpl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "EcdhMultiPSIImpl.h"
22
#include "Common.h"
3+
#include "ppc-framework/protocol/Constant.h"
34
#include <gperftools/malloc_extension.h>
45

56
using namespace ppc::psi;
@@ -314,10 +315,10 @@ void EcdhMultiPSIImpl::executeWorker()
314315
psiMsg->setUUID(pop_msg->uuid());
315316
ECDH_MULTI_LOG(TRACE) << LOG_DESC("onReceiveMessage") << printPSIMessage(psiMsg)
316317
<< LOG_KV("uuid", psiMsg->uuid());
317-
// release the larger payload immediately
318-
if (payLoad->size() >= ppc::protocol::Message::LARGER_MSG_THRESHOLD)
318+
// release the large payload immediately
319+
if (payLoad && payLoad->size() >= ppc::protocol::LARGE_MSG_THRESHOLD)
319320
{
320-
ECDH_MULTI_LOG(INFO) << LOG_DESC("Release larger message payload")
321+
ECDH_MULTI_LOG(INFO) << LOG_DESC("Release large message payload")
321322
<< LOG_KV("size", payLoad->size());
322323
pop_msg->releasePayload();
323324
MallocExtension::instance()->ReleaseFreeMemory();

0 commit comments

Comments
 (0)