25 #include <zmqpp/message.hpp>
32 std::vector<std::string> auth_sources,
33 std::vector<std::string> connect_to,
34 std::vector<std::string> bind_to,
36 : bus_sub_(ctx,
zmqpp::socket_type::sub)
37 , tcp_(ctx,
zmqpp::socket_type::stream)
38 , protocol_(std::move(protocol_handler))
40 ASSERT_LOG(connect_to.empty() || bind_to.empty(),
41 "Cannot bind and connect at the same time.");
42 ASSERT_LOG(!connect_to.empty() || !bind_to.empty(),
"Cannot do nothing");
47 bus_sub_.connect(
"inproc://zmq-bus-pub");
48 for (
const auto &src : auth_sources)
67 msg << target.zmq_identity_;
70 auto data =
protocol_->build_cred_msg(card);
71 msg.add_raw(&data[0], data.size());
75 WARN(
"TCPNotifier: Protocol error: " << e.what());
78 auto ret =
tcp_.send(msg,
true);
81 ERROR(
"Sending to client would block.");
88 std::string routing_id;
91 assert(msg.parts() == 2);
92 msg >> routing_id >> data;
108 INFO(
"TCP-Notifier: New client connected.");
114 return info.zmq_identity_ ==
118 INFO(
"TCP-Notifier: Client disconnected.");
122 ASSERT_LOG(target,
"Why did we lose a target?");
125 INFO(
"Lost connection with client.");
127 INFO(
"Successfully connected to client.");
129 target->status_ = !target->status_;
137 while (
tcp_.receive(msg,
true))
148 return target.zmq_identity_ == routing_id;
166 WARN(
"Unexpected message content.");
169 msg >> src >> type >> card >> bits;
172 INFO(
"TCP-Notifier cannot handle this type of credential yet.");
175 auto wiegand_card = std::make_shared<Cred::RFIDCard>();
176 wiegand_card->card_id(card);
177 wiegand_card->nb_bits(bits);
183 const std::vector<std::string> &endpoints)
185 tcp_.set(zmqpp::socket_option::backlog, 5);
188 for (
auto &endpoint : endpoints)
190 INFO(
"TCP-Notifier binding to: tcp://" << endpoint);
191 tcp_.bind(
"tcp://" + endpoint);
196 for (
auto &endpoint : endpoints)
199 target.
url_ =
"tcp://" + endpoint;
204 targets_.push_back(std::move(target));