mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
API CHANGE: Get the sysadm-bridge all finished up. Now to add the necessary bits to the server/client so we can try using it.
NOTE: There is a special API/event for the bridge to announce which server/client connections are available (clients will see only servers, and vice versa)
The syntax for this event is:
{
"namespace":"events",
"name":"bridge",
"id":"",
"args":{
"available_connections":["ID1","ID2", etc..]
}
}
Note that the available_connections are *all* the connections available at that time (it is not a difference from a previous state), so there may be both new ID's in the list and ID's which are no longer listed.
This event will get sent out any time a new connection/disconnection is made from the bridge which impacts the current connection (so a client will only get the event when a server connects/disconnects and vice versa).
This commit is contained in:
@@ -12,12 +12,11 @@
|
||||
//=======================
|
||||
BridgeServer::BridgeServer() : QWebSocketServer("sysadm-bridge", QWebSocketServer::SecureMode){
|
||||
//Setup all the various settings
|
||||
//AUTH = new AuthorizationManager();
|
||||
connect(AUTHSYSTEM, SIGNAL(BlockHost(QHostAddress)), this, SLOT(BlackListConnection(QHostAddress)) );
|
||||
}
|
||||
|
||||
BridgeServer::~BridgeServer(){
|
||||
//delete AUTH;
|
||||
|
||||
}
|
||||
|
||||
bool BridgeServer::startServer(quint16 port){
|
||||
@@ -125,6 +124,7 @@ void BridgeServer::NewSocketConnection(){
|
||||
//qDebug() << "New Socket Connection";
|
||||
connect(sock, SIGNAL(SocketClosed(QString)), this, SLOT(SocketClosed(QString)) );
|
||||
connect(sock, SIGNAL(SocketMessage(QString, QString)), this, SLOT(SendMessage(QString, QString)) );
|
||||
connect(sock, SIGNAL(keysChanged(QString, bool, QStringList)), this, SLOT(announceKeyChange(QString, bool, QStringList)) );
|
||||
OpenSockets << sock;
|
||||
}
|
||||
|
||||
@@ -183,3 +183,24 @@ void BridgeServer::SocketClosed(QString ID){
|
||||
}
|
||||
QTimer::singleShot(0,this, SLOT(NewSocketConnection()) ); //check for a new connection
|
||||
}
|
||||
|
||||
// Connection Keys Changed
|
||||
void BridgeServer::announceKeyChange(QString ID, bool isServer, QStringList keys){
|
||||
for(int c = 0; c<OpenSockets.length(); c++){
|
||||
bool server = OpenSockets[c]->isServer();
|
||||
QStringList keys = OpenSockets[c]->validKeySums();
|
||||
keys.removeDuplicates();
|
||||
QStringList IDs;
|
||||
for(int i=0; i<OpenSockets.length(); i++){
|
||||
if(i==c){ continue; } //current socket
|
||||
else if(OpenSockets[i]->isServer() != server){ //look for a server/client pair
|
||||
//compare keys to look for matches
|
||||
QStringList chkkeys = OpenSockets[i ]->validKeySums();
|
||||
chkkeys.removeDuplicates();
|
||||
chkkeys << keys;
|
||||
if(chkkeys.removeDuplicates() > 0){ IDs << OpenSockets[i]->ID(); }
|
||||
}
|
||||
}//end inner loop of sockets
|
||||
OpenSockets[c]->announceIDAvailability(IDs);
|
||||
} //end loop over sockets to check
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user