00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _REMOTESOCKETSITE_HH_
00024 #define _REMOTESOCKETSITE_HH_
00025
00026
00027
00028
00029
00030 #include <vos/corelibs/vos/vosdefs.hh>
00031 #include <vos/corelibs/vos/remotesite.hh>
00032 #include <vos/corelibs/vos/localsocketsite.hh>
00033
00034 namespace VOS
00035 {
00036 class RemoteSocketSite;
00037 class LocalSite;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class AsyncConnect
00050 {
00051 public:
00052 bool* done;
00053 RemoteSocketSite** remotesite;
00054 LocalSite* localpeer;
00055 string remotehost;
00056 unsigned short int remoteport;
00057 string exstring;
00058 bool spooftest;
00059
00060 AsyncConnect(bool* isdone, RemoteSocketSite** rs, LocalSite* localpeer,
00061 const string& host, unsigned short int port, bool isspooftest);
00062 void operator()();
00063 static RemoteSocketSite* connect(const string& h, unsigned short int p, LocalSite* defaultPeer, bool isspooftest);
00064 };
00065
00066
00067
00068
00069 class OutgoingLock : public MessageFilter
00070 {
00071 public:
00072 virtual bool checkMessage(Message* m);
00073 };
00074
00075
00076
00077
00078 class EnqueueOutgoing : public MessageFilter
00079 {
00080 public:
00081 queue< pair<Message*, MessageBlock*> > outgoingQueue;
00082 virtual bool checkMessage(Message* m);
00083 virtual bool checkMessage(MessageBlock* m);
00084 };
00085
00086
00087
00088 class RewriteTo : public MessageFilter
00089 {
00090 public:
00091 string hostandport;
00092 RewriteTo(string hnp) : hostandport(hnp) { }
00093 virtual bool checkMessage(Message* m);
00094 };
00095
00096
00097
00098
00099
00100
00101
00102 class VOS_API RemoteSocketSite : public virtual RemoteSite
00103 {
00104 protected:
00105 unsigned short int remoteport;
00106 int readingFD;
00107 int writingFD;
00108 bool usingSOCKS;
00109 SSL* ssl;
00110 MessageBlock* partialMessage;
00111
00112 void init(const string& hostname, unsigned short int port) throw (SiteConnectionError);
00113
00114 RemoteSocketSite(const string& hostname, unsigned short int port) throw (SiteConnectionError);
00115 RemoteSocketSite(const string& hostname) throw (SiteConnectionError);
00116 RemoteSocketSite(int fd, struct sockaddr_in* peeraddr);
00117
00118 virtual int readStream(char* data, unsigned int datasize);
00119 virtual int writeStream(const char* data, unsigned int datasize);
00120
00121
00122 OutgoingLock outgoinglock;
00123 EnqueueOutgoing enqueueOutgoing;
00124
00125 int sockSendBufSz;
00126 string outputBuffer;
00127
00128 public:
00129 virtual ~RemoteSocketSite();
00130
00131
00132 virtual int getReadingFD() const { return readingFD; }
00133
00134
00135 virtual int getWritingFD() const { return writingFD; }
00136
00137 virtual bool isConnected();
00138
00139
00140
00141
00142
00143 virtual void suppressOutgoing(bool enqueue);
00144
00145
00146
00147
00148 virtual void enableOutgoing(bool sendqueue, const string& rewriteTo = "?");
00149
00150 virtual void sendMessage(Message* m);
00151 virtual void sendMessage(MessageBlock* m);
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 void secureConnection(const string& protocol);
00163
00164
00165
00166
00167
00168 void switchProtocol(SSL_CTX* context);
00169
00170
00171
00172
00173 X509* getCertificate();
00174 virtual void handleDisconnection();
00175 virtual void flushIncomingBuffers();
00176 virtual void flushOutgoingBuffers(const char* data = 0, unsigned int sz = 0);
00177
00178 virtual void excise();
00179
00180
00181 friend void LocalSocketSite::acceptConnectionRequests();
00182 friend class LocalSite;
00183 friend class AsyncConnect;
00184 };
00185 }
00186
00187 #endif