Skip to content

Commit

Permalink
optimize log && fix ut (#25)
Browse files Browse the repository at this point in the history
* optimize log

* fix ut
  • Loading branch information
cyjseagull authored Sep 6, 2024
1 parent 4415b6e commit 7db7ad0
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 317 deletions.
1 change: 1 addition & 0 deletions cpp/cmake/IncludeDirectories.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-computing)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-crypto)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-storage)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-helper)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-transport)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-crypto/sdk)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-transport/ppc-front)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-transport/ppc-gateway)
Expand Down
5 changes: 5 additions & 0 deletions cpp/ppc-framework/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ inline std::string_view printP2PIDElegantly(std::string_view p2pId) noexcept
return p2pId.substr(RSA_PUBLIC_KEY_PREFIX, RSA_PUBLIC_KEY_TRUNC);
}

template <typename T>
inline std::string printNodeID(T const& nodeID)
{
return std::string(nodeID.begin(), nodeID.begin() + 8);
}

#if ENABLE_CPU_FEATURES
#if X86
Expand Down
1 change: 1 addition & 0 deletions cpp/ppc-framework/front/IFront.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class IFront : virtual public IFrontClient
* @param topic the topic to unregister
*/
virtual void unRegisterTopic(std::string const& topic) = 0;

};

