Sorry I can't find the EDIT option to edit my first post:
{
{
}
}
void DServer::incomingConnection(int socketDescriptor)
{
serverSocket = new QSslSocket(this);
if (serverSocket->setSocketDescriptor(socketDescriptor))
{
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(response_to_connection()));
connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(errorOccured(const QList<QSslError> &)));
connect(serverSocket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
serverSocket->setProtocol(QSsl::SslV3);
serverSocket->setPrivateKey("server.key");
serverSocket->setLocalCertificate("server.crt");
serverSocket->startServerEncryption();
}
else
{
delete serverSocket;
}
}
void DServer::response_to_connection()
{
if(connected_host.
toString() == QString("192.168.56.101")) {
response_to_replication();
}
}
void DServer::errorOccured(const QList<QSslError> &error)
{
serverSocket->ignoreSslErrors();
}
void DServer::response_to_replication()
{
blockSize = 0;
block.clear();
serverfiles.clear();
serverfiles = rfilelist();
out << (quint64)0;
out << (out,serverfiles);
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
qint64 data = serverSocket->write(block);
QTextStream(stdout) <<
"block.size = " <<block.
size() <<endl;
serverSocket->reset();
if (blockSize == 0)
{
do
{
{
return;
}
serverSocket->waitForReadyRead(1);
}
while(serverSocket->bytesAvailable() < (int)sizeof(quint64));
in >> blockSize;
}
do
{
{
return;
}
serverSocket->waitForReadyRead(1);
}
while(serverSocket->bytesAvailable() < blockSize);
in >> (in,requestedFL);
serverSocket->reset();
for(int h=0;h<requestedFL.count();h++)
{
}
if(requestedFL.isEmpty() == false)
{
int len_requestedFL = requestedFL.count();
for(int i=0; i<len_requestedFL; i++)
{
block.clear();
ba.clear();
compressed_ba.clear();
QFile file(*homepath
+ requestedFL
[i
]);
return;
ba = file.readAll();
out << (quint64)0;
out << ba;
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
serverSocket->write(block);
serverSocket->reset();
file.close();
blockSize = 0;
int v=0;
do
{
{
return;
}
serverSocket->waitForReadyRead(1);
}
while((serverSocket->bytesAvailable() < (int)sizeof(quint64)) );
in >> blockSize;
in >> confirmation;
serverSocket->reset();
}
}
}
void DServer::clientDisconnected()
{
if (!serverSocket)
return;
serverSocket->deleteLater();
wtolog
(QString("Client Disconnected from Server"));
}
void DServer::response_to_connection()
{
while (hasPendingConnections())
{
QSslSocket *client = nextPendingConnection();
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
serverSockets.append(client);
if(connected_host.
toString() == QString("192.168.56.101")) {
response_to_replication(client);
}
}
}
DServer::DServer(QObject *parent) : QTcpServer(parent)
{
if (!listen(QHostAddress("192.168.56.1"),(quint16)55678))
{
QTextStream(stdout) << errorString();
}
}
void DServer::incomingConnection(int socketDescriptor)
{
serverSocket = new QSslSocket(this);
if (serverSocket->setSocketDescriptor(socketDescriptor))
{
connect(serverSocket, SIGNAL(encrypted()), this, SLOT(response_to_connection()));
connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(errorOccured(const QList<QSslError> &)));
connect(serverSocket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
serverSocket->setProtocol(QSsl::SslV3);
serverSocket->setPrivateKey("server.key");
serverSocket->setLocalCertificate("server.crt");
serverSocket->startServerEncryption();
}
else
{
delete serverSocket;
}
}
void DServer::response_to_connection()
{
QHostAddress connected_host = serverSocket->peerAddress();
if(connected_host.toString() == QString("192.168.56.101"))
{
response_to_replication();
}
}
void DServer::errorOccured(const QList<QSslError> &error)
{
serverSocket->ignoreSslErrors();
}
void DServer::response_to_replication()
{
blockSize = 0;
QByteArray block;
block.clear();
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
serverfiles.clear();
serverfiles = rfilelist();
out << (quint64)0;
out << (out,serverfiles);
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
qint64 data = serverSocket->write(block);
QTextStream(stdout) <<"block.size = " <<block.size() <<endl;
QTextStream(stdout) <<"data = " <<data <<endl;
serverSocket->reset();
QDataStream in(serverSocket);
in.setVersion(QDataStream::Qt_4_0);
if (blockSize == 0)
{
do
{
if(serverSocket->state() == QAbstractSocket::UnconnectedState)
{
return;
}
serverSocket->waitForReadyRead(1);
}
while(serverSocket->bytesAvailable() < (int)sizeof(quint64));
in >> blockSize;
}
do
{
if(serverSocket->state() == QAbstractSocket::UnconnectedState)
{
return;
}
serverSocket->waitForReadyRead(1);
}
while(serverSocket->bytesAvailable() < blockSize);
QStringList requestedFL;
in >> (in,requestedFL);
serverSocket->reset();
for(int h=0;h<requestedFL.count();h++)
{
QTextStream(stdout) << requestedFL[h] <<endl;
}
if(requestedFL.isEmpty() == false)
{
QByteArray ba;
QByteArray compressed_ba;
int len_requestedFL = requestedFL.count();
for(int i=0; i<len_requestedFL; i++)
{
block.clear();
ba.clear();
compressed_ba.clear();
QFile file(*homepath + requestedFL[i]);
if (!file.open(QIODevice::ReadOnly))
return;
ba = file.readAll();
out << (quint64)0;
out << ba;
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
serverSocket->write(block);
serverSocket->reset();
file.close();
blockSize = 0;
int v=0;
do
{
if(serverSocket->state() == QAbstractSocket::UnconnectedState)
{
return;
}
serverSocket->waitForReadyRead(1);
}
while((serverSocket->bytesAvailable() < (int)sizeof(quint64)) );
in >> blockSize;
QString confirmation;
in >> confirmation;
serverSocket->reset();
}
}
}
void DServer::clientDisconnected()
{
if (!serverSocket)
return;
serverSocket->deleteLater();
wtolog(QString("Client Disconnected from Server"));
}
void DServer::response_to_connection()
{
while (hasPendingConnections())
{
QSslSocket *client = nextPendingConnection();
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
serverSockets.append(client);
QHostAddress connected_host = client->peerAddress();
if(connected_host.toString() == QString("192.168.56.101"))
{
response_to_replication(client);
}
}
}
To copy to clipboard, switch view to plain text mode
server2client:
Server::Server()
{
clientSocket = new QSslSocket(this);
clientSocket->abort();
quint16 hostPort = 55678;
connect(clientSocket, SIGNAL(readyRead()),this, SLOT(connectionEstablished()));
connect(clientSocket, SIGNAL(sslErrors(const QList<QSslError> &)),this, SLOT(errorOccured(const QList<QSslError> &)));
clientSocket->setProtocol(QSsl::SslV3);
clientSocket->connectToHostEncrypted(hostIP, hostPort);
}
void Server::connectionEstablished()
{
QSslCertificate cert = clientSocket->peerCertificate();
if(cert.isNull())
{
}
QSslCipher cipher;
cipher = clientSocket->sessionCipher();
initiate_replication();
}
void Server::initiate_replication()
{
blockSize = 0;
if (blockSize == 0)
{
do
{
clientSocket->waitForReadyRead(1);
}
while(clientSocket->bytesAvailable() < (int)sizeof(quint64));
in >> blockSize;
}
do
{
clientSocket->waitForReadyRead(1);
}
while(clientSocket->bytesAvailable() < blockSize);
in >> (in,receivedFL);
clientSocket->reset();
block.clear();
out << (quint64)0;
out << (out,requestedlist);
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
clientSocket->write(block);
clientSocket->reset();
blockSize = 0;
if (blockSize == 0)
{
do
{
clientSocket->waitForReadyRead(1);
}
while(clientSocket->bytesAvailable() < (int)sizeof(quint64));
in >> blockSize;
}
int p=0;
do
{
clientSocket->waitForReadyRead(1000);
}
while (clientSocket->bytesAvailable() < blockSize);
ba = clientSocket->readAll();
clientSocket->reset();
block.clear();
out << requestedlist[j];
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
clientSocket->write(block);
clientSocket->reset();
}
clientSocket->disconnectFromHost();
}
void Server::errorOccured(const QList<QSslError> &error)
{
clientSocket->ignoreSslErrors();
}
Server::~Server()
{
}
Server::Server()
{
clientSocket = new QSslSocket(this);
clientSocket->abort();
QString hostIP("192.168.56.1");
quint16 hostPort = 55678;
connect(clientSocket, SIGNAL(readyRead()),this, SLOT(connectionEstablished()));
connect(clientSocket, SIGNAL(sslErrors(const QList<QSslError> &)),this, SLOT(errorOccured(const QList<QSslError> &)));
clientSocket->setProtocol(QSsl::SslV3);
clientSocket->connectToHostEncrypted(hostIP, hostPort);
}
void Server::connectionEstablished()
{
QSslCertificate cert = clientSocket->peerCertificate();
if(cert.isNull())
{
}
QSslCipher cipher;
cipher = clientSocket->sessionCipher();
initiate_replication();
}
void Server::initiate_replication()
{
QDataStream in(clientSocket);
blockSize = 0;
in.setVersion(QDataStream::Qt_4_0);
if (blockSize == 0)
{
do
{
clientSocket->waitForReadyRead(1);
}
while(clientSocket->bytesAvailable() < (int)sizeof(quint64));
in >> blockSize;
}
do
{
clientSocket->waitForReadyRead(1);
}
while(clientSocket->bytesAvailable() < blockSize);
QStringList receivedFL;
in >> (in,receivedFL);
clientSocket->reset();
QByteArray block;
block.clear();
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint64)0;
out << (out,requestedlist);
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
clientSocket->write(block);
clientSocket->reset();
blockSize = 0;
if (blockSize == 0)
{
do
{
clientSocket->waitForReadyRead(1);
}
while(clientSocket->bytesAvailable() < (int)sizeof(quint64));
in >> blockSize;
}
int p=0;
do
{
clientSocket->waitForReadyRead(1000);
}
while (clientSocket->bytesAvailable() < blockSize);
QByteArray compressed_ba;
QByteArray ba;
ba = clientSocket->readAll();
clientSocket->reset();
block.clear();
out << requestedlist[j];
out.device()->seek(0);
out << (quint64)(block.size() - sizeof(quint64));
clientSocket->write(block);
clientSocket->reset();
}
clientSocket->disconnectFromHost();
}
void Server::errorOccured(const QList<QSslError> &error)
{
clientSocket->ignoreSslErrors();
}
Server::~Server()
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks