ArnLib  4.0.x
Active Registry Network
ArnClient Class Reference

Class for connecting to an Arn Server. More...

#include <ArnClient.hpp>

Inheritance diagram for ArnClient:
Collaboration diagram for ArnClient:

Classes

struct  HostAddrPort
 

Public Types

typedef ArnClientConnectStat ConnectStat
 
typedef Arn::ClientSyncMode SyncMode
 
typedef QList< HostAddrPortHostList
 

Signals

void tcpError (const QString &errorText, QAbstractSocket::SocketError socketError)
 Signal emitted when a connection tcp error occur. More...
 
void tcpConnected (const QString &arnHost, quint16 port)
 Signal emitted when the tcp connection is successfull. More...
 
void tcpDisConnected ()
 Signal emitted when the tcp connection is broken (has been successfull). More...
 
void connectionStatusChanged (int status, int curPrio)
 Signal emitted when the connection status is changed. More...
 
void loginRequired (int contextCode)
 Signal emitted when the remote ArnServer demands a login. More...
 
void killRequested ()
 Signal emitted when the server request this client to kill its connection. More...
 
void chatReceived (const QString &text, int prioType)
 Signal emitted when a chat message is received from the server. More...
 

Public Member Functions

 ArnClient (QObject *parent=arnNullptr)
 
 ~ArnClient ()
 
void clearArnList (int prioFilter=-1)
 Clear the Arn connection list. More...
 
HostList arnList (int prioFilter=-1) const
 Return the Arn connection list. More...
 
void addToArnList (const QString &arnHost, quint16 port=0, int prio=0)
 Add an Arn Server to the Arn connection list. More...
 
void connectToArnList ()
 Connect to an Arn Server in the Arn connection list. More...
 
void connectToArn (const QString &arnHost, quint16 port=0)
 Connect to an Arn Server More...
 
void disconnectFromArn ()
 Disconnect from an Arn Server More...
 
void loginToArn (const QString &userName, const QString &password, Arn::Allow allow=Arn::Allow::All)
 Login to an Arn Server More...
 
void loginToArnHashed (const QString &userName, const QString &passwordHashed, Arn::Allow allow=Arn::Allow::All)
 Login to an Arn Server using hashed password. More...
 
void close ()
 Close sharing with an Arn Server More...
 
bool setMountPoint (const QString &path)
 Set the sharing tree path. More...
 
bool addMountPoint (const QString &localPath, const QString &remotePath=QString())
 Add a sharing tree path. More...
 
bool removeMountPoint (const QString &localPath)
 Remove a sharing tree path. More...
 
ConnectStat connectStatus () const
 Return the Arn connection status. More...
 
void setAutoConnect (bool isAuto, int retryTime=2)
 Set automatic reconnect. More...
 
void registerClient (const QString &id)
 Register this client to be avaiable with id. More...
 
QString id () const
 Get the id of this client. More...
 
int receiveTimeout () const
 Get receive data timeout (base time) More...
 
void setReceiveTimeout (int receiveTimeout)
 Set receive data timeout (base time) More...
 
bool isDemandLogin () const
 Get clients demand for login. More...
 
void setDemandLogin (bool isDemandLogin)
 Set clients demand for login. More...
 
SyncMode syncMode () const
 Get ClientSyncMode. More...
 
void setSyncMode (SyncMode syncMode)
 Set ClientSyncMode. More...
 
QStringList freePaths () const
 Returns current list of freePaths. More...
 
void setWhoIAm (const Arn::XStringMap &whoIAmXsm)
 Set clients human readable identification information. More...
 
Arn::XStringMap remoteWhoIAm () const
 Returns remote side (server) readable identification information. More...
 
bool isReContact () const
 Is last TCP connection a reContact. More...
 
bool isReConnect () const
 Is last Arn Connection a reConnect. More...
 
void chatSend (const QString &text, int prioType)
 Send chat message to server. More...
 
void abortKillRequest ()
 Send abort kill requst to server. More...
 
bool getTraffic (quint64 &in, quint64 &out) const
 Get traffic metrics. More...
 

Static Public Member Functions

static ArnClientgetClient (const QString &id)
 Get a client by its id. More...
 