class IFrontBuilder
Expand Down
4 changes: 3 additions & 1 deletion cpp/ppc-framework/protocol/INodeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @date 2024-08-26
*/
#pragma once
#include "ppc-framework/Common.h"
#include <bcos-utilities/Common.h>
#include <memory>
#include <set>
Expand Down Expand Up @@ -77,7 +78,8 @@ inline std::string printNodeInfo(INodeInfo::Ptr const& nodeInfo)
return "nullptr";
}
std::ostringstream stringstream;
stringstream << LOG_KV("endPoint", nodeInfo->endPoint());
stringstream << LOG_KV("endPoint", nodeInfo->endPoint())
<< LOG_KV("nodeID", printNodeID(nodeInfo->nodeID()));
std::string components = "";
for (auto const& it : nodeInfo->components())
{
Expand Down
2 changes: 1 addition & 1 deletion cpp/wedpr-computing/ppc-cem/tests/TestCEMService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BOOST_FIXTURE_TEST_SUITE(cMServiceTest, TestPromptFixture)
BOOST_AUTO_TEST_CASE(testCEMService)
{
auto cemService = std::make_shared<CEMService>();
std::string configPath{"../../../ppc-cem/tests/data/config.ini"};
std::string configPath{"../../../../wedpr-computing/ppc-cem/tests/data/config.ini"};
boost::property_tree::ptree pt;
boost::property_tree::read_ini(configPath, pt);
// load the cm config
Expand Down
2 changes: 1 addition & 1 deletion cpp/wedpr-computing/ppc-cem/tests/data/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[cem]
use_mysql = false
dataset_hdfs_path = /user/ppc/admin
dataset_file_path = ../../../ppc-cem/tests/data
dataset_file_path = ../../../../wedpr-computing/ppc-cem/tests/data
ciphertext_suffix = -encrypted
read_per_batch_lines = 100000

Expand Down
2 changes: 1 addition & 1 deletion cpp/wedpr-computing/ppc-mpc/tests/TestMPCService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BOOST_FIXTURE_TEST_SUITE(MPCServiceTest, TestPromptFixture)
BOOST_AUTO_TEST_CASE(testMPCService)
{
auto mpcService = std::make_shared<MPCService>();
std::string configPath{"../../../ppc-mpc/tests/data/config.ini"};
std::string configPath{"../../../../wedpr-computing/ppc-mpc/tests/data/config.ini"};
boost::property_tree::ptree pt;
boost::property_tree::read_ini(configPath, pt);
// load the mpc config
Expand Down
70 changes: 37 additions & 33 deletions cpp/wedpr-computing/ppc-pir/tests/FakeOtPIRFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,51 +38,55 @@ using namespace ppc::io;
using namespace ppc::front;
using namespace ppc::tools;

namespace ppc::test {

class FakeOtPIRImpl : public OtPIRImpl {
namespace ppc::test
{
class FakeOtPIRImpl : public OtPIRImpl
{
public:
using Ptr = std::shared_ptr<FakeOtPIRImpl>;
FakeOtPIRImpl(OtPIRConfig::Ptr const &_config, unsigned _idleTimeMs = 0)
: OtPIRImpl(_config, _idleTimeMs) {
m_enableOutputExists = true;
}
~FakeOtPIRImpl() override = default;
using Ptr = std::shared_ptr<FakeOtPIRImpl>;
FakeOtPIRImpl(OtPIRConfig::Ptr const& _config, unsigned _idleTimeMs = 0)
: OtPIRImpl(_config, _idleTimeMs)
{
m_enableOutputExists = true;
}
~FakeOtPIRImpl() override = default;
};

class FakeOtPIRFactory : public OtPIRFactory {
class FakeOtPIRFactory : public OtPIRFactory
{
public:
using Ptr = std::shared_ptr<FakeOtPIRFactory>;
using Ptr = std::shared_ptr<FakeOtPIRFactory>;

FakeOtPIRFactory()
FakeOtPIRFactory()
: m_front(std::make_shared<FakeFront>()),
m_dataResourceLoader(std::make_shared<DataResourceLoaderImpl>(
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)),
m_threadPool(std::make_shared<ThreadPool>("ot-pir", 4)) {
auto hashImpl = std::make_shared<Sha512Hash>();
auto eccCrypto = std::make_shared<OpenSSLEccCrypto>(
hashImpl, ppc::protocol::ECCCurve::P256);
m_cryptoBox = std::make_shared<ppc::crypto::CryptoBox>(hashImpl, eccCrypto);
}
m_threadPool(std::make_shared<ThreadPool>("ot-pir", 4))
{
auto hashImpl = std::make_shared<Sha512Hash>();
auto eccCrypto =
std::make_shared<OpenSSLEccCrypto>(hashImpl, ppc::protocol::ECCCurve::P256);
m_cryptoBox = std::make_shared<ppc::crypto::CryptoBox>(hashImpl, eccCrypto);
}

~FakeOtPIRFactory() override = default;
~FakeOtPIRFactory() override = default;

OtPIRImpl::Ptr createOtPIR(std::string const &_selfParty) {
auto config =
std::make_shared<OtPIRConfig>(_selfParty, m_front, m_cryptoBox,
m_threadPool, m_dataResourceLoader, 1);
OtPIRImpl::Ptr createOtPIR(std::string const& _selfParty)
{
auto config = std::make_shared<OtPIRConfig>(
_selfParty, m_front, m_cryptoBox, m_threadPool, m_dataResourceLoader, 1);

return std::make_shared<FakeOtPIRImpl>(config);
}
return std::make_shared<FakeOtPIRImpl>(config);
}

DataResourceLoaderImpl::Ptr resourceLoader() { return m_dataResourceLoader; }
FakeFront::Ptr front() { return m_front; }
CryptoBox::Ptr cryptoBox() { return m_cryptoBox; }
DataResourceLoaderImpl::Ptr resourceLoader() { return m_dataResourceLoader; }
FakeFront::Ptr front() { return m_front; }
CryptoBox::Ptr cryptoBox() { return m_cryptoBox; }

private:
FakeFront::Ptr m_front;
DataResourceLoaderImpl::Ptr m_dataResourceLoader;
ThreadPool::Ptr m_threadPool;
CryptoBox::Ptr m_cryptoBox;
FakeFront::Ptr m_front;
DataResourceLoaderImpl::Ptr m_dataResourceLoader;
ThreadPool::Ptr m_threadPool;
CryptoBox::Ptr m_cryptoBox;
};
} // namespace ppc::test
} // namespace ppc::test
Loading

0 comments on commit 7db7ad0

Please sign in to comment.