summaryrefslogtreecommitdiffstats
path: root/src/Net/ClientConnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Net/ClientConnection.cpp')
-rw-r--r--src/Net/ClientConnection.cpp31
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() {