flowher 11 лет назад
Родитель
Сommit
614f82a7d7
3 измененных файлов: 12 добавлений и 12 удалений
  1. +1
    -1
      Makefile
  2. +7
    -11
      client.cpp
  3. +4
    -0
      server.cpp

+ 1
- 1
Makefile Просмотреть файл

@@ -2,7 +2,7 @@ EXECUTABLE = server
EXECUTABLECLI = client
CC=g++ -lboost_system -lboost_thread
CFLAGS=-Wall -ggdb -DDEBUG -Wreorder
CFLAGS=-Wall -O2 -DDEBUG -Wreorder
COMPILE=$(CC) $(CFLAGS)
all: server client


+ 7
- 11
client.cpp Просмотреть файл

@@ -27,7 +27,6 @@
using namespace std;
using namespace boost;

int Handler = 0;
SSL* SSLHandler = 0;
int CharsRead = 0;

@@ -40,8 +39,6 @@ void Sender()
{
string buf(EXCHANGE_STRING);
int len = 0;
SSL_write(SSLHandler, buf.c_str()+len, buf.size()-len);
/*
do
{
lock_guard<mutex> lock(WriteReadMutex);
@@ -49,7 +46,6 @@ void Sender()
// for debugging re-neg
// cout << "SSL STATE: " << SSL_state_string(handler.second) << endl;
} while( len != static_cast<int>(buf.size()) );
*/
}
};

@@ -62,7 +58,6 @@ void Client::receive()
int len_rcv = 0;
{
lock_guard<mutex> lock(WriteReadMutex);
cout << "A" << endl;
len_rcv = SSL_read(SSLHandler, buf, MAX_PACKET_SIZE);
}

@@ -89,26 +84,28 @@ void Client::connect()
lock_guard<mutex> lock(WriteReadMutex);

struct sockaddr_in echoserver;
int sock = socket(AF_INET, SOCK_STREAM, 0);
_handler = socket(AF_INET, SOCK_STREAM, 0);
memset(&echoserver, 0, sizeof(echoserver));
echoserver.sin_family = AF_INET;
echoserver.sin_addr.s_addr = inet_addr(IP);
echoserver.sin_port = htons(PORT);

/* Establish connection */
if ( 0 > ::connect(sock, (struct sockaddr *) &echoserver, sizeof(echoserver)) )
if ( 0 > ::connect(_handler, (struct sockaddr *) &echoserver, sizeof(echoserver)) )
{
throw runtime_error("Can't connect to the server");
}
Handler = sock;
SSLHandler = SSL_new(_ctx);
SSL_set_fd(SSLHandler, Handler);
SSL_set_fd(SSLHandler, _handler);

if( SSL_connect(SSLHandler) <= 0)
{
cerr << "Can't setup SSL session" << endl;
exit(1);
}
fcntl(sock, F_SETFL, O_NONBLOCK);
// bug reproduces even if call is blocking, so not need to uncommet this line
// fcntl(_handler, F_SETFL, O_NONBLOCK);
}

void Client::start()
@@ -147,7 +144,6 @@ void Client::start()
void Client::renegotiate()
{
lock_guard<mutex> lock_reads(WriteReadMutex);
cout << "B" << endl;

cout << "Starting SSL renegotiation on SSL"
<< "client (initiating by SSL client)" << endl;


+ 4
- 0
server.cpp Просмотреть файл

@@ -32,11 +32,15 @@ mutex SocketSetMutex;
// WaitForWrite is a condition variable that is signaled when Sender must start sending the data
condition_variable WaitForWrite;
mutex WaitForWriteMutex;
// mutex that synchronizes access to SSL_read/SSL_write
mutex WriteReadMutex;
// thread functions to send and receive
void Receive();
void Send();
Server::Server()
: SSLProcess(true)
, _master(0)


Загрузка…
Отмена
Сохранить