MIRA
|
Manages connections to other remote frameworks. More...
#include <fw/RemoteModule.h>
Classes | |
struct | AuthSettings |
Contains the authentication settings. More... | |
Public Types | |
enum | AuthMode { AUTH_NONE =0, AUTH_PASSWORD =1, AUTH_KEY =2 } |
Authentication mode. More... | |
typedef boost::shared_ptr< RemoteServer > | RemoteServerPtr |
typedef std::list< RemoteConnectionProxy > | ConnectionList |
typedef std::map< UUID, RemoteConnectionProxy > | ConnectionMap |
typedef std::list< KnownFramework > | KnownFrameworkList |
typedef std::list< ServiceLevel > | ServiceLevelList |
typedef std::map< std::string, ServiceLevel > | ServiceLevelMap |
typedef std::list< TypeServiceLevel > | TypeServiceLevelList |
typedef std::map< Typename, TypeServiceLevel > | TypeServiceLevelMap |
Public Member Functions | |
RemoteModule () | |
template<typename Reflector > | |
void | reflect (Reflector &r) |
void | setPort (uint16 port) |
Set the port of our TCP server. More... | |
uint16 | getPort () const |
Returns the port we listen on for incoming connections. More... | |
void | enablePTPSync (bool enable=true) |
Enable/Disable synchronization of clocks via PTP. More... | |
bool | isPTPSyncEnabled () const |
Returns true if PTP clock synchronization is enabled. More... | |
void | enablePingTimeout (bool enable=true) |
Enable/Disable the ping timeout. More... | |
bool | isPingTimeoutEnabled () const |
Returns true if ping timeout is enabled. More... | |
Duration | getPingInterval () const |
Return the ping interval. More... | |
Duration | getPingTimeout () const |
Return the ping timeout. More... | |
void | setAuthGroup (const std::string &group) |
Sets the working group for this framework. More... | |
void | setNoAuth () |
Resets passwords and keys, and sets authentication to "none". More... | |
void | setAuthPassword (const std::string &password) |
Enables the weak password based authentication mode and sets the password. More... | |
void | setAuthKey (const std::string &key) |
Enables the strong RSA key based authentication mode and sets the key. More... | |
void | setAuthKeyFile (const std::string &keyfile) |
Enables the strong RSA key based authentication mode and sets the key file. More... | |
const AuthSettings & | getAuthSettings () const |
Returns the current authentication settings. More... | |
void | setExitOnDisconnectTimeout (Duration timeout) |
Sets the timeout to exit on disconnect, closes the framework if a connection is closed or can not be established for this time (set Duration::invalid() to disable) More... | |
const UUID & | getID () const |
Returns the unique ID of the remote framework. More... | |
ServiceLevel | getServiceLevel (const std::string &channelID, const Typename &channelType) |
Get the level of service for given channel. More... | |
void | start () |
Start the remote framework. More... | |
void | stop () |
Stops the remote framework. More... | |
ScopedAccess< const ConnectionMap, boost::recursive_mutex > | getConnections () const |
Returns the map of connections. More... | |
void | addKnownFramework (const std::string &address) |
Adds the address of a framework to the list of known remote frameworks. More... | |
void | addKnownFramework (const std::string &address, bool forcePTP, bool legacyBinaryFormat, bool monitorOnly, const Duration &delayConnect=Duration::seconds(0)) |
Adds the address of a framework to the list of known remote frameworks. More... | |
void | disconnectFramework (const std::string &frameworkID, bool autoReconnect=false) |
Disconnects framework with given ID (if it is connected). More... | |
void | disconnectFrom (const std::string &address, bool autoReconnect=false) |
Disconnects framework with given address (if it is connected). More... | |
bool | isFrameworkConnected (const std::string &frameworkID) const |
Returns if a framework with given ID is connected with us. More... | |
bool | isConnectedTo (const std::string &address) const |
Returns if a framework with given address is connected to us. More... | |
void | migrateUnitToThisFramework (const std::string &id) |
Requests that the unit with the given id migrates to this framework. More... | |
void | updateIncomingStats (std::size_t size) |
Update statistics about incoming data. More... | |
void | updateOutgoingStats (std::size_t size) |
Update statistics about outgoing data. More... | |
std::size_t | getIncomingBytesPerSecond () const |
std::size_t | getOutgoingBytesPerSecond () const |
Internal functions that should not be called directly but cannot | |
be protected. | |
void | publishAuthority (const AuthorityDescription &authority) |
Publishes an authority to all connected remote frameworks. More... | |
void | unpublishAuthority (const AuthorityDescription &authority) |
Unpublishes an authority to all connected remote frameworks. More... | |
void | publishService (const std::string &service) |
Publishes a service to all connected remote frameworks. More... | |
void | unpublishService (const std::string &service) |
Unpublishes a service to all connected remote frameworks. More... | |
void | publishChannel (const std::string &channelID, const Typename &type) |
Notify all connected remote frameworks about the fact that we have a publisher for the given channel. More... | |
void | unpublishChannel (const std::string &channelID) |
Notify all connected remote frameworks about the fact that we have no longer a publisher for the given channel. More... | |
void | subscribeChannel (const std::string &channelID) |
Notify all connected remote frameworks about the fact that we have a subscriber for the given channel. More... | |
void | unsubscribeChannel (const std::string &channelID) |
Notify all connected remote frameworks that we no longer have a subscriber on the given channel. More... | |
Static Public Member Functions | |
static uint32 | getCurrentVersion () |
Returns the version of the communication protocol, that is supported by THIS framework. More... | |
Protected Member Functions | |
RemoteConnectionProxy | createIncomingConnection () |
RemoteConnectionProxy & | addPendingIncomingConnection (RemoteConnectionProxy &&proxy, bool start=true) |
Move a connection to the list of pending incoming connections. More... | |
void | removePendingIncomingConnection (RemoteConnection *connection) |
If there is a proxy for connection in the list of pending incoming connections, remove it. More... | |
RemoteConnectionProxy & | addPendingOutgoingConnection (RemoteConnectionProxy &&proxy, bool start=true) |
Move a connection to the list of pending outgoing connections. More... | |
void | removePendingOutgoingConnection (RemoteConnection *connection) |
If there is a proxy for connection in the list of pending outgoing connections, remove it. More... | |
void | onRemoteFrameworkDiscovered (const std::string &host, uint16 port, UUID id) |
Called when a new remote framework was discovered (e.g. More... | |
void | storeConnection (RemoteConnectionProxy iConnection) |
Add a connection to our internal map of connections (and update the property node). More... | |
void | eraseConnection (ConnectionMap::iterator it) |
Remove a connection from our internal map of connections (and update the property node). More... | |
bool | onIncomingConnected (RemoteIncomingConnection *iConnection) |
Called whenever a client connects to our server. More... | |
void | onIncomingDisconnected (RemoteIncomingConnection *iConnection) |
Called whenever a client disconnects from our server. More... | |
bool | onOutgoingConnected (RemoteOutgoingConnectionBase *iConnection) |
Called whenever we connect to a remote server. More... | |
void | onOutgoingDisconnected (RemoteOutgoingConnectionBase *iConnection) |
Called whenever one of our client disconnects from a remote server. More... | |
void | process () |
The main process method of the remote module. More... | |
void | startDisconnectTimeout () |
void | stopDisconnectTimeout () |
bool | checkDisconnectTimeout () |
Friends | |
class | RemoteConnection |
class | RemoteIncomingConnection |
class | RemoteOutgoingConnectionBase |
class | DiscoverService |
class | RemoteServer |
Manages connections to other remote frameworks.
Exchanges channel data, authorities, RPC calls and handles time synchronization between frameworks. The handshake protocol for establishing a connection between two frameworks is as follows:
typedef boost::shared_ptr<RemoteServer> RemoteServerPtr |
typedef std::list<RemoteConnectionProxy> ConnectionList |
typedef std::map<UUID, RemoteConnectionProxy> ConnectionMap |
typedef std::list<KnownFramework> KnownFrameworkList |
typedef std::list<ServiceLevel> ServiceLevelList |
typedef std::map<std::string, ServiceLevel> ServiceLevelMap |
typedef std::list<TypeServiceLevel> TypeServiceLevelList |
typedef std::map<Typename, TypeServiceLevel> TypeServiceLevelMap |
enum AuthMode |
RemoteModule | ( | ) |
|
inline |
|
static |
Returns the version of the communication protocol, that is supported by THIS framework.
|
inline |
Set the port of our TCP server.
If not specified it uses auto port
[in] | port | The port |
uint16 getPort | ( | ) | const |
Returns the port we listen on for incoming connections.
|
inline |
Enable/Disable synchronization of clocks via PTP.
|
inline |
Returns true if PTP clock synchronization is enabled.
|
inline |
Enable/Disable the ping timeout.
|
inline |
Returns true if ping timeout is enabled.
|
inline |
Return the ping interval.
|
inline |
Return the ping timeout.
void setAuthGroup | ( | const std::string & | group | ) |
Sets the working group for this framework.
The framework will be able to connect to other frameworks within the same group only. The default group is "".
void setNoAuth | ( | ) |
Resets passwords and keys, and sets authentication to "none".
void setAuthPassword | ( | const std::string & | password | ) |
Enables the weak password based authentication mode and sets the password.
Previously set RSA keys will be dropped.
void setAuthKey | ( | const std::string & | key | ) |
Enables the strong RSA key based authentication mode and sets the key.
A previously set password will be dropped.
void setAuthKeyFile | ( | const std::string & | keyfile | ) |
Enables the strong RSA key based authentication mode and sets the key file.
A previously set password will be dropped.
const AuthSettings& getAuthSettings | ( | ) | const |
Returns the current authentication settings.
|
inline |
Sets the timeout to exit on disconnect, closes the framework if a connection is closed or can not be established for this time (set Duration::invalid() to disable)
|
inline |
Returns the unique ID of the remote framework.
ServiceLevel getServiceLevel | ( | const std::string & | channelID, |
const Typename & | channelType | ||
) |
Get the level of service for given channel.
void start | ( | ) |
Start the remote framework.
Including the server.
void stop | ( | ) |
Stops the remote framework.
ScopedAccess<const ConnectionMap, boost::recursive_mutex> getConnections | ( | ) | const |
Returns the map of connections.
void addKnownFramework | ( | const std::string & | address | ) |
Adds the address of a framework to the list of known remote frameworks.
This module will try to connect to all known frameworks. It will also reconnect on connection loss.
[in] | address | Address of the remote framework in the form Host:Port. |
void addKnownFramework | ( | const std::string & | address, |
bool | forcePTP, | ||
bool | legacyBinaryFormat, | ||
bool | monitorOnly, | ||
const Duration & | delayConnect = Duration::seconds(0) |
||
) |
Adds the address of a framework to the list of known remote frameworks.
This module will try to connect to all known frameworks. It will also reconnect on connection loss.
[in] | address | Address of the remote framework in the form Host:Port. |
[in] | forcePTP | Force PTP time sync |
[in] | legacyBinaryFormat | If true, encode all binary data for remote connection using legacy serializer, thus it can communicate with legacy framework. |
[in] | monitorOnly | If true, do not publish local channels, services and authorities to remote. |
[in] | delayConnect | Wait for this duration before trying to connect. |
void disconnectFramework | ( | const std::string & | frameworkID, |
bool | autoReconnect = false |
||
) |
Disconnects framework with given ID (if it is connected).
If autoReconnect is false the framework is removed from the list of known remote frameworks so there will be no reconnect.
void disconnectFrom | ( | const std::string & | address, |
bool | autoReconnect = false |
||
) |
Disconnects framework with given address (if it is connected).
If autoReconnect is false the framework is removed from the list of known remote frameworks so there will be no reconnect.
[in] | address | Address of the remote framework in the form Host:Port. |
[in] | autoReconnect | If true there will be a reconnect |
bool isFrameworkConnected | ( | const std::string & | frameworkID | ) | const |
Returns if a framework with given ID is connected with us.
bool isConnectedTo | ( | const std::string & | address | ) | const |
Returns if a framework with given address is connected to us.
[in] | address | Address of the remote framework in the form Host:Port. |
void migrateUnitToThisFramework | ( | const std::string & | id | ) |
Requests that the unit with the given id migrates to this framework.
If the unit is already located in this framework nothing happens. Otherwise the framework will ask all connected frameworks if they run a unit with the given id and if a request is sent to move the unit into this framework. The remote framework will serialize the unit, destroy it and send it to this framework where it is created out of its serialized state.
void publishAuthority | ( | const AuthorityDescription & | authority | ) |
Publishes an authority to all connected remote frameworks.
void unpublishAuthority | ( | const AuthorityDescription & | authority | ) |
Unpublishes an authority to all connected remote frameworks.
void publishService | ( | const std::string & | service | ) |
Publishes a service to all connected remote frameworks.
void unpublishService | ( | const std::string & | service | ) |
Unpublishes a service to all connected remote frameworks.
void publishChannel | ( | const std::string & | channelID, |
const Typename & | type | ||
) |
Notify all connected remote frameworks about the fact that we have a publisher for the given channel.
All frameworks will subscribe if they have a subscriber for this channel
[in] | channelID | The channel we have a publisher for. |
[in] | type | The typename of the channels type. |
void unpublishChannel | ( | const std::string & | channelID | ) |
Notify all connected remote frameworks about the fact that we have no longer a publisher for the given channel.
All frameworks will unsubscribe if they were subscribed to that channel.
[in] | channelID | The channel we have no more publishers for. |
void subscribeChannel | ( | const std::string & | channelID | ) |
Notify all connected remote frameworks about the fact that we have a subscriber for the given channel.
Subscribes on all remote frameworks that have a publisher for this channel. Remote frameworks will notify us on data changes.
[in] | channelID | The channel we have a subscriber for. |
void unsubscribeChannel | ( | const std::string & | channelID | ) |
Notify all connected remote frameworks that we no longer have a subscriber on the given channel.
We will not longer receive updates on that channel.
[in] | channelID | The channel we have no more subscribers for. |
void updateIncomingStats | ( | std::size_t | size | ) |
Update statistics about incoming data.
void updateOutgoingStats | ( | std::size_t | size | ) |
Update statistics about outgoing data.
std::size_t getIncomingBytesPerSecond | ( | ) | const |
std::size_t getOutgoingBytesPerSecond | ( | ) | const |
|
protected |
|
protected |
Move a connection to the list of pending incoming connections.
[in] | start | if true, call proxy->start() |
|
protected |
If there is a proxy for connection in the list of pending incoming connections, remove it.
|
protected |
Move a connection to the list of pending outgoing connections.
[in] | start | if true, call proxy->start() |
|
protected |
If there is a proxy for connection in the list of pending outgoing connections, remove it.
|
protected |
Called when a new remote framework was discovered (e.g.
via multi cast)
|
protected |
Add a connection to our internal map of connections (and update the property node).
[in] | iConnection | The connection pointer |
|
protected |
Remove a connection from our internal map of connections (and update the property node).
[in] | it | Iterator to the entry to be removed |
|
protected |
Called whenever a client connects to our server.
[in] | iConnection | The connection pointer |
|
protected |
Called whenever a client disconnects from our server.
[in] | iConnection | The connection pointer |
|
protected |
Called whenever we connect to a remote server.
[in] | iConnection | The connection pointer |
|
protected |
Called whenever one of our client disconnects from a remote server.
[in] | iConnection | The connection pointer |
|
protected |
The main process method of the remote module.
Tries to connect to known remote frameworks and does time synchronization between frameworks.
|
protected |
|
protected |
|
protected |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
mutableprotected |