Commit another batch of fine-tuning for the bridge/server. Still not getting the server->bridge connection for some reason - working on it...

This commit is contained in:
Ken Moore
2016-05-18 14:44:42 -04:00
parent 18bcd3b03e
commit 6e07eb7c49
5 changed files with 10 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ BridgeConnection::BridgeConnection(QWebSocket *sock, QString ID){
SockAuthToken.clear(); //nothing set initially
SOCKET = sock;
SockPeerIP = SOCKET->peerAddress().toString();
qDebug() << "New Connection:" << SockPeerIP;
idletimer = new QTimer(this);
idletimer->setInterval(30000); //connection timout for idle sockets
idletimer->setSingleShot(true);
@@ -155,10 +156,12 @@ void BridgeConnection::HandleAPIMessage(QString msg){
array.append(SockAuthToken);
array.append(AUTHSYSTEM->checkAuthTimeoutSecs(SockAuthToken));
outargs = array;
qDebug() << "Connection Authorized:" << SockPeerIP;
QTimer::singleShot(10 ,this, SLOT(requestKeyList()) );
}else{
out.insert("name","error");
outargs = "unauthorized";
qDebug() << "Connection Not Authorized:" << SockPeerIP;
}
}
}else if(AUTHSYSTEM->checkAuth(SockAuthToken)){

View File

@@ -51,6 +51,7 @@ void BridgeServer::sendMessage(QString toID, QString msg){
//===================
bool BridgeServer::setupWebSocket(quint16 port){
//SSL Configuration
qDebug() << "SSL Files:" << SSLFILEDIR+"/["+SSLCERTFILE+", "+SSLKEYFILE+"]";
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
QFile CF( SSLFILEDIR +"/"+SSLCERTFILE );
if(CF.open(QIODevice::ReadOnly) ){
@@ -112,6 +113,7 @@ QString BridgeServer::generateID(QString name){
// New Connection Signals
void BridgeServer::NewSocketConnection(){
BridgeConnection *sock = 0;
qDebug() << "New incoming connection..";
if(this->hasPendingConnections()){
QWebSocket *ws = this->nextPendingConnection();
if(allowConnection(ws->peerAddress()) ){

View File

@@ -219,7 +219,9 @@ void WebServer::SocketClosed(QString ID){
// BRIDGE Connection checks
void WebServer::checkBridges(){
qDebug() << "Check Bridges:" << WS_MODE;
if(!WS_MODE){ return; }
//Get all the unique bridge URL's we need connections to
QStringList bridgeKeys = CONFIG->allKeys().filter("bridge_connections/");
for(int i=0; i<bridgeKeys.length(); i++){
@@ -236,6 +238,7 @@ void WebServer::checkBridges(){
}
//Now startup any connections which are missing
for(int i=0; i<bridgeKeys.length(); i++){
qDebug() << "Try to connect to bridge:" << bridgeKeys[i];
WebSocket *sock = new WebSocket(bridgeKeys[i], bridgeKeys[i], AUTH);
connect(sock, SIGNAL(SocketClosed(QString)), this, SLOT(SocketClosed(QString)) );
OpenSockets << sock;

View File

@@ -86,6 +86,7 @@ WebSocket::WebSocket(QString url, QString ID, AuthorizationManager *auth){
bool hasport = false;
url.section(":",-1).toInt(&hasport); //check if the last piece of the url is a valid number
if(!hasport){ url.append(":"+QString::number(BRIDGEPORTNUMBER)); }
qDebug() << "Connecting to bridge:" << url;
SOCKET->open(QUrl(url));
}

View File

@@ -107,7 +107,7 @@ int main( int argc, char ** argv )
qDebug() << "Unknown option:" << argv[i];
return 1;
}
}else if(QString(argv[i])=="-import_ssl_key" && i+3>argc){
}else if(QString(argv[i])=="-import_ssl_key" && i+3<argc){
setonly = true;
i++; QString user(argv[i]);
i++; QByteArray key(argv[i]);