37 #ifndef _PROTOBUF_COMM_PEER_H_ 38 #define _PROTOBUF_COMM_PEER_H_ 40 #include <google/protobuf/message.h> 41 #include <protobuf_comm/frame_header.h> 42 #include <protobuf_comm/message_register.h> 43 #include <protobuf_comm/queue_entry.h> 45 #include <boost/asio.hpp> 46 #include <boost/signals2.hpp> 51 namespace protobuf_comm {
53 class BufferEncryptor;
54 class BufferDecryptor;
64 unsigned short send_to_port,
65 unsigned short recv_on_port);
68 std::vector<std::string> &proto_path);
70 unsigned short send_to_port,
71 unsigned short recv_on_port,
72 std::vector<std::string> &proto_path);
75 unsigned short send_to_port,
76 unsigned short recv_on_port,
78 frame_header_version_t header_version = PB_FRAME_V2);
81 const std::string crypto_key,
82 const std::string cipher =
"aes-128-ecb");
86 const std::string crypto_key,
87 const std::string cipher =
"aes-128-ecb");
89 unsigned short send_to_port,
90 unsigned short recv_on_port,
91 const std::string crypto_key,
92 const std::string cipher =
"aes-128-ecb");
94 unsigned short send_to_port,
95 unsigned short recv_on_port,
97 const std::string crypto_key,
98 const std::string cipher =
"aes-128-ecb");
103 void send(uint16_t component_id, uint16_t msg_type, google::protobuf::Message &m);
104 void send(uint16_t component_id, uint16_t msg_type, std::shared_ptr<google::protobuf::Message> m);
105 void send(std::shared_ptr<google::protobuf::Message> m);
106 void send(google::protobuf::Message &m);
110 void setup_crypto(
const std::string &key,
const std::string &cipher);
118 return *message_register_;
122 typedef boost::signals2::signal<void(boost::asio::ip::udp::endpoint &,
125 std::shared_ptr<google::protobuf::Message>)>
129 typedef boost::signals2::signal<
130 void(boost::asio::ip::udp::endpoint &,
frame_header_t &,
void *,
size_t)>
134 typedef boost::signals2::signal<void(boost::asio::ip::udp::endpoint &, std::string)>
157 return sig_rcvd_raw_;
166 return sig_recv_error_;
175 return sig_send_error_;
179 void ctor(
const std::string &address,
180 unsigned int send_to_port,
181 const std::string crypto_key =
"",
182 const std::string cipher =
"aes-128-ecb",
183 frame_header_version_t = PB_FRAME_V2);
184 void determine_local_endpoints();
188 void start_resolve();
189 void retry_resolve(
const boost::system::error_code &ec);
190 void handle_resolve(
const boost::system::error_code & err,
191 boost::asio::ip::udp::resolver::iterator endpoint_iterator);
192 void handle_sent(
const boost::system::error_code &error,
195 void handle_recv(
const boost::system::error_code &error,
size_t bytes_rcvd);
198 boost::asio::io_service io_service_;
199 boost::asio::ip::udp::resolver resolver_;
200 boost::asio::ip::udp::socket socket_;
201 boost::asio::deadline_timer resolve_retry_timer_;
203 std::list<boost::asio::ip::udp::endpoint> local_endpoints_;
210 std::string send_to_address_;
211 unsigned int send_to_port_;
213 std::queue<QueueEntry *> outbound_queue_;
214 std::mutex outbound_mutex_;
215 bool outbound_active_;
216 bool outbound_ready_;
218 boost::asio::ip::udp::endpoint outbound_endpoint_;
219 boost::asio::ip::udp::endpoint in_endpoint_;
223 size_t in_data_size_;
224 size_t enc_in_data_size_;
228 std::thread asio_thread_;
230 bool own_message_register_;
232 frame_header_version_t frame_header_version_;
maximum packet length in bytes
boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, frame_header_t &, void *, size_t)> signal_received_raw_type
Boost signal for a received raw message.
void send(uint16_t component_id, uint16_t msg_type, google::protobuf::Message &m)
Send a message to other peers.
void send_raw(const frame_header_t &frame_header, const void *data, size_t data_size)
Send a raw message.
Register to map msg type numbers to Protobuf messages.
boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, uint16_t, uint16_t, std::shared_ptr< google::protobuf::Message >)> signal_received_type
Boost signal for a received message.
boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, std::string)> signal_recv_error_type
Boost signal for an error during receiving a message.
void setup_crypto(const std::string &key, const std::string &cipher)
Setup encryption.
Communicate by broadcasting protobuf messages.
signal_send_error_type & signal_send_error()
Signal that is invoked when sending a message failed.
signal_received_type & signal_received()
Signal that is invoked when a message has been received.
Decrypt buffers encrypted with BufferEncryptor.
ProtobufBroadcastPeer(const std::string address, unsigned short port)
Constructor.
void set_filter_self(bool filter)
Set if to filter out own messages.
signal_received_raw_type & signal_received_raw()
Signal that is invoked when a message has been received.
boost::signals2::signal< void(std::string)> signal_send_error_type
Boost signal for an error during sending a message.
signal_recv_error_type & signal_recv_error()
Signal that is invoked when receiving a message failed.
~ProtobufBroadcastPeer()
Destructor.
Encrypt buffers using AES128 in ECB mode.
MessageRegister & message_register()
Get the server's message register.