static QString passwordHash (const QString &password)
 Generate a hashed password from clear text password. More...
 

Detailed Description

Class for connecting to an Arn Server.

About Sharing Arn Data Objects About Sync Rules

Connection can be made to a specific Host by connectToArn(). It's also possible to define an Arn Connection List. Each host address is added to the list with a priority. The priority is used to control the order at which the host addresses will be tried for connection. Lowest priority number is tried first. Connection trials are started with connectToArnlList(). The priority can also be used for selction in clearArnList() and arnList().

Example usage

// In class declare
ArnClient _arnClient;
// In class code
_arnClient.connectToArn("localhost");
_arnClient.addMountPoint("//");
_arnClient.setAutoConnect( true);
Examples:
ArnDemoChat/MainWindow.hpp.

Definition at line 104 of file ArnClient.hpp.

Member Typedef Documentation

◆ ConnectStat

Definition at line 110 of file ArnClient.hpp.

◆ HostList

Definition at line 121 of file ArnClient.hpp.

◆ SyncMode

Definition at line 111 of file ArnClient.hpp.

Constructor & Destructor Documentation

◆ ArnClient()

ArnClient::ArnClient ( QObject *  parent = arnNullptr)
explicit

Definition at line 253 of file ArnClient.cpp.

◆ ~ArnClient()

ArnClient::~ArnClient ( )

Definition at line 269 of file ArnClient.cpp.

Member Function Documentation

◆ abortKillRequest()

void ArnClient::abortKillRequest ( )

Send abort kill requst to server.

The server can request client to kill connection. This method is used to request an abort of the kill request. This method can be called any time but it will only be considered during a kill countdown.

See also
killRequested()

Definition at line 621 of file ArnClient.cpp.

◆ addMountPoint()

bool ArnClient::addMountPoint ( const QString &  localPath,
const QString &  remotePath = QString() 
)

Add a sharing tree path.

Mountpoint is an association to the similarity of mounting a "remote filesystem". In Arn, the remote "file system" can be at different sub path than the local mountpoint, e.g. a client having mountpoint local="/a/b/" remote="/r/" and opening an Arn Data Object at "/a/b/c" will have the object c shared with the server at its path "/r/c". However if remotePath is not specified, it will be same as localPath. In the above example, the c object will then be shared with the server at its path "/a/b/c".

Parameters
[in]localPathis the local sharing tree.
[in]remotePathis the remote sharing tree. If empty, same as localPath.
Return values
falseif error.
See also
Sharing Arn Data Objects

Definition at line 385 of file ArnClient.cpp.

◆ addToArnList()

void ArnClient::addToArnList ( const QString &  arnHost,
quint16  port = 0,
int  prio = 0 
)

Add an Arn Server to the Arn connection list.

Parameters
[in]arnHostis host name or ip address, e.g. "192.168.1.1".
[in]portis the host port, 0 gives Arn::defaultTcpPort.
[in]priogives the sorting (connection) order and can be used for selection filter.
See also
clearArnList()
arnList()
Arn::makeHostWithInfo()

Definition at line 293 of file ArnClient.cpp.

◆ arnList()

ArnClient::HostList ArnClient::arnList ( int  prioFilter = -1) const

Return the Arn connection list.

Parameters
[in]prioFilterselects hosts in the list with this pri. Default -1 selects all.
Return values
theselected Arn connection list.
See also
addToArnList()

Definition at line 285 of file ArnClient.cpp.

◆ chatReceived

void ArnClient::chatReceived ( const QString &  text,
int  prioType 
)
signal

Signal emitted when a chat message is received from the server.

Parameters
[in]textis the message.
[in]prioTypeis the priority of the message (1=Hi 2=Normal).
See also
chatSend()

◆ chatSend()

void ArnClient::chatSend ( const QString &  text,
int  prioType 
)

Send chat message to server.

This is used for a chat session between client and server.

Parameters
[in]textis the message.
[in]prioTypeis the priority of the message (1=Hi 2=Normal).
See also
chatReceived()

Definition at line 611 of file ArnClient.cpp.

◆ clearArnList()

void ArnClient::clearArnList ( int  prioFilter = -1)

Clear the Arn connection list.

Typically used to start making a new Arn connection list.

Parameters
[in]prioFilterselects hosts in the list with this pri, to be removed. Default -1 removes all.
See also
addToArnList()

Definition at line 277 of file ArnClient.cpp.

◆ close()

void ArnClient::close ( )

Close sharing with an Arn Server

Stop sharing Arn objects with the Arn server. Similar to disconnectFromArn(). All pending data is written before disconnect. No syncronized Arn objects are remembered. This implies that it's not possible to continue previous session. This function is aimed at later starting a new session from scratch.

Auto connection is also disabled.

See also
disconnectFromArn()
setAutoConnect()
connectToArn()

Definition at line 354 of file ArnClient.cpp.

◆ connectionStatusChanged

void ArnClient::connectionStatusChanged ( int  status,
int  curPrio 
)
signal

Signal emitted when the connection status is changed.

Parameters
[in]statusis the new connection status ArnClient::ConnectStat.
[in]curPriois the current priority of the connection in ArnList
See also
curPrio()

◆ connectStatus()

ArnClient::ConnectStat ArnClient::connectStatus ( ) const

Return the Arn connection status.

Return values
theArn connection status.

Definition at line 364 of file ArnClient.cpp.

◆ connectToArn()

void ArnClient::connectToArn ( const QString &  arnHost,
quint16  port = 0 
)

Connect to an Arn Server

Parameters
[in]arnHostis host name or ip address, e.g. "192.168.1.1".
[in]portis the host port, 0 gives Arn::defaultTcpPort.
See also
Arn::makeHostWithInfo()
connectToArnList()

Definition at line 314 of file ArnClient.cpp.

◆ connectToArnList()

void ArnClient::connectToArnList ( )

Connect to an Arn Server in the Arn connection list.

Will scan the connection list once until a successful connection is made. If the end of the list is reached without connection, the tcpError() signal

See also
connectToArn()

Definition at line 301 of file ArnClient.cpp.

◆ disconnectFromArn()

void ArnClient::disconnectFromArn ( )

Disconnect from an Arn Server

Force disconnect from the Arn server, similar behaviour to losing connection. All pending data is written before disconnect. All Arn objects that has been setup to be synronized is still kept. This implies that it's possible to continue previous session by just connecting to the Arn server again.

Auto connection is also disabled.

See also
close()
setAutoConnect()
connectToArn()

Definition at line 327 of file ArnClient.cpp.

◆ freePaths()

QStringList ArnClient::freePaths ( ) const

Returns current list of freePaths.

A freePath can be used even if not logged in to an ArnServer that demands login. Also all children below freePath is free to use. Usage is restricted to read operations and alike from ArnServer to ArnClient. The list of freePaths is used to enable the operation requests to be transfered to ArnServer. ArnServer still decides what's allowed. The list is automatically transfered from ArnServer to ArnClient during the negotiation phase.

Returns
the freePath list.
See also
ArnServer::addFreePath()

Definition at line 563 of file ArnClient.cpp.

◆ getClient()

ArnClient * ArnClient::getClient ( const QString &  id)
static

Get a client by its id.

Parameters
[in]idif "" will always return 0.
Returns
the found client, 0 = not found or id == ""
See also
registerClient()

Definition at line 492 of file ArnClient.cpp.

◆ getTraffic()

bool ArnClient::getTraffic ( quint64 &  in,
quint64 &  out 
) const

Get traffic metrics.

Return values
trueif ok.
Parameters
[out]inis the clients received number of bytes.
[out]outis the clients sent number of bytes.

Definition at line 629 of file ArnClient.cpp.

◆ id()

QString ArnClient::id ( ) const

Get the id of this client.

Returns
the id, "" = none (local)
See also
registerClient()

Definition at line 498 of file ArnClient.cpp.

◆ isDemandLogin()

bool ArnClient::isDemandLogin ( ) const

Get clients demand for login.

If any of server or client demand login, it must be used.

Return values
trueif client demand login.
See also
setDemandLogin()

Definition at line 522 of file ArnClient.cpp.

◆ isReConnect()

bool ArnClient::isReConnect ( ) const

Is last Arn Connection a reConnect.

ReConnect occurs if an Arn connection is successful, then lost and then restored due to autoConnect. Successful Arn connection gives a state change to ConnectStat::Connected.

Return values
trueif this is a reConnect.
See also
isReContact()
setAutoConnect()
connectionStatusChanged()

Definition at line 595 of file ArnClient.cpp.

◆ isReContact()

bool ArnClient::isReContact ( ) const

Is last TCP connection a reContact.

ReContact occurs if a TCP connection is successful, then lost and then restored due to autoConnect. Successful TCP connection gives a state change to ConnectStat::Negotiating.

Return values
trueif this is a reContact.
See also
isReConnect()
setAutoConnect()
connectionStatusChanged()

Definition at line 587 of file ArnClient.cpp.

◆ killRequested

void ArnClient::killRequested ( )
signal

Signal emitted when the server request this client to kill its connection.

This request should normally be obeyed by the client. I.e. it should usually result in a call to close().

See also
abortKillRequest()

◆ loginRequired

void ArnClient::loginRequired ( int  contextCode)
signal

Signal emitted when the remote ArnServer demands a login.

When this signal is emitted, a call to loginToArn() must be done to complete the connection process.

Parameters
[in]contextCodeis the situation context as: 0 = First login trial 1 = Server deny, login retry 2 = Client deny, server gave bad password (fake server?) 3 = Client deny, server not support login 4 = Client deny, server bad negotiate sequence
See also
loginToArn()

◆ loginToArn()

void ArnClient::loginToArn ( const QString &  userName,
const QString &  password,
Arn::Allow  allow = Arn::Allow::All 
)

Login to an Arn Server

This routine must be called when the signal loginRequired() is emitted. Otherwise the client will not be fully conected to the server, ie the apropriate access privileges will not be setup at server and client. If a reconnect occurs, usually due to tcp breakage, login process is handled automatically by ArnLib using the last used login credentials. If this automatical login is failed, signal loginRequired() is emitted.

Parameters
[in]userName
[in]password
[in]allowis the permissions for the server actions to this client.
See also
Arn::Allow
loginRequired;
loginToArnHashed()

Definition at line 338 of file ArnClient.cpp.

◆ loginToArnHashed()

void ArnClient::loginToArnHashed ( const QString &  userName,
const QString &  passwordHashed,
Arn::Allow  allow = Arn::Allow::All 
)

Login to an Arn Server using hashed password.

This behaves exactly as loginToArn(), exept for password being hashed. The hashed password which can be generated by ArnClient::passwordHash() (see also ArnBrowser Settings).

Parameters
[in]userName
[in]passwordHashed
[in]allowis the permissions for the server actions to this client.
See also
loginToArn()
Arn::Allow
loginRequired;

Definition at line 345 of file ArnClient.cpp.

◆ passwordHash()

QString ArnClient::passwordHash ( const QString &  password)
static

Generate a hashed password from clear text password.

Parameters
[in]passwordis the clear text password.
Returns
the hashed password, e.g "{A5ha62Aug}"

Definition at line 557 of file ArnClient.cpp.

◆ receiveTimeout()

int ArnClient::receiveTimeout ( ) const

Get receive data timeout (base time)

Returns
the timeout in seconds
See also
setReceiveTimeout()

Definition at line 506 of file ArnClient.cpp.

◆ registerClient()

void ArnClient::registerClient ( const QString &  id)

Register this client to be avaiable with id.

When instantiating an ArnClient, it's always registered as id = "std", if that's not taken by another client.

Any previous registration of id for this client will be released when using registerClient().

Parameters
[in]idmust not be "".
See also
getClient()
id()

Definition at line 481 of file ArnClient.cpp.

◆ remoteWhoIAm()

Arn::XStringMap ArnClient::remoteWhoIAm ( ) const

Returns remote side (server) readable identification information.

This is used to identify the server side in session.

Returns
the inforamtion.
See also
setWhoIAm()

Definition at line 579 of file ArnClient.cpp.

◆ removeMountPoint()

bool ArnClient::removeMountPoint ( const QString &  localPath)

Remove a sharing tree path.

Only the mount point will be removed, i.e any new Arn Data Objects created within the localPath tree will not be shared with the server. However already existing objects will not be affected and is still shared with the server.

Parameters
[in]localPathis the sharing tree to be removed. Only affects newly created objects.
Return values
falseif error.
See also
Sharing Arn Data Objects

Definition at line 440 of file ArnClient.cpp.

◆ setAutoConnect()

void ArnClient::setAutoConnect ( bool  isAuto,
int  retryTime = 2 
)

Set automatic reconnect.

If connectToArnList() is used, this auto connect funtionality starts every time after the last host in the Arn connection list has failed. The connection list is retried after retryTime. When using connectToArn(), there will be a retryTime delay between each reConnect to the host.

Parameters
[in]isAutotrue if using auto reconnect
[in]retryTimeis the time between attempts in seconds

Definition at line 472 of file ArnClient.cpp.

◆ setDemandLogin()

void ArnClient::setDemandLogin ( bool  isDemandLogin)

Set clients demand for login.

If any of server or client demand login, it must be used.

Parameters
[in]isDemandLogintrue if client demand login.
See also
isDemandLogin()

Definition at line 530 of file ArnClient.cpp.

◆ setMountPoint()

bool ArnClient::setMountPoint ( const QString &  path)

Set the sharing tree path.

For campatibility, this can only set one mount point and with same local as remote path. If exactly one mount point exist, it will be removed before this new one is added.

Parameters
[in]pathis the sharing tree.
Return values
falseif error.
See also
Sharing Arn Data Objects
Deprecated:
Use addMountPoint() and removeMountPoint()

Definition at line 372 of file ArnClient.cpp.

◆ setReceiveTimeout()

void ArnClient::setReceiveTimeout ( int  receiveTimeout)

Set receive data timeout (base time)

The timeout deals with no received data. This base time T is used as follows: time passed == T/2, send a dummy request to ArnServer time passed == T, signal status ConnectStat::Stopped time passed == 3*T, abort ArnClient tcp socket.

Default base time T is set to 10 seconds.

Parameters
[in]receiveTimeoutis the base time T in seconds. 0 = off (no timeout).
See also
receiveTimeout()
Note
Must be set before client is connected

Definition at line 514 of file ArnClient.cpp.

◆ setSyncMode()

void ArnClient::setSyncMode ( ArnClient::SyncMode  syncMode)

Set ClientSyncMode.

Default for ArnClient is StdAutoMaster.

Parameters
[in]syncModethe ClientSyncMode to be set.
See also
ClientSyncMode
syncMode()

Definition at line 546 of file ArnClient.cpp.

◆ setWhoIAm()

void ArnClient::setWhoIAm ( const Arn::XStringMap whoIAmXsm)

Set clients human readable identification information.

This is used to identify the client session. Standard keys to use are: Agent, UserName, Contact, Location.

Example usage

wimXsm.add("Agent", "Arn Browser");
wimXsm.add("UserName", "Arn Magnusson");
wimXsm.add("Contact", "arn@arnas.se");
wimXsm.add("Location", "The Longhouse");
_arnClient->setWhoIAm( wimXsm);
Parameters
[in]whoIAmXsmcontains the information.
See also
remoteWhoIAm()

Definition at line 571 of file ArnClient.cpp.

◆ syncMode()

ArnClient::SyncMode ArnClient::syncMode ( ) const

Get ClientSyncMode.

Default for ArnClient is StdAutoMaster.

Return values
ClientSyncMode.
See also
ClientSyncMode
setSyncMode()

Definition at line 538 of file ArnClient.cpp.

◆ tcpConnected

void ArnClient::tcpConnected ( const QString &  arnHost,
quint16  port 
)
signal

Signal emitted when the tcp connection is successfull.

Parameters
[in]arnHostis host name or ip address, e.g. "192.168.1.1".
[in]portis the host port, e.g. 2022.

◆ tcpDisConnected

void ArnClient::tcpDisConnected ( )
signal

Signal emitted when the tcp connection is broken (has been successfull).

◆ tcpError

void ArnClient::tcpError ( const QString &  errorText,
QAbstractSocket::SocketError  socketError 
)
signal

Signal emitted when a connection tcp error occur.

Parameters
[in]errorTextis the human readable description of the error.
[in]socketErroris the error from tcp socket, see Qt doc.

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