diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-07-17 20:17:19 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-07-17 20:17:19 +0200 |
commit | 83c885f9702bb02206ad8dfa95b78333401e5154 (patch) | |
tree | 1cab9042ea686858af8306d78cbccaf608aa9d14 | |
parent | 9f96fb364bea47ec76dea57fc14e03e0e42fa5e3 (diff) | |
download | mad-83c885f9702bb02206ad8dfa95b78333401e5154.tar mad-83c885f9702bb02206ad8dfa95b78333401e5154.zip |
Identify-Pakete implementiert
-rw-r--r-- | Konzept/Netzwerk.txt | 9 | ||||
-rw-r--r-- | src/Common/Request/DisconnectRequest.h | 4 | ||||
-rw-r--r-- | src/Common/Request/IdentifyRequest.h (renamed from src/Common/Request/PingRequest.h) | 26 | ||||
-rw-r--r-- | src/Common/Request/Makefile.am | 2 | ||||
-rw-r--r-- | src/Common/Request/Makefile.in | 2 | ||||
-rw-r--r-- | src/Common/RequestManager.cpp | 15 | ||||
-rw-r--r-- | src/Net/Packet.h | 4 | ||||
-rw-r--r-- | src/madc.cpp | 4 |
8 files changed, 37 insertions, 29 deletions
diff --git a/Konzept/Netzwerk.txt b/Konzept/Netzwerk.txt index 39ea274..6aee849 100644 --- a/Konzept/Netzwerk.txt +++ b/Konzept/Netzwerk.txt @@ -33,6 +33,14 @@ Jeder Client/Dämon und der Kern verwalten ihre eigenen Request-IDs, und insgesa Damit es nicht zu Konflikten zwischen vom Kern und von Clients/Dämonen generierten IDs kommt, ist bei Client/Dämon-IDs das letzte Bit gesetzt, bei Kern-IDs nicht. +Implementierte Pakettypen: + +0000: OK (leeres Paket) +0001: Error (Fehlerinformationen) +0002: Disconnect (leeres Paket) +0010: Identify request (bisher: enthält den Namen des identifizierenden Dämons) +0011: Identify reply (bisher: leer) + Mögliche Pakettypen: * Login-Anfrage -> Übertragung von Kerberos-Daten @@ -42,7 +50,6 @@ Mögliche Pakettypen: * Status-Antwort * Kommando (Shutdown, etc.) * Kommando-Antwort -* Error * Verbindung trennen - Anfrage und Antwort (implementiert) + weitere Anfragen und Antworten... diff --git a/src/Common/Request/DisconnectRequest.h b/src/Common/Request/DisconnectRequest.h index 9023c13..77509a0 100644 --- a/src/Common/Request/DisconnectRequest.h +++ b/src/Common/Request/DisconnectRequest.h @@ -48,7 +48,7 @@ class DisconnectRequest: public Request { if(isSent()) return false; - if(!connection->send(Net::Packet(Net::Packet::TYPE_DISCONNECT_REQ, requestId))) + if(!connection->send(Net::Packet(Net::Packet::TYPE_DISCONNECT, requestId))) return false; setSent(); @@ -59,7 +59,7 @@ class DisconnectRequest: public Request { if(isFinished()) return false; - if(packet.getType() != Net::Packet::TYPE_DISCONNECT_REP) + if(packet.getType() != Net::Packet::TYPE_OK) return false; // TODO Logging connection->disconnect(); diff --git a/src/Common/Request/PingRequest.h b/src/Common/Request/IdentifyRequest.h index 92e3c1a..9df1548 100644 --- a/src/Common/Request/PingRequest.h +++ b/src/Common/Request/IdentifyRequest.h @@ -1,5 +1,5 @@ /* - * PingRequest.h + * IdentifyRequest.h * * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> * @@ -17,13 +17,14 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MAD_COMMON_REQUEST_PINGREQUEST_H_ -#define MAD_COMMON_REQUEST_PINGREQUEST_H_ +#ifndef IDENTIFYREQUEST_H_ +#define IDENTIFYREQUEST_H_ #include "Request.h" #include "../RequestManager.h" #include <Net/Connection.h> #include <Net/Packet.h> +#include <string> #include <iostream> @@ -31,13 +32,15 @@ namespace Mad { namespace Common { namespace Request { -class PingRequest : public Request { +class IdentifyRequest: public Request { private: - PingRequest() {} + IdentifyRequest(const std::string &hostname0) : hostname(hostname0) {} + + std::string hostname; public: - static bool send(Net::Connection *connection, RequestManager &requestManager) { - Request *request = new PingRequest(); + static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0) { + Request *request = new IdentifyRequest(hostname0); if(requestManager.sendRequest(connection, request)) return true; @@ -50,7 +53,7 @@ class PingRequest : public Request { if(isSent()) return false; - if(!connection->send(Net::Packet(Net::Packet::TYPE_PING, requestId))) + if(!connection->send(Net::Packet(Net::Packet::TYPE_IDENTIFY_REQ, requestId, hostname.c_str(), hostname.length()))) return false; setSent(); @@ -61,11 +64,10 @@ class PingRequest : public Request { if(isFinished()) return false; - if(packet.getType() != Net::Packet::TYPE_PONG) + if(packet.getType() != Net::Packet::TYPE_IDENTIFY_REP) return false; // TODO Logging - std::cout << "Received ping reply." << std::endl; - std::cout << " Request ID: " << packet.getRequestId() << std::endl; + std::cout << "Identified as '" << hostname << "'." << std::endl; setFinished(); return true; @@ -76,4 +78,4 @@ class PingRequest : public Request { } } -#endif /* MAD_COMMON_REQUEST_PINGREQUEST_H_ */ +#endif /* IDENTIFYREQUEST_H_ */ diff --git a/src/Common/Request/Makefile.am b/src/Common/Request/Makefile.am index 17e47fe..a7de050 100644 --- a/src/Common/Request/Makefile.am +++ b/src/Common/Request/Makefile.am @@ -1 +1 @@ -noinst_HEADERS = DisconnectRequest.h PingRequest.h Request.h +noinst_HEADERS = DisconnectRequest.h IdentifyRequest.h Request.h diff --git a/src/Common/Request/Makefile.in b/src/Common/Request/Makefile.in index d96c0a7..9c48118 100644 --- a/src/Common/Request/Makefile.in +++ b/src/Common/Request/Makefile.in @@ -162,7 +162,7 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -noinst_HEADERS = DisconnectRequest.h PingRequest.h Request.h +noinst_HEADERS = DisconnectRequest.h IdentifyRequest.h Request.h all: all-am .SUFFIXES: diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index 86d3529..755f59b 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -47,16 +47,15 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack } switch(packet.getType()) { - case Net::Packet::TYPE_PING: - std::cout << "Received ping request." << std::endl; - std::cout << " Request ID: " << packet.getRequestId() << std::endl; - - connection->send(Net::Packet(Net::Packet::TYPE_PONG, packet.getRequestId(), packet.getData(), packet.getLength())); - break; - case Net::Packet::TYPE_DISCONNECT_REQ: - connection->send(Net::Packet(Net::Packet::TYPE_DISCONNECT_REP, packet.getRequestId())); + case Net::Packet::TYPE_DISCONNECT: + connection->send(Net::Packet(Net::Packet::TYPE_OK, packet.getRequestId())); connection->disconnect(); break; + case Net::Packet::TYPE_IDENTIFY_REQ: + std::cout << "Received identify request from '" << std::string((char*)packet.getData(), packet.getLength()) << "'." << std::endl; + + connection->send(Net::Packet(Net::Packet::TYPE_IDENTIFY_REP, packet.getRequestId(), packet.getData(), packet.getLength())); + break; default: std::cerr << "Received an unexpected packet." << std::endl; } diff --git a/src/Net/Packet.h b/src/Net/Packet.h index c867ffa..2d2fb77 100644 --- a/src/Net/Packet.h +++ b/src/Net/Packet.h @@ -29,8 +29,8 @@ namespace Net { class Packet { public: enum Type { - TYPE_PING = 0x0000, TYPE_PONG = 0x0001, - TYPE_DISCONNECT_REQ = 0x0010, TYPE_DISCONNECT_REP = 0x0011 + TYPE_OK = 0x0000, TYPE_ERROR = 0x0001, TYPE_DISCONNECT = 0x0002, + TYPE_IDENTIFY_REQ = 0x0010, TYPE_IDENTIFY_REP = 0x0011 }; struct Data { diff --git a/src/madc.cpp b/src/madc.cpp index f987a9d..9609e56 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -22,7 +22,7 @@ #include "Net/Packet.h" #include "Common/RequestManager.h" #include "Common/Request/DisconnectRequest.h" -#include "Common/Request/PingRequest.h" +#include "Common/Request/IdentifyRequest.h" #include <iostream> int main() { @@ -43,7 +43,7 @@ int main() { requestManager.registerConnection(connection); - Mad::Common::Request::PingRequest::send(connection, requestManager); + Mad::Common::Request::IdentifyRequest::send(connection, requestManager, "test"); Mad::Common::Request::DisconnectRequest::send(connection, requestManager); while(connection->isConnected()) { |