Fawkes API
Fawkes Development Version
|
Communicate by broadcasting protobuf messages. More...
#include <>>
Public Types | |
enum | { max_packet_length = 1024 } |
Anonymus enum for constants. More... | |
typedef 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. More... | |
typedef 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. More... | |
typedef boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, std::string)> | signal_recv_error_type |
Boost signal for an error during receiving a message. More... | |
typedef boost::signals2::signal< void(std::string)> | signal_send_error_type |
Boost signal for an error during sending a message. More... | |
Public Member Functions | |
ProtobufBroadcastPeer (const std::string address, unsigned short port) | |
Constructor. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short send_to_port, unsigned short recv_on_port) | |
Testing constructor. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short port, std::vector< std::string > &proto_path) | |
Constructor. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short send_to_port, unsigned short recv_on_port, std::vector< std::string > &proto_path) | |
Testing constructor. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short port, MessageRegister *mr) | |
Constructor. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short send_to_port, unsigned short recv_on_port, MessageRegister *mr, frame_header_version_t header_version=PB_FRAME_V2) | |
Testing constructor. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short port, const std::string crypto_key, const std::string cipher="aes-128-ecb") | |
Constructor with encryption. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short port, MessageRegister *mr, const std::string crypto_key, const std::string cipher="aes-128-ecb") | |
Constructor with encryption. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short send_to_port, unsigned short recv_on_port, const std::string crypto_key, const std::string cipher="aes-128-ecb") | |
Constructor with encryption. More... | |
ProtobufBroadcastPeer (const std::string address, unsigned short send_to_port, unsigned short recv_on_port, MessageRegister *mr, const std::string crypto_key, const std::string cipher="aes-128-ecb") | |
Constructor with encryption. More... | |
~ProtobufBroadcastPeer () | |
Destructor. More... | |
void | set_filter_self (bool filter) |
Set if to filter out own messages. More... | |
void | send (uint16_t component_id, uint16_t msg_type, google::protobuf::Message &m) |
Send a message to other peers. More... | |
void | send (uint16_t component_id, uint16_t msg_type, std::shared_ptr< google::protobuf::Message > m) |
Send a message to other peers. More... | |
void | send (std::shared_ptr< google::protobuf::Message > m) |
Send a message to other peers. More... | |
void | send (google::protobuf::Message &m) |
Send a message to other peers. More... | |
void | send_raw (const frame_header_t &frame_header, const void *data, size_t data_size) |
Send a raw message. More... | |
void | setup_crypto (const std::string &key, const std::string &cipher) |
Setup encryption. More... | |
MessageRegister & | message_register () |
Get the server's message register. More... | |
signal_received_type & | signal_received () |
Signal that is invoked when a message has been received. More... | |
signal_received_raw_type & | signal_received_raw () |
Signal that is invoked when a message has been received. More... | |
signal_recv_error_type & | signal_recv_error () |
Signal that is invoked when receiving a message failed. More... | |
signal_send_error_type & | signal_send_error () |
Signal that is invoked when sending a message failed. More... | |
Communicate by broadcasting protobuf messages.
This class allows to communicate via UDP by broadcasting messages to the network.
typedef boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, frame_header_t &, void *, size_t)> protobuf_comm::ProtobufBroadcastPeer::signal_received_raw_type |
typedef boost::signals2::signal<void(boost::asio::ip::udp::endpoint &, uint16_t, uint16_t, std::shared_ptr<google::protobuf::Message>)> protobuf_comm::ProtobufBroadcastPeer::signal_received_type |
typedef boost::signals2::signal<void(boost::asio::ip::udp::endpoint &, std::string)> protobuf_comm::ProtobufBroadcastPeer::signal_recv_error_type |
typedef boost::signals2::signal<void(std::string)> protobuf_comm::ProtobufBroadcastPeer::signal_send_error_type |
anonymous enum |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | port | ||
) |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | send_to_port, | ||
unsigned short | recv_on_port | ||
) |
Testing constructor.
This constructor listens and sends to different ports. It can be used to send and receive on the same host or even from within the same process. It is most useful for communication tests.
address | IPv4 address to send to |
send_to_port | IPv4 UDP port to send data to |
recv_on_port | IPv4 UDP port to receive data on |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | port, | ||
std::vector< std::string > & | proto_path | ||
) |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | send_to_port, | ||
unsigned short | recv_on_port, | ||
std::vector< std::string > & | proto_path | ||
) |
Testing constructor.
This constructor listens and sends to different ports. It can be used to send and receive on the same host or even from within the same process. It is most useful for communication tests.
address | IPv4 address to send to |
send_to_port | IPv4 UDP port to send data to |
recv_on_port | IPv4 UDP port to receive data on |
proto_path | list of file system paths where to look for proto files |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | port, | ||
MessageRegister * | mr | ||
) |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | send_to_port, | ||
unsigned short | recv_on_port, | ||
MessageRegister * | mr, | ||
frame_header_version_t | header_version = PB_FRAME_V2 |
||
) |
Testing constructor.
This constructor listens and sends to different ports. It can be used to send and receive on the same host or even from within the same process. It is most useful for communication tests.
address | IPv4 address to send to |
send_to_port | IPv4 UDP port to send data to |
recv_on_port | IPv4 UDP port to receive data on |
mr | message register to query for message types |
header_version | which frame header version to send, use with caution |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | port, | ||
const std::string | crypto_key, | ||
const std::string | cipher = "aes-128-ecb" |
||
) |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | port, | ||
MessageRegister * | mr, | ||
const std::string | crypto_key, | ||
const std::string | cipher = "aes-128-ecb" |
||
) |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | send_to_port, | ||
unsigned short | recv_on_port, | ||
const std::string | crypto_key, | ||
const std::string | cipher = "aes-128-ecb" |
||
) |
protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer | ( | const std::string | address, |
unsigned short | send_to_port, | ||
unsigned short | recv_on_port, | ||
MessageRegister * | mr, | ||
const std::string | crypto_key, | ||
const std::string | cipher = "aes-128-ecb" |
||
) |
Constructor with encryption.
address | IPv4 broadcast address to send to |
send_to_port | IPv4 UDP port to send data to |
recv_on_port | IPv4 UDP port to receive data on |
mr | message register to query for message types |
crypto_key | encryption key for messages |
cipher | cipher to use for encryption |
protobuf_comm::ProtobufBroadcastPeer::~ProtobufBroadcastPeer | ( | ) |
|
inline |
void protobuf_comm::ProtobufBroadcastPeer::send | ( | uint16_t | component_id, |
uint16_t | msg_type, | ||
google::protobuf::Message & | m | ||
) |
Send a message to other peers.
component_id | ID of the component to address |
msg_type | numeric message type |
m | message to send |
Definition at line 575 of file peer.cpp.
References protobuf_comm::QueueEntry::buffers, protobuf_comm::message_header_t::component_id, protobuf_comm::frame_header_v1_t::component_id, protobuf_comm::QueueEntry::frame_header, protobuf_comm::QueueEntry::frame_header_v1, max_packet_length, protobuf_comm::QueueEntry::message_header, protobuf_comm::message_header_t::msg_type, protobuf_comm::frame_header_v1_t::msg_type, protobuf_comm::frame_header_t::payload_size, protobuf_comm::frame_header_v1_t::payload_size, protobuf_comm::MessageRegister::serialize(), and protobuf_comm::QueueEntry::serialized_message.
Referenced by send().
void protobuf_comm::ProtobufBroadcastPeer::send | ( | uint16_t | component_id, |
uint16_t | msg_type, | ||
std::shared_ptr< google::protobuf::Message > | m | ||
) |
void protobuf_comm::ProtobufBroadcastPeer::send | ( | std::shared_ptr< google::protobuf::Message > | m | ) |
void protobuf_comm::ProtobufBroadcastPeer::send | ( | google::protobuf::Message & | m | ) |
void protobuf_comm::ProtobufBroadcastPeer::send_raw | ( | const frame_header_t & | frame_header, |
const void * | data, | ||
size_t | data_size | ||
) |
Send a raw message.
The message is sent as-is (frame_header appended by message data) over the wire.
frame_header | frame header to prepend, must be completely and properly setup. |
data | data buffer, maybe encrypted (if indicated in frame header) |
data_size | size in bytes of data |
Definition at line 617 of file peer.cpp.
References protobuf_comm::QueueEntry::buffers, protobuf_comm::QueueEntry::frame_header, and protobuf_comm::QueueEntry::serialized_message.
void protobuf_comm::ProtobufBroadcastPeer::set_filter_self | ( | bool | filter | ) |
void protobuf_comm::ProtobufBroadcastPeer::setup_crypto | ( | const std::string & | key, |
const std::string & | cipher | ||
) |
Setup encryption.
After this call communication will be encrypted. Note that the first received message might be considered invalid because we are still listening for plain text messages. To avoid this use the constructor which takes the encryption key as parameter.
key | encryption key |
cipher | cipher to use for encryption |
|
inline |
Signal that is invoked when a message has been received.
Definition at line 144 of file peer.h.
Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto().
|
inline |
|
inline |
Signal that is invoked when receiving a message failed.
Definition at line 164 of file peer.h.
Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto().
|
inline |
Signal that is invoked when sending a message failed.
Definition at line 173 of file peer.h.
Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto().