C++ Actor Framework 1.0.0
|
A broker implementation for the Binary Actor System Protocol (BASP). More...
#include <basp_broker.hpp>
Public Types | |
using | super = broker |
using | ctx_map = std::unordered_map<connection_handle, basp::endpoint_context> |
using | monitored_actor_map = std::unordered_map<actor_addr, std::unordered_set<node_id>> |
Public Types inherited from caf::io::broker | |
using | super = extended_base |
using | signatures = none_t |
using | behavior_type = behavior |
Public Member Functions | |
basp_broker (actor_config &cfg) | |
void | on_exit () override |
const char * | name () const override |
behavior | make_behavior () override |
proxy_registry * | proxy_registry_ptr () override |
resume_result | resume (scheduler *, size_t) override |
strong_actor_ptr | make_proxy (node_id nid, actor_id aid) override |
Creates a new proxy instance. | |
void | set_last_hop (node_id *ptr) override |
Sets the thread-local last-hop pointer to detect indirect connections. | |
void | finalize_handshake (const node_id &nid, actor_id aid, std::set< std::string > &sigs) override |
Called if a server handshake was received and the connection to nid is established. | |
void | purge_state (const node_id &nid) override |
Called whenever a direct connection was closed or a node became unreachable for other reasons before this node gets erased from the routing table. | |
void | proxy_announced (const node_id &nid, actor_id aid) override |
Called whenever a remote node created a proxy for one of our local actors. | |
void | learned_new_node_directly (const node_id &nid, bool was_indirectly_before) override |
Called whenever BASP learns the ID of a remote node to which it does not have a direct connection. | |
void | learned_new_node_indirectly (const node_id &nid) override |
Called whenever BASP learns the ID of a remote node to which it does not have a direct connection. | |
byte_buffer & | get_buffer (connection_handle hdl) override |
Returns a reference to the sent buffer. | |
void | flush (connection_handle hdl) override |
Flushes the underlying write buffer of hdl . | |
void | handle_heartbeat () override |
Called if a heartbeat was received from nid | |
scheduler * | current_scheduler () override |
Returns the current CAF scheduler context. | |
strong_actor_ptr | this_actor () override |
Returns a handle to the callee actor. | |
void | emit_node_down_msg (const node_id &node, const error &reason) |
Sends node_down_msg to all registered observers. | |
void | learned_new_node (const node_id &nid) |
Performs bookkeeping such as managing spawn_servers . | |
void | set_context (connection_handle hdl) |
Sets this_context by either creating or accessing state for hdl . | |
void | connection_cleanup (connection_handle hdl, sec code) |
Cleans up any state for hdl . | |
void | send_basp_down_message (const node_id &nid, actor_id aid, error err) |
Sends a basp::down_message message to a remote node. | |
actor_system & | system () |
const actor_system_config & | config () |
const node_id & | this_node () const |
Returns the node identifier of the underlying BASP instance. | |
Public Member Functions inherited from caf::io::broker | |
template<class F , class... Ts> | |
infer_handle_from_fun_t< F > | fork (F fun, connection_handle hdl, Ts &&... xs) |
void | initialize () override |
template<class... Args> | |
auto | mail (Args &&... args) |
Starts a new message. | |
template<class T , class... Ts> | |
void | become (T &&arg, Ts &&... args) |
Changes the behavior of this actor. | |
void | unbecome () |
Removes the last added behavior. | |
Public Member Functions inherited from caf::io::abstract_broker | |
abstract_broker (abstract_broker &&)=delete | |
abstract_broker (const abstract_broker &&)=delete | |
abstract_broker & | operator= (abstract_broker &&)=delete |
abstract_broker & | operator= (const abstract_broker &&)=delete |
bool | enqueue (mailbox_element_ptr, scheduler *) override |
void | launch (scheduler *eu, bool lazy, bool hide) override |
void | on_cleanup (const error &reason) override |
resume_result | resume (scheduler *, size_t) override |
template<class Handle > | |
void | halt (Handle hdl) |
Suspends activities on hdl unconditionally. | |
template<class Handle > | |
void | trigger (Handle hdl) |
Allows activities on hdl unconditionally (default). | |
template<class Handle > | |
void | trigger (Handle hdl, size_t num_events) |
Allows num_events activities on hdl . | |
void | configure_read (connection_handle hdl, receive_policy::config cfg) |
Modifies the receive policy for a given connection. | |
void | ack_writes (connection_handle hdl, bool enable) |
Enables or disables write notifications for a given connection. | |
byte_buffer & | wr_buf (connection_handle hdl) |
Returns the write buffer for a given connection. | |
void | write (connection_handle hdl, size_t bs, const void *buf) |
Writes data into the buffer for a given connection. | |
void | write (connection_handle hdl, span< const std::byte > buf) |
Writes buf into the buffer for a given connection. | |
void | flush (connection_handle hdl) |
Sends the content of the buffer for a given connection. | |
void | ack_writes (datagram_handle hdl, bool enable) |
Enables or disables write notifications for a given datagram socket. | |
byte_buffer & | wr_buf (datagram_handle hdl) |
Returns the write buffer for a given sink. | |
void | enqueue_datagram (datagram_handle, byte_buffer) |
Enqueue a buffer to be sent as a datagram via a given endpoint. | |
void | write (datagram_handle hdl, size_t data_size, const void *data) |
Writes data into the buffer of a given sink. | |
void | flush (datagram_handle hdl) |
Sends the content of the buffer to a UDP endpoint. | |
middleman & | parent () |
Returns the middleman instance this broker belongs to. | |
void | add_scribe (scribe_ptr ptr) |
Adds the uninitialized scribe instance ptr to this broker. | |
connection_handle | add_scribe (network::native_socket fd) |
Creates and assigns a new scribe from given native socked fd . | |
expected< connection_handle > | add_tcp_scribe (const std::string &host, uint16_t port) |
Tries to connect to host on given port and creates a new scribe describing the connection afterwards. | |
void | move_scribe (scribe_ptr ptr) |
Moves the initialized scribe instance ptr from another broker to this broker. | |
void | add_doorman (doorman_ptr ptr) |
Adds a doorman instance to this broker. | |
accept_handle | add_doorman (network::native_socket fd) |
Creates and assigns a new doorman from given native socked fd . | |
void | move_doorman (doorman_ptr ptr) |
Adds a doorman instance to this broker. | |
expected< std::pair< accept_handle, uint16_t > > | add_tcp_doorman (uint16_t port=0, const char *in=nullptr, bool reuse_addr=false) |
Tries to open a local port and creates a doorman managing it on success. | |
void | add_datagram_servant (datagram_servant_ptr ptr) |
Adds a datagram_servant to this broker. | |
void | add_hdl_for_datagram_servant (datagram_servant_ptr ptr, datagram_handle hdl) |
Adds the datagram_servant under an additional hdl . | |
datagram_handle | add_datagram_servant (network::native_socket fd) |
Creates and assigns a new datagram_servant from a given socket fd . | |
datagram_handle | add_datagram_servant_for_endpoint (network::native_socket fd, const network::ip_endpoint &ep) |
Creates and assigns a new datagram_servant from a given socket fd for the remote endpoint ep . | |
expected< datagram_handle > | add_udp_datagram_servant (const std::string &host, uint16_t port) |
Creates a new datagram_servant for the remote endpoint host and port . | |
expected< std::pair< datagram_handle, uint16_t > > | add_udp_datagram_servant (uint16_t port=0, const char *in=nullptr, bool reuse_addr=false) |
Tries to open a local port and creates a datagram_servant managing it on success. | |
void | move_datagram_servant (datagram_servant_ptr ptr) |
Moves an initialized datagram_servant instance ptr from another broker to this one. | |
std::string | remote_addr (connection_handle hdl) |
Returns the remote address associated with hdl or empty string if hdl is invalid. | |
uint16_t | remote_port (connection_handle hdl) |
Returns the remote port associated with hdl or 0 if hdl is invalid. | |
std::string | local_addr (accept_handle hdl) |
Returns the local address associated with hdl or empty string if hdl is invalid. | |
uint16_t | local_port (accept_handle hdl) |
Returns the local port associated with hdl or 0 if hdl is invalid. | |
accept_handle | hdl_by_port (uint16_t port) |
Returns the handle associated with given local port or none . | |
datagram_handle | datagram_hdl_by_port (uint16_t port) |
Returns the dgram handle associated with given local port or none . | |
std::string | remote_addr (datagram_handle hdl) |
Returns the remote address associated with hdl or an empty string if hdl is invalid. | |
uint16_t | remote_port (datagram_handle hdl) |
Returns the remote port associated with hdl or 0 if hdl is invalid. | |
uint16_t | local_port (datagram_handle hdl) |
Returns the remote port associated with hdl or 0 if hdl is invalid. | |
bool | remove_endpoint (datagram_handle hdl) |
Remove the endpoint hdl from the broker. | |
void | close_all () |
Closes all connections and acceptors. | |
template<class Handle > | |
bool | close (Handle hdl) |
Closes the connection or acceptor identified by handle . | |
template<class Handle > | |
bool | valid (Handle hdl) |
Checks whether hdl is assigned to broker. | |
const char * | name () const override |
subtype_t | subtype () const noexcept override |
size_t | num_connections () const noexcept |
Returns the number of open connections. | |
size_t | num_doormen () const noexcept |
Returns the number of attached doorman for accepting incoming connections. | |
std::vector< connection_handle > | connections () const |
Returns all handles of all scribe instances attached to this broker. | |
network::multiplexer & | backend () |
Returns the multiplexer running this broker. | |
Public Member Functions inherited from caf::io::basp::instance::callee | |
callee (actor_system &sys, proxy_registry::backend &backend) | |
proxy_registry & | proxies () |
Returns the actor namespace associated to this BASP protocol instance. | |
Public Attributes | ||
union { | ||
basp::instance instance | ||
}; | ||
Protocol instance of BASP. | ||
ctx_map | ctx | |
Keeps context information for all open connections. | ||
basp::endpoint_context * | this_context | |
points to the current context for callbacks. | ||
std::unordered_map< node_id, actor > | spawn_servers | |
Stores handles to spawn servers for other nodes. | ||
std::unordered_map< node_id, std::vector< actor_addr > > | node_observers | |
Keeps track of actors that wish to receive a node_down_msg if a particular node fails. | ||
bool | automatic_connections = false | |
Configures whether BASP automatically open new connections to optimize routing paths by forming a mesh between all nodes. | ||
monitored_actor_map | monitored_actors | |
Keeps track of nodes that monitor local actors. | ||
Additional Inherited Members | |
Protected Types inherited from caf::io::abstract_broker | |
using | doorman_map = std::unordered_map<accept_handle, intrusive_ptr<doorman>> |
using | scribe_map = std::unordered_map<connection_handle, intrusive_ptr<scribe>> |
using | datagram_servant_map = std::unordered_map<datagram_handle, intrusive_ptr<datagram_servant>> |
Protected Member Functions inherited from caf::io::abstract_broker | |
void | init_broker () |
abstract_broker (actor_config &cfg) | |
template<class Handle > | |
auto | by_id (Handle hdl) -> decltype(ptr_of(hdl)) |
Returns a scribe or doorman identified by hdl . | |
Protected Attributes inherited from caf::io::basp::instance::callee | |
proxy_registry | namespace_ |
A broker implementation for the Binary Actor System Protocol (BASP).
|
overridevirtual |
Returns the current CAF scheduler context.
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Called if a server handshake was received and the connection to nid
is established.
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Flushes the underlying write buffer of hdl
.
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Returns a reference to the sent buffer.
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Called if a heartbeat was received from nid
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Reimplemented from caf::io::broker.
|
overridevirtual |
Creates a new proxy instance.
Implements caf::proxy_registry::backend.
|
overridevirtual |
Called whenever a remote node created a proxy for one of our local actors.
Implements caf::io::basp::instance::callee.
|
overridevirtual |
Called whenever a direct connection was closed or a node became unreachable for other reasons before this node gets erased from the routing table.
Implements caf::io::basp::instance::callee.
void caf::io::basp_broker::set_context | ( | connection_handle | hdl | ) |
Sets this_context
by either creating or accessing state for hdl
.
Automatically sets endpoint_context::last_seen
to clock().now()
.
|
overridevirtual |
Sets the thread-local last-hop pointer to detect indirect connections.
Implements caf::proxy_registry::backend.
|
overridevirtual |
Returns a handle to the callee actor.
Implements caf::io::basp::instance::callee.
Stores handles to spawn servers for other nodes.
These servers are spawned whenever the broker learns a new node ID and tries to get a 'SpawnServ' instance on the remote side.