diff --git a/lib/tcp_socket.hpp b/lib/tcp_socket.hpp index be202c9..20c9993 100644 --- a/lib/tcp_socket.hpp +++ b/lib/tcp_socket.hpp @@ -15,6 +15,11 @@ using namespace std; +class client; +// class secure; +// class server; + + /** * Server klasa za TCP/IP soket * Instanca se incijalizira kada pokrećemo server @@ -24,13 +29,14 @@ class server { public: int sock; struct sockaddr_in addr; + SSL_CTX* securefds = NULL; - server (const ushort port, const uint limit = 1000); + server (const ushort port, const uint limit = 1000, SSL_CTX* _securefds = NULL); ~server (); - // dok god živi server žive i klijenti - klijetni moraju biti dio servera - // omogućiti enkripciju i na nivou servera - + // one klijent + client* cli; + void accept(const uint timeout = 100); }; @@ -60,6 +66,8 @@ class client { int conn; // mijenja sock struct sockaddr_in addr; SSL* ssl = NULL; + // server s klijentima + const server* srv; // klijent sa serverom string ipv4; string ipv6; diff --git a/src/tcp_socket.cpp b/src/tcp_socket.cpp index c7fb05d..e48f63c 100644 --- a/src/tcp_socket.cpp +++ b/src/tcp_socket.cpp @@ -4,7 +4,8 @@ * Kontrustruktor varijable tipa server, prima port i limit za ograničenje liste klijenata na čekanju */ -server::server (const ushort port, const uint limit) { +server::server (const ushort port, const uint limit, SSL_CTX* _securefds) { + securefds = _securefds; addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; @@ -31,6 +32,10 @@ server::server (const ushort port, const uint limit) { } +void server::accept(const uint timeout) { + cli = new client(this, timeout, securefds); +} + /** * Destruktor varijable tipa server */ @@ -38,6 +43,9 @@ server::server (const ushort port, const uint limit) { server::~server () { + cli->~client(); + cli = NULL; + if (sock<=0) { throw string("[ERROR] The socket is already closed "); } diff --git a/test/client.o b/test/client.o index 54fa244..c0afdca 100755 Binary files a/test/client.o and b/test/client.o differ diff --git a/test/server.cpp b/test/server.cpp index 8080de3..a6255ce 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -6,21 +6,26 @@ using namespace std; int main() { try{ - cout << "init server " << endl; - server myserver(5000); cout << "init cert " << endl; secure crypto ("../example/cert.pem", "../example/privkey.pem"); + cout << "init server " << endl; + server myserver(5000, 100, crypto.fds); + cout << "init client " << endl; - client myclient(&myserver, 100, crypto.fds); + // client myclient(&myserver, 100, crypto.fds); // comming myclient(&myserver, 100); - cout << "wait client " << myclient.ipv4 << endl; + myserver.accept(); + // cout << "wait client " << myclient.ipv4 << endl; + cout << "wait client " << myserver.cli->ipv4 << endl; - string fromclient = myclient.pull(); + string fromclient = myserver.cli->pull(); + // string fromclient = myclient.pull(); cout << "tell client " << fromclient << endl; // usleep(600*1000); sleep(5); - myclient.push(fromclient); + myserver.cli->push(fromclient); + // myclient.push(fromclient); // myclient.~comming(); // while (true) { diff --git a/test/server.o b/test/server.o index 47650b0..ae26bb9 100755 Binary files a/test/server.o and b/test/server.o differ