-
Notifications
You must be signed in to change notification settings - Fork 43
/
sender_dispatcher.h
76 lines (64 loc) · 2.63 KB
/
sender_dispatcher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#pragma once
// STD
#include <atomic>
#include <memory>
#include <utility>
// APSI
#include "apsi/network/sender_operation.h"
#include "apsi/network/zmq/zmq_channel.h"
#include "apsi/oprf/oprf_sender.h"
#include "apsi/sender.h"
#include "apsi/sender_db.h"
namespace apsi {
namespace sender {
/**
The ZMQSenderDispatcher is in charge of handling incoming requests through the network.
*/
class ZMQSenderDispatcher {
public:
ZMQSenderDispatcher() = delete;
/**
Creates a new ZMQSenderDispatcher object. This constructor accepts both a SenderDB
object, as well as a separately provided OPRF key. It uses the provided OPRF key to
respond to OPRF requests, instead of attempting to retrieve a key from the SenderDB.
This is necessary, for example, when the SenderDB is stripped, in which case it no
longer carries a valid OPRF key.
*/
ZMQSenderDispatcher(std::shared_ptr<SenderDB> sender_db, oprf::OPRFKey oprf_key);
/**
Creates a new ZMQSenderDispatcher object. This constructor accepts a SenderDB object. It
attempts to retrieve an OPRF key from the SenderDB and uses it to serve OPRF requests.
This constructor cannot be used if the SenderDB is stripped, because the OPRF key is no
longer available through the SenderDB.
*/
ZMQSenderDispatcher(std::shared_ptr<SenderDB> sender_db);
/**
Run the dispatcher on the given port.
*/
void run(const std::atomic<bool> &stop, int port);
private:
std::shared_ptr<sender::SenderDB> sender_db_;
oprf::OPRFKey oprf_key_;
/**
Dispatch a Get Parameters request to the Sender.
*/
void dispatch_parms(
std::unique_ptr<network::ZMQSenderOperation> sop,
network::ZMQSenderChannel &channel);
/**
Dispatch an OPRF query request to the Sender.
*/
void dispatch_oprf(
std::unique_ptr<network::ZMQSenderOperation> sop,
network::ZMQSenderChannel &channel);
/**
Dispatch a Query request to the Sender.
*/
void dispatch_query(
std::unique_ptr<network::ZMQSenderOperation> sop,
network::ZMQSenderChannel &channel);
}; // class ZMQSenderDispatcher
} // namespace sender
} // namespace apsi