00001 #ifndef IONFLUX_TOOLS_TCPREMOTEPEER 00002 #define IONFLUX_TOOLS_TCPREMOTEPEER 00003 /* ========================================================================== 00004 * Ionflux Tools 00005 * Copyright (c) 2004 Joern P. Meier 00006 * mail@ionflux.org 00007 * -------------------------------------------------------------------------- 00008 * TCPRemotePeer.hpp Remote peer of a TCP connection. 00009 * ========================================================================== 00010 * 00011 * This file is part of Ionflux Tools. 00012 * 00013 * Ionflux Tools is free software; you can redistribute it and/or modify it 00014 * under the terms of the GNU General Public License as published by the Free 00015 * Software Foundation; either version 2 of the License, or (at your option) 00016 * any later version. 00017 * 00018 * Ionflux Tools is distributed in the hope that it will be useful, but 00019 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00020 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00021 * for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with Ionflux Tools; if not, write to the Free Software Foundation, 00025 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 * 00027 * ========================================================================== */ 00028 00029 #include <string> 00030 #include <iostream> 00031 #include <vector> 00032 #include "ionflux/Auth.hpp" 00033 #include "ionflux/TCPSocket.hpp" 00034 #include "ionflux/Message.hpp" 00035 #include "ionflux/MessageDump.hpp" 00036 #include "ionflux/MessageHandler.hpp" 00037 00038 namespace Ionflux 00039 { 00040 00041 namespace Tools 00042 { 00043 00044 class MessageHandler; 00045 00051 class TCPRemotePeer 00052 : public MessageDump 00053 { 00054 protected: 00056 int id; 00058 TCPSocket socket; 00060 std::string recvBuf; 00066 int protocolState; 00071 void *data; 00073 unsigned int dataSize; 00079 Message *message; 00081 MessageHandler *messageHandler; 00083 AuthData auth; 00089 Node *cache; 00090 00091 public: 00093 static const int ID_NOT_SET; 00095 static const int PROTOCOL_STATE_UNDEFINED; 00096 00101 TCPRemotePeer(); 00102 00109 TCPRemotePeer(int initID); 00110 00115 virtual ~TCPRemotePeer(); 00116 00124 virtual bool receive(); 00125 00134 virtual bool send(const std::string &bytes); 00135 00142 virtual void setID(int newID); 00143 00151 virtual void setProtocolState(int newProtocolState); 00152 00163 virtual void setMessageHandler(MessageHandler *newMessageHandler); 00164 00169 virtual int getID(); 00170 00177 virtual TCPSocket &getSocket(); 00178 00185 virtual AuthData &getAuthData(); 00186 00191 virtual std::string &getRecvBuf(); 00192 00199 virtual unsigned int removeRecvBytes(unsigned int numBytes); 00200 00202 virtual void clearRecvBuf(); 00203 00208 virtual int getProtocolState(); 00209 00214 virtual void *getData(); 00215 00220 virtual unsigned int getDataSize(); 00221 00227 virtual Message *getMessage(); 00228 00236 virtual Node *getCache(); 00237 00244 virtual void dump(Message &msg); 00245 00246 }; 00247 00248 } 00249 00250 } 00251 00255 #endif