diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-06-25 19:05:00 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-06-25 19:05:00 +0200 |
commit | 06f98c0289be27cca68f4400fb792e1d27a846b2 (patch) | |
tree | a1ccf91970690007be6199ef2dbdbef7fabacf1f /src/Net/ClientConnection.cpp | |
parent | 4da2aa187717f34a98792ca6708da959b7937998 (diff) | |
download | mad-06f98c0289be27cca68f4400fb792e1d27a846b2.tar mad-06f98c0289be27cca68f4400fb792e1d27a846b2.zip |
Initialisierung der Verbindung
Diffstat (limited to 'src/Net/ClientConnection.cpp')
-rw-r--r-- | src/Net/ClientConnection.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/Net/ClientConnection.cpp b/src/Net/ClientConnection.cpp index d49054d..1523b44 100644 --- a/src/Net/ClientConnection.cpp +++ b/src/Net/ClientConnection.cpp @@ -27,7 +27,33 @@ namespace Mad { namespace Net { -void ClientConnection::connect(const IPAddress &address) throw(ConnectionException) { +void ClientConnection::sendConnectionHeader(bool daemon) { + ConnectionHeader header = {'M', 'A', 'D', daemon ? 'D' : 'C', 0, 1, 1, 1}; + + rawSend(reinterpret_cast<unsigned char*>(&header), sizeof(header)); + rawReceive(sizeof(ConnectionHeader), sigc::mem_fun(this, &ClientConnection::connectionHeaderReceiveHandler)); +} + +void ClientConnection::connectionHeaderReceiveHandler(const void *data, unsigned long length) { + if(length != sizeof(ConnectionHeader)) + // Error... disconnect + return; + + const ConnectionHeader *header = reinterpret_cast<const ConnectionHeader*>(data); + + if(header->m != 'M' || header->a != 'A' || header->d != 'D') + // Error... disconnect + return; + + if(header->protVerMin != 1) + // Unsupported protocol... disconnect + return; + + connecting = false; + enterReceiveLoop(); +} + +void ClientConnection::connect(const IPAddress &address, bool daemon) throw(ConnectionException) { const int kx_list[] = {GNUTLS_KX_ANON_DH, 0}; if(connected) @@ -46,6 +72,7 @@ void ClientConnection::connect(const IPAddress &address) throw(ConnectionExcepti } connected = true; + connecting = true; gnutls_init(&session, GNUTLS_CLIENT); @@ -63,7 +90,7 @@ void ClientConnection::connect(const IPAddress &address) throw(ConnectionExcepti throw ConnectionException("gnutls_handshake()", gnutls_strerror(ret)); } - enterReceiveLoop(); + sendConnectionHeader(daemon); } void ClientConnection::disconnect() { |