MIRA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
RemoteModule Class Reference

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< KnownFrameworkKnownFrameworkList
 
typedef std::list< ServiceLevelServiceLevelList
 
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 AuthSettingsgetAuthSettings () 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 UUIDgetID () 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 ()
 
RemoteConnectionProxyaddPendingIncomingConnection (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...
 
RemoteConnectionProxyaddPendingOutgoingConnection (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 ()
 

Protected Attributes

PerformanceStatistics mIncomingStats
 
PerformanceStatistics mOutgoingStats
 
uint32 mIncomingData
 
uint32 mOutgoingData
 
CyclicRunnable mCyclicRunnable
 
DiscoverServicePtr mDiscoverService
 
boost::thread mThread
 
uint16 mPort
 
bool mEnablePTPSync
 
bool mEnablePingTimeout
 
Duration mPingInterval
 
Duration mPingTimeout
 
uint16 mIOThreadCount
 
UUID mID
 
RemoteServerPtr mServer
 
ConnectionList mPendingOutgoingConnections
 
ConnectionList mPendingIncomingConnections
 
ConnectionMap mConnections
 
RemoteConnectionPool mRemoteConnectionPool
 
AuthSettings mAuthSettings
 
Duration mExitOnDisconnectTimeout
 
Time mDisconnectedSince
 
KnownFrameworkList mKnownFrameworks
 
ServiceLevelList mServiceLevels
 
TypeServiceLevelList mTypeServiceLevels
 
ServiceLevelMap mChannelServiceLevels
 
TypeServiceLevelMap mChannelTypeServiceLevels
 
boost::recursive_mutex mConnectionMutex
 

Friends

class RemoteConnection
 
class RemoteIncomingConnection
 
class RemoteOutgoingConnectionBase
 
class DiscoverService
 
class RemoteServer
 

Detailed Description

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:

No Authentication
Client Server
| |
| CONNECT_MSG: Version, Group, ClientIDs, AuthMode 0 |
|--------------------------------------------------->|
| |
| CONNECT_ACCEPT_MSG: ServerIDs Version |
|<---------------------------------------------------|
On error (e.g. wrong version, wrong authentication, etc)
| CONNECT_DENIED_MSG: message |
|<---------------------------------------------------|
Password Authentication
Client Server
| CONNECT_MSG: Version, ClientIDs, AuthMode 1, PW |
|--------------------------------------------------->|
| |
| CONNECT_ACCEPT_MSG: ServerIDs Version |
|<---------------------------------------------------|
On error
| CONNECT_DENIED_MSG: message |
|<---------------------------------------------------|
Key Authentication
Client Server
| CONNECT_MSG: Version, ClientIDs, AuthMode 2, Msg1 |
|--------------------------------------------------->|
| |
| SERVER_AUTH_MSG: Signed Msg1, Msg2 |
|<---------------------------------------------------|
| |
| CLIENT_AUTH_MSG: Signed Msg2 |
|--------------------------------------------------->|
| |
| CONNECT_ACCEPT_MSG: ServerIDs Version |
|<---------------------------------------------------|
On error
| CONNECT_DENIED_MSG: message |
|<---------------------------------------------------|
CONNECT_DENIED_MSG is sent from server only,
clients simply close the connection on error.

Member Typedef Documentation

typedef boost::shared_ptr<RemoteServer> RemoteServerPtr
typedef std::list<KnownFramework> KnownFrameworkList
typedef std::list<ServiceLevel> ServiceLevelList
typedef std::map<std::string, ServiceLevel> ServiceLevelMap

Member Enumeration Documentation

enum AuthMode

Authentication mode.

Enumerator
AUTH_NONE 
AUTH_PASSWORD 
AUTH_KEY 

Constructor & Destructor Documentation

Member Function Documentation

void reflect ( Reflector &  r)
inline
static uint32 getCurrentVersion ( )
static

Returns the version of the communication protocol, that is supported by THIS framework.

void setPort ( uint16  port)
inline

Set the port of our TCP server.

If not specified it uses auto port

Parameters
[in]portThe port
uint16 getPort ( ) const

Returns the port we listen on for incoming connections.

void enablePTPSync ( bool  enable = true)
inline

Enable/Disable synchronization of clocks via PTP.

bool isPTPSyncEnabled ( ) const
inline

Returns true if PTP clock synchronization is enabled.

void enablePingTimeout ( bool  enable = true)
inline

Enable/Disable the ping timeout.

bool isPingTimeoutEnabled ( ) const
inline

Returns true if ping timeout is enabled.

Duration getPingInterval ( ) const
inline

Return the ping interval.

Duration getPingTimeout ( ) const
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.

void setExitOnDisconnectTimeout ( Duration  timeout)
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)

const UUID& getID ( ) const
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.

Parameters
[in]addressAddress 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.

Parameters
[in]addressAddress of the remote framework in the form Host:Port.
[in]forcePTPForce PTP time sync
[in]legacyBinaryFormatIf true, encode all binary data for remote connection using legacy serializer, thus it can communicate with legacy framework.
[in]monitorOnlyIf true, do not publish local channels, services and authorities to remote.
[in]delayConnectWait 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.

Parameters
[in]addressAddress of the remote framework in the form Host:Port.
[in]autoReconnectIf 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.

Parameters
[in]addressAddress 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

Parameters
[in]channelIDThe channel we have a publisher for.
[in]typeThe 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.

Parameters
[in]channelIDThe 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.

Parameters
[in]channelIDThe 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.

Parameters
[in]channelIDThe 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
RemoteConnectionProxy createIncomingConnection ( )
protected
RemoteConnectionProxy& addPendingIncomingConnection ( RemoteConnectionProxy &&  proxy,
bool  start = true 
)
protected

Move a connection to the list of pending incoming connections.

Parameters
[in]startif true, call proxy->start()
void removePendingIncomingConnection ( RemoteConnection connection)
protected

If there is a proxy for connection in the list of pending incoming connections, remove it.

RemoteConnectionProxy& addPendingOutgoingConnection ( RemoteConnectionProxy &&  proxy,
bool  start = true 
)
protected

Move a connection to the list of pending outgoing connections.

Parameters
[in]startif true, call proxy->start()
void removePendingOutgoingConnection ( RemoteConnection connection)
protected

If there is a proxy for connection in the list of pending outgoing connections, remove it.

void onRemoteFrameworkDiscovered ( const std::string &  host,
uint16  port,
UUID  id 
)
protected

Called when a new remote framework was discovered (e.g.

via multi cast)

void storeConnection ( RemoteConnectionProxy  iConnection)
protected

Add a connection to our internal map of connections (and update the property node).

Parameters
[in]iConnectionThe connection pointer
void eraseConnection ( ConnectionMap::iterator  it)
protected

Remove a connection from our internal map of connections (and update the property node).

Parameters
[in]itIterator to the entry to be removed
bool onIncomingConnected ( RemoteIncomingConnection iConnection)
protected

Called whenever a client connects to our server.

Parameters
[in]iConnectionThe connection pointer
Returns
true if connection is accepted, false if not
void onIncomingDisconnected ( RemoteIncomingConnection iConnection)
protected

Called whenever a client disconnects from our server.

Parameters
[in]iConnectionThe connection pointer
bool onOutgoingConnected ( RemoteOutgoingConnectionBase iConnection)
protected

Called whenever we connect to a remote server.

Parameters
[in]iConnectionThe connection pointer
Returns
true if connection is accepted, false if not
void onOutgoingDisconnected ( RemoteOutgoingConnectionBase iConnection)
protected

Called whenever one of our client disconnects from a remote server.

Parameters
[in]iConnectionThe connection pointer
void process ( )
protected

The main process method of the remote module.

Tries to connect to known remote frameworks and does time synchronization between frameworks.

void startDisconnectTimeout ( )
protected
void stopDisconnectTimeout ( )
protected
bool checkDisconnectTimeout ( )
protected

Friends And Related Function Documentation

friend class RemoteConnection
friend
friend class RemoteIncomingConnection
friend
friend class RemoteOutgoingConnectionBase
friend
friend class DiscoverService
friend
friend class RemoteServer
friend

Member Data Documentation

PerformanceStatistics mIncomingStats
protected
PerformanceStatistics mOutgoingStats
protected
uint32 mIncomingData
protected
uint32 mOutgoingData
protected
CyclicRunnable mCyclicRunnable
protected
DiscoverServicePtr mDiscoverService
protected
boost::thread mThread
protected
uint16 mPort
protected
bool mEnablePTPSync
protected
bool mEnablePingTimeout
protected
Duration mPingInterval
protected
Duration mPingTimeout
protected
uint16 mIOThreadCount
protected
UUID mID
protected
RemoteServerPtr mServer
protected
ConnectionList mPendingOutgoingConnections
protected
ConnectionList mPendingIncomingConnections
protected
ConnectionMap mConnections
protected
RemoteConnectionPool mRemoteConnectionPool
protected
AuthSettings mAuthSettings
protected
Duration mExitOnDisconnectTimeout
protected
Time mDisconnectedSince
protected
KnownFrameworkList mKnownFrameworks
protected
ServiceLevelList mServiceLevels
protected
TypeServiceLevelList mTypeServiceLevels
protected
ServiceLevelMap mChannelServiceLevels
protected
TypeServiceLevelMap mChannelTypeServiceLevels
protected
boost::recursive_mutex mConnectionMutex
mutableprotected

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