p2p::P2PServer

class kanzi::connect::p2p::P2PServer : public NetworkListener::Observer

Peer to Peer server functionality.

Public Functions

explicit P2PServer(ClientIdManager &cim, const string &reliableBearer, const string &unreliableBearer, ConnectDomain *domain, AbstractServiceSharedPtr service, RuntimeDataProvider *dataProvider)

Constructor.

Parameters
  • cim – client identity manager

  • reliableBearer – the default bearer for reliable communication

  • unreliableBearer – the default bearer for unreliable communication

  • domain – server side connect domain

  • service – the service bound to this P2P functionality

  • dataProvider – runtime data provider.

virtual ~P2PServer()

Destructor.

void disconnectAll()

Disconnects all connected peers.

void enableVerboseLogging(bool enable)

Controls verbose logging.

Parameters

enable – enables the verbose logging.

void flushPendingProviders()

Refresh updates pending for transfer credits.

ClientIdManager &getClientIdManager() const

Retrieve client id manager functionality.

Returns

client id manager instance.

ConnectDomain *getConnectDomain() const

Retrieve connect domain.

Returns

connect domain pointer, ownership not transfered.

string getDiagnosticsCounters(vector<DiagnosticsObject> &objects)

Will fill the provided array with known diagnostics variables.

Parameters

objects – vector to be filled with diagnostics objects.

Returns

the textual identifier (effectively a service name) to which entity the measurements belong into.

vector<EndpointSharedPtr> getEndpoints()

Gets all the endpoints this P2PServer has configured.

Returns

vector of endpoint definitions

RoutingRulesSharedPtr getRoutingRules()

Retrieve routing rules for the bound service.

Returns

routing rules bound to this server.

bool initialize(RoutingRules &rr, ConnectionAdapter::Parameters SSLParameters = ConnectionAdapter::Parameters())

Initialize and instantiate all required connection adapters.

Parameters
  • rr – routing rules that will be filled with connection endpoints accordingly.

  • SSLParameters – contains SSL parameters to be used with server side functionality. Required only if SSL bearer is to be used. Parameters should be passed with following keys “server_cert” Server certificate “server_pkey” Server private key “client_ca” Client CA certificate. “server_name” server name identitity (optional)

Returns

true if succeeded and operational. false otherwise.

void registerMessageFilter(messagefilter::ServiceMessageFilterHandler handler)

Register a message filter callback that is invoked for each and every incoming message.

Parameters

handler – the handler to be invoked.

void reportServiceRuntimeData(const string &interfaceId, const string &path, const string &stream)

Invoked when-ever the runtime data of the hosted remote service changes.

Parameters
  • interfaceId – the interface whom data got changed

  • path – the path that got changed.

  • stream – the serialized runtimedata stream.

void setDomain(ConnectDomain *domain)

Sets the domain to be used.

Parameters

domain – the domain

bool transmit(size_t clientId, const MessagePackage &message)

Transmits a provided message to specified client.

Parameters
  • clientId – the client to dispatch the message to

  • message – the message to dispatch

bool tryTransmitDirectly(const MessagePackage &message)

Try transmit message directly to peers shall there be a route(s) for such.

Parameters

message – the message to send

Returns

true if message got sent, false if should be dispatched further.