APSI简单测试例子分析整个交互过程

#include <string>
#include <vector>
#include <fstream>
#include <utility>
#include <memory>
#include <iostream>

#include <apsi/receiver.h>
#include <apsi/sender.h>
#include <apsi/network/stream_channel.h>

using namespace std;
using namespace apsi;

int main() {
    // Use 4 threads
    ThreadPoolMgr::SetThreadCount(4);

    // Full logging to console
    Log::SetLogLevel(Log::Level::all);
    Log::SetConsoleDisabled(false);

    // We use a StreamChannel object for networking here; this allows the user to
    // decide how to exactly communicate the data. This channel is backed in this
    // case by a std::stringstream, but some other C++ stream could be used as well.
    stringstream channel_stream;
    network::StreamChannel channel(channel_stream);

    // This example demonstrates the "advanced" API where you have to handle
    // networking yourself. The CLI provides an example of using the "simple" API.
    // These are described more in README.md.


    // We need to have APSI parameters first. Some example parameters
    // are available in the APSI repo in the parameters/ subdirectory.
    // Here we use some rather small parameters (in the local file params.json).
    ifstream params_fs("params.json", ios::in);
    string params_str, curr_line;
    while (getline(params_fs, curr_line)) {
        params_str.append(curr_line);
        params_str.append("\n");
    }
    PSIParams params = PSIParams::Load(params_str);
    
    // Create the Sender's database (we are setting up an unlabeled SenderDB here).
    // The SenderDB should typically live in a std::shared_ptr.
    shared_ptr<sender::SenderDB> sender_db = make_shared<sender::SenderDB>(params);

    // Let's insert a couple items
    vector<string> raw_sender_items{
        "Alice",
        "Bob",
        "Charlie",
        "Daniel",
        "Eve",
        "Fazila",
        "Gilbert" };

    // We need to convert the strings to Item objects
    vector<Item> sender_items(raw_sender_items.begin(), raw_sender_items.end());

    // Insert the items in the SenderDB 
    sender_db->insert_or_assign(sender_items);


    // Now suppose the Receiver wants to query for a couple items
    vector<string> raw_receiver_items{
        "Amir",
        "Charlie",
        "Danny",
        "Eve" };

    // We need to convert the strings to Item objects
    vector<Item> receiver_items(raw_receiver_items.begin(), raw_receiver_items.end());

    // The first step is to obtain OPRF values for these items, so we need to
    // create an oprf::OPRFReceiver object and use it to create an OPRF request
    oprf::OPRFReceiver oprf_receiver = receiver::Receiver::CreateOPRFReceiver(receiver_items);
    Request request = receiver::Receiver::CreateOPRFRequest(oprf_receiver);
    
    // Send the OPRF request on our communication channel (note the need to std::move it)
    channel.send(move(request));


    // The Sender must receive the OPRF request (need to convert it to OPRFRequest type)
    Request received_request = channel.receive_operation(sender_db->get_seal_context());
    OPRFRequest received_oprf_request = to_oprf_request(move(received_request));

    // Process the OPRF request and send a response back to the Receiver
    sender::Sender::RunOPRF(received_oprf_request, sender_db->get_oprf_key(), channel);


    // The Receiver can now get the OPRF response from the communication channel.
    // We need to extract the OPRF hashes from the response.
    Response response = channel.receive_response();
    OPRFResponse oprf_response = to_oprf_response(response);
    auto receiver_oprf_items = receiver::Receiver::ExtractHashes(
        oprf_response,
        oprf_receiver
    );

    // With the OPRF hashed Receiver's items, we are ready to create a PSI query.
    // First though, we need to create our Receiver object (assume here the Receiver
    // knows the PSI parameters). We need to keep the IndexTranslationTable object that
    // Receiver::create_query returns.
    receiver::Receiver receiver(params);
    pair<Request, receiver::IndexTranslationTable> query_data
        = receiver.create_query(receiver_oprf_items.first);
    receiver::IndexTranslationTable itt = query_data.second;
    request = move(query_data.first);

    // Now we are ready to send the PSI query request on our communication channel
    channel.send(move(request));


    // The Sender will then receive the PSI query request
    received_request = channel.receive_operation(sender_db->get_seal_context());
    QueryRequest received_query_request = to_query_request(received_request);

    // We need to extract the PSI query first
    sender::Query query(move(received_query_request), sender_db);

    // Process the PSI query request and send the response back to the Receiver
    sender::Sender::RunQuery(query, channel);


    // The Receiver then receives a QueryResponse object on the channel
    response = channel.receive_response();
    QueryResponse query_response = to_query_response(response);

    // The actual result data is communicated separately; the query response only
    // contains the number of ResultPart objects we expect to receive.
    uint32_t result_part_count = query_response->package_count;

    // Now loop to receive all of the ResultParts 
    vector<ResultPart> result_parts;
    while (result_part_count--) {
        ResultPart result_part = channel.receive_result(receiver.get_seal_context());
        result_parts.push_back(move(result_part));
    }

    // Finally process the result
    vector<receiver::MatchRecord> results
        = receiver.process_result(receiver_oprf_items.second, itt, result_parts);

    // The results vector indicates match information; the order matches the order
    // of the original input vector receiver_items
    for (size_t i = 0; i < raw_receiver_items.size(); i++) {
        cout << "Item " << raw_receiver_items[i] << ": ";
        cout << (results[i].found ? "FOUND" : "NOT FOUND") << endl;
    }


    return 0;
}

这个类演示了如何使用 APSI 库来进行私有集合交集(PSI)计算。让我们逐步解释 main() 函数中的操作:

  1. 设置线程池:通过 ThreadPoolMgr::SetThreadCount(4) 设置线程池中线程的数量为 4。

  2. 设置日志级别:通过 Log::SetLogLevel(Log::Level::all) 设置日志级别为全部,以及通过 Log::SetConsoleDisabled(false) 启用日志输出到控制台。

  3. 创建通信通道:使用 network::StreamChannel 类创建一个通信通道,通过该通道与发送者和接收者进行通信。

  4. 加载参数:从文件 params.json 中读取 APSI 参数并加载到 PSIParams 对象中。

  5. 创建发送者数据库:使用加载的参数创建一个发送者数据库 sender_db,该数据库用于存储发送者的数据集合。

  6. 插入数据:将一些字符串数据插入到发送者数据库中,这些字符串将作为发送者的数据集合。

  7. 构建接收者的 OPRF 请求:使用接收者的数据集合创建一个 OPRF 请求,并通过通信通道发送给发送者。

  8. 发送者处理 OPRF 请求:发送者接收到接收者发送的 OPRF 请求后,根据请求计算 OPRF 值,并将响应发送给接收者。

  9. 接收者处理 OPRF 响应:接收者从通信通道接收到发送者的 OPRF 响应,提取其中的 OPRF 哈希值。

  10. 构建 PSI 查询请求:使用 OPRF 哈希值创建一个 PSI 查询请求,并通过通信通道发送给发送者。

  11. 发送者处理 PSI 查询请求:发送者接收到接收者发送的 PSI 查询请求后,根据请求进行处理,并将查询结果发送给接收者。

  12. 接收者处理查询响应:接收者从通信通道接收到发送者的查询响应,提取其中的结果部分,并将结果进行处理,得到最终的匹配结果。

  13. 输出匹配结果:将匹配结果输出到控制台,指示每个查询项是否在发送者的数据集合中找到了匹配项。

整个程序流程是:接收者先发送 OPRF 请求,然后发送者接收到请求后进行处理并发送响应,接收者再接收响应并进行处理,最终输出匹配结果。
代码源地址:https://github.com/kimlaine/APSI-example

  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
营运中心 2009年3月 国美电器2009年 音响商品知识培训课件 1 音响培训资料全文共30页,当前为第1页。 碟机 音响 音响 音响商品包括碟机和音响 2 音响培训资料全文共30页,当前为第2页。 第一部分 碟机 音响 3 音响培训资料全文共30页,当前为第3页。 1 2 3 碟机的发展史 碟机的相关术语及解释 碟机的原理及分类 4 碟机的使用及日常维护 音响---碟机 4 音响培训资料全文共30页,当前为第4页。 到目前为止,碟机的发展经过了"LD—CD—VCD—SVCD—DVD—HVD(EVD)—蓝光DVD(HD-DVD)等几个阶段 1.LD LD光盘英文全称为"LASER DISC"光盘技术是70年代继磁记录技术之后的一大重大科技发明,它利用聚焦激光从内圈到外圈按逆时针方向旋转将图象信号和伴音信号刻录在直径为30CM的塑料圆盘上,这就是激光视盘 商品化激光视盘播放机(简称LD播放机)于1980年问世 音响---碟机 一、碟机的发展史 5 音响培训资料全文共30页,当前为第5页。 2. CD 1981年飞利浦公司和索尼公司联合开发了数字激光唱机,称为CD(COMPACT DISC)唱机,全称CD-DA,是专门播放音乐节目的,取样频率为44.1KHZ,量化数为16BIT,外径为12CM的盘上可记录74MIN的音乐节目 音响---碟机 6 音响培训资料全文共30页,当前为第6页。 1993年飞利浦公司和JVQ公司制定了VCD标准,VCD全称为视频光盘(VIDEO COMPACT DISC),通常称为数字视盘或小影碟。VCD是利用MPEG-I压缩技术,对数字视\音频信号进行压缩处理,然后记录在直径为12CM的光盘上。一张VCD光盘可记录74MIN的活动图象及立体声伴音,VCD经过了版本1.0\1.1\2.0三个发展过程.1993年,世界第一台VCD视盘机整机在北京万燕公司诞生.后期过度到超级VCD及眼下的多用途DVD,超级VCD与DVD都采用MPEG-II压缩技术,图象和音质在MPEG-I基础上得到大幅度提升 音响---碟机 3.VCD 7 音响培训资料全文共30页,当前为第7页。 4.DVD4 DVD是英文DIGITAL VIDEO DISK的缩写,中文直译为"数字视频光盘"从性能来看,它完全有能力取代LD和VCD,因为它既有CD的优点,又有清晰度和播放时间都优于LD和VCD的特点,DVD播放机与1996年底问世 音响---碟机 8 音响培训资料全文共30页,当前为第8页。 5.HVD HVD的清晰度为普通DVD的5倍以上,全面支持高清数字电视所需要的720P/1080I/1080P格式输出,它的显示清晰度可以达到216万相素,而普通DVD只能达到30万到四十万相素,它是DVD的升级换代产品,EVD也是高清碟机的一种,只支持1080I的隔行高清 音响---碟机 9 音响培训资料全文共30页,当前为第9页。 HD-DVD一以东芝为首仍然采用红光技术,采用低比特率压缩技术的高清碟机,市场价格7000元左右 音响---碟机 6.蓝光DVD 蓝光DVD以索尼为首采用蓝光技术的高清碟机,市场价格6000元左右 10 音响培训资料全文共30页,当前为第10页。 二、碟机的工作原理及分类 (一)碟机的原理 通过激光头读取光碟上的数字信号传送到解码芯片和先进的数字化解码技术,对音频数字的信号进行还原,再通过音频电路和高保真耳机传送到人耳,通过动态数码滤波器对数字信号智能检测,使画面保持高度清晰 (二)碟机的分类 碟机按面板材料分为:APSI工程材料面板和铝镁合金面板 音响---碟机 11 音响培训资料全文共30页,当前为第11页。 音响---碟机 三、碟机的专业术语解释 1.电子防震(ESP) 3.端口的标识: 4.SMDS: 2.电子均衡: 超越号移动数字系统技术,通过这项技术DVD的显示屏、光头、机芯、解码等软硬被有机融合于方寸之间从而达到高度统一 此部分内容与便携式CD机中的内容机同 此部分内容与便携式CD机中的内容机同 通过先将信号存入内存缓冲区,再通过读取内存数据来达到防震的目的,其防震程度的大小取决于内存的大小和激光头的读取数据的快慢 5.电子、机械双重防震: 可预读碟片信息,当机器处于较剧烈震动、停顿、脱离状态时,自动释放预存信息、并对缺损、错误信息进行补偿,插补和纠错、保证连续稳定播放 12 音响培训资料全文共30页,当前为第12页。 音响---碟机 四、碟机的使用及日常维护 注意事项3 注意事项2 注意事项4 注意事项1 摆放:不要将机器放置在易移动或震动的地方,如车辆的仪表板或不稳的支架上 不可使用破裂、变形或修补过的影碟,这样的影碟易于破碎并引起机器故障 使用机器时,应尽量避免有水份的地方,如浴盆、脸盆、厨房洗碗池、

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值