Fawkes API  Fawkes Development Version
protobuf_comm::ProtobufBroadcastPeer Class Reference

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...
 
MessageRegistermessage_register ()
 Get the server's message register. More...
 
signal_received_typesignal_received ()
 Signal that is invoked when a message has been received. More...
 
signal_received_raw_typesignal_received_raw ()
 Signal that is invoked when a message has been received. More...
 
signal_recv_error_typesignal_recv_error ()
 Signal that is invoked when receiving a message failed. More...
 
signal_send_error_typesignal_send_error ()
 Signal that is invoked when sending a message failed. More...
 

Detailed Description

Communicate by broadcasting protobuf messages.

This class allows to communicate via UDP by broadcasting messages to the network.

Author
Tim Niemueller

Definition at line 56 of file peer.h.

Member Typedef Documentation

◆ signal_received_raw_type

typedef boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, frame_header_t &, void *, size_t)> protobuf_comm::ProtobufBroadcastPeer::signal_received_raw_type

Boost signal for a received raw message.

Definition at line 131 of file peer.h.

◆ signal_received_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

Boost signal for a received message.

Definition at line 126 of file peer.h.

◆ signal_recv_error_type

typedef boost::signals2::signal<void(boost::asio::ip::udp::endpoint &, std::string)> protobuf_comm::ProtobufBroadcastPeer::signal_recv_error_type

Boost signal for an error during receiving a message.

Definition at line 135 of file peer.h.

◆ signal_send_error_type

typedef boost::signals2::signal<void(std::string)> protobuf_comm::ProtobufBroadcastPeer::signal_send_error_type

Boost signal for an error during sending a message.

Definition at line 138 of file peer.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Anonymus enum for constants.

Enumerator
max_packet_length 

maximum packet length in bytes

Definition at line 60 of file peer.h.

Constructor & Destructor Documentation

◆ ProtobufBroadcastPeer() [1/10]

protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer ( const std::string  address,
unsigned short  port 
)

Constructor.

Parameters
addressIPv4 broadcast address to send to
portIPv4 UDP port to listen on and to send to

Definition at line 59 of file peer.cpp.

◆ ProtobufBroadcastPeer() [2/10]

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.

Parameters
addressIPv4 address to send to
send_to_portIPv4 UDP port to send data to
recv_on_portIPv4 UDP port to receive data on

Definition at line 78 of file peer.cpp.

◆ ProtobufBroadcastPeer() [3/10]

protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer ( const std::string  address,
unsigned short  port,
std::vector< std::string > &  proto_path 
)

Constructor.

Parameters
addressIPv4 broadcast address to send to
portIPv4 UDP port to listen on and to send to
proto_pathlist of file system paths where to look for proto files

Definition at line 96 of file peer.cpp.

◆ ProtobufBroadcastPeer() [4/10]

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.

Parameters
addressIPv4 address to send to
send_to_portIPv4 UDP port to send data to
recv_on_portIPv4 UDP port to receive data on
proto_pathlist of file system paths where to look for proto files

Definition at line 118 of file peer.cpp.

◆ ProtobufBroadcastPeer() [5/10]

protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer ( const std::string  address,
unsigned short  port,
MessageRegister mr 
)

Constructor.

Parameters
addressIPv4 broadcast address to send to
portIPv4 UDP port to listen on and to send to
mrmessage register to query for message types

Definition at line 137 of file peer.cpp.

◆ ProtobufBroadcastPeer() [6/10]

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.

Parameters
addressIPv4 address to send to
send_to_portIPv4 UDP port to send data to
recv_on_portIPv4 UDP port to receive data on
mrmessage register to query for message types
header_versionwhich frame header version to send, use with caution

Definition at line 248 of file peer.cpp.

◆ ProtobufBroadcastPeer() [7/10]

protobuf_comm::ProtobufBroadcastPeer::ProtobufBroadcastPeer ( const std::string  address,
unsigned short  port,
const std::string  crypto_key,
const std::string  cipher = "aes-128-ecb" 
)

Constructor with encryption.

Parameters
addressIPv4 broadcast address to send to
portIPv4 UDP port to listen on and to send to
crypto_keyencryption key for messages
ciphercipher to use for encryption

Definition at line 202 of file peer.cpp.

◆ ProtobufBroadcastPeer() [8/10]

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" 
)

Constructor with encryption.

Parameters
addressIPv4 broadcast address to send to
portIPv4 UDP port to listen on and to send to
mrmessage register to query for message types
crypto_keyencryption key for messages
ciphercipher to use for encryption

Definition at line 223 of file peer.cpp.

◆ ProtobufBroadcastPeer() [9/10]

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" 
)

Constructor with encryption.

Parameters
addressIPv4 broadcast address to send to
send_to_portIPv4 UDP port to send data to
recv_on_portIPv4 UDP port to receive data on
crypto_keyencryption key for messages
ciphercipher to use for encryption

Definition at line 157 of file peer.cpp.

◆ ProtobufBroadcastPeer() [10/10]

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.

Parameters
addressIPv4 broadcast address to send to
send_to_portIPv4 UDP port to send data to
recv_on_portIPv4 UDP port to receive data on
mrmessage register to query for message types
crypto_keyencryption key for messages
ciphercipher to use for encryption

Definition at line 180 of file peer.cpp.

◆ ~ProtobufBroadcastPeer()

protobuf_comm::ProtobufBroadcastPeer::~ProtobufBroadcastPeer ( )

Destructor.

Definition at line 305 of file peer.cpp.

Member Function Documentation

◆ message_register()

MessageRegister& protobuf_comm::ProtobufBroadcastPeer::message_register ( )
inline

Get the server's message register.

Returns
message register

Definition at line 116 of file peer.h.

◆ send() [1/4]

void protobuf_comm::ProtobufBroadcastPeer::send ( google::protobuf::Message &  m)

Send a message to other peers.

Parameters
mMessage to send, the message must have an CompType enum type to specify component ID and message type.

Definition at line 665 of file peer.cpp.

References send().

◆ send() [2/4]

void protobuf_comm::ProtobufBroadcastPeer::send ( std::shared_ptr< google::protobuf::Message >  m)

Send a message to other peers.

Parameters
mMessage to send, the message must have an CompType enum type to specify component ID and message type.

Definition at line 655 of file peer.cpp.

References send().

◆ send() [3/4]

◆ send() [4/4]

void protobuf_comm::ProtobufBroadcastPeer::send ( uint16_t  component_id,
uint16_t  msg_type,
std::shared_ptr< google::protobuf::Message >  m 
)

Send a message to other peers.

Parameters
component_idID of the component to address
msg_typenumeric message type
mmessage to send

Definition at line 643 of file peer.cpp.

References send().

◆ send_raw()

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.

Parameters
frame_headerframe header to prepend, must be completely and properly setup.
datadata buffer, maybe encrypted (if indicated in frame header)
data_sizesize in bytes of data

Definition at line 618 of file peer.cpp.

References protobuf_comm::QueueEntry::buffers, protobuf_comm::QueueEntry::frame_header, and protobuf_comm::QueueEntry::serialized_message.

◆ set_filter_self()

void protobuf_comm::ProtobufBroadcastPeer::set_filter_self ( bool  filter)

Set if to filter out own messages.

Parameters
filtertrue to filter out own messages, false to receive them

Definition at line 386 of file peer.cpp.

◆ setup_crypto()

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.

Parameters
keyencryption key
ciphercipher to use for encryption
See also
BufferEncryptor for supported ciphers

Definition at line 333 of file peer.cpp.

◆ signal_received()

signal_received_type& protobuf_comm::ProtobufBroadcastPeer::signal_received ( )
inline

Signal that is invoked when a message has been received.

Returns
signal

Definition at line 144 of file peer.h.

Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto(), and protoboard::ProtobufThead::peer_create_local_crypto().

◆ signal_received_raw()

signal_received_raw_type& protobuf_comm::ProtobufBroadcastPeer::signal_received_raw ( )
inline

Signal that is invoked when a message has been received.

This allows access to the raw packet data. This allows, for example, to write an ecryption agnostic repeater.

Returns
signal

Definition at line 155 of file peer.h.

◆ signal_recv_error()

signal_recv_error_type& protobuf_comm::ProtobufBroadcastPeer::signal_recv_error ( )
inline

Signal that is invoked when receiving a message failed.

Returns
signal

Definition at line 164 of file peer.h.

Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto(), and protoboard::ProtobufThead::peer_create_local_crypto().

◆ signal_send_error()

signal_send_error_type& protobuf_comm::ProtobufBroadcastPeer::signal_send_error ( )
inline

Signal that is invoked when sending a message failed.

Returns
signal

Definition at line 173 of file peer.h.

Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto(), and protoboard::ProtobufThead::peer_create_local_crypto().


The documentation for this class was generated from the following files: