00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ns_http_h
00023 #define ns_http_h
00024
00025 #include <stdlib.h>
00026 #include <tcl.h>
00027 #include "config.h"
00028 #include "agent.h"
00029 #include "ns-process.h"
00030 #include "app.h"
00031
00032 #include "pagepool.h"
00033 #include "inval-agent.h"
00034 #include "tcpapp.h"
00035 #include "http-aux.h"
00036
00037 class HttpApp : public Process {
00038 public:
00039 HttpApp();
00040 virtual ~HttpApp();
00041
00042 virtual int command(int argc, const char*const* argv);
00043 void log(const char *fmt, ...);
00044 int id() const { return id_; }
00045
00046 virtual void process_data(int size, AppData* d);
00047 virtual AppData* get_data(int&, AppData*) {
00048
00049 abort();
00050 return NULL;
00051 }
00052
00053 protected:
00054 int add_cnc(HttpApp *client, TcpApp *agt);
00055 void delete_cnc(HttpApp *client);
00056 TcpApp* lookup_cnc(HttpApp *client);
00057
00058 void set_pagepool(ClientPagePool* pp) { pool_ = pp; }
00059
00060 Tcl_HashTable *tpa_;
00061 int id_;
00062 ClientPagePool *pool_;
00063 Tcl_Channel log_;
00064 };
00065
00066
00067
00068
00069
00070 class HttpServer : public HttpApp {
00071 public:
00072
00073 };
00074
00075 class HttpInvalServer : public HttpServer {
00076 public:
00077 };
00078
00079
00080 class HttpYucInvalServer : public HttpInvalServer {
00081 public:
00082 HttpYucInvalServer();
00083
00084 virtual int command(int argc, const char*const* argv);
00085 void add_inv(const char *name, double mtime);
00086
00087 protected:
00088
00089 HttpUInvalAgent *inv_sender_;
00090 InvalidationRec *invlist_;
00091 int num_inv_;
00092
00093 void send_heartbeat();
00094 HttpHbData* pack_heartbeat();
00095 virtual void send_hb_helper(int size, AppData *data);
00096 InvalidationRec* get_invrec(const char *name);
00097
00098 int Ca_, Cb_, push_thresh_, enable_upd_;
00099 int push_high_bound_, push_low_bound_;
00100 double hb_interval_;
00101 };
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 class HttpClient : public HttpApp {
00112 };
00113
00114
00115
00116
00117
00118
00119
00120 class HttpCache : public HttpApp {
00121 };
00122
00123 class HttpInvalCache : public HttpCache {
00124 };
00125
00126
00127
00128 const int HTTP_INVALCACHE_FILTERED = 0;
00129 const int HTTP_INVALCACHE_UNFILTERED = 1;
00130
00131
00132 class HttpMInvalCache : public HttpInvalCache {
00133 public:
00134 HttpMInvalCache();
00135 virtual ~HttpMInvalCache();
00136
00137 virtual int command(int argc, const char*const* argv);
00138 virtual void process_data(int size, AppData* data);
00139 virtual void timeout(int reason);
00140
00141 void handle_node_failure(int cid);
00142 void invalidate_server(int sid);
00143 void add_inv(const char *name, double mtime);
00144
00145 protected:
00146 HBTimer hb_timer_;
00147 HttpInvalAgent **inv_sender_;
00148 int num_sender_;
00149 int size_sender_;
00150 InvalidationRec *invlist_;
00151 int num_inv_;
00152
00153 void send_heartbeat();
00154 HttpHbData* pack_heartbeat();
00155 virtual void send_hb_helper(int size, AppData *data);
00156
00157 int recv_inv(HttpHbData *d);
00158 virtual void process_inv(int n, InvalidationRec *ivlist, int cache);
00159 virtual int recv_inv_filter(ClientPage* pg, InvalidationRec *p) {
00160 return ((pg == NULL) || (pg->mtime() >= p->mtime()) ||
00161 !pg->is_valid()) ?
00162 HTTP_INVALCACHE_FILTERED : HTTP_INVALCACHE_UNFILTERED;
00163 }
00164 InvalidationRec* get_invrec(const char *name);
00165
00166
00167
00168 struct SState {
00169 SState(NeighborCache* c) : down_(0), cache_(c) {}
00170 int is_down() { return down_; }
00171 void down() { down_ = 1; }
00172 void up() { down_ = 0; }
00173 NeighborCache* cache() { return cache_; }
00174 int down_;
00175 NeighborCache *cache_;
00176 };
00177
00178 Tcl_HashTable sstate_;
00179 void add_sstate(int sid, SState* sst);
00180 SState* lookup_sstate(int sid);
00181
00182 void check_sstate(int sid, int cid);
00183
00184
00185 Tcl_HashTable nbr_;
00186 void add_nbr(HttpMInvalCache* c);
00187 NeighborCache* lookup_nbr(int id);
00188
00189 HttpUInvalAgent *inv_parent_;
00190
00191 void recv_heartbeat(int id);
00192 void recv_leave(HttpLeaveData *d);
00193 void send_leave(HttpLeaveData *d);
00194
00195 double hb_interval_;
00196 int enable_upd_;
00197 int Ca_, Cb_, push_thresh_;
00198 int push_high_bound_, push_low_bound_;
00199
00200 HttpInvalAgent **upd_sender_;
00201 int num_updater_;
00202 int size_updater_;
00203
00204 void add_update(const char *name, double mtime);
00205 void send_upd(ClientPage *pg);
00206 int recv_upd(HttpUpdateData *d);
00207 virtual void send_upd_helper(int pgsize, AppData* data);
00208 HttpUpdateData* pack_upd(ClientPage *pg);
00209
00210
00211 static HttpMInvalCache** CacheRepository_;
00212 static int NumCache_;
00213 static void add_cache(HttpMInvalCache* c);
00214 static HttpMInvalCache* map_cache(int id) {
00215 return CacheRepository_[id];
00216 }
00217 };
00218
00219
00220
00221
00222
00223 class HttpPercInvalCache : virtual public HttpMInvalCache {
00224 public:
00225 HttpPercInvalCache();
00226 int command(int argc, const char*const* argv);
00227
00228 protected:
00229 virtual int recv_inv_filter(ClientPage *pg, InvalidationRec *ir) {
00230
00231
00232 return ((pg == NULL) || (pg->mtime() >= ir->mtime()) ||
00233 !pg->is_header_valid()) ?
00234 HTTP_INVALCACHE_FILTERED : HTTP_INVALCACHE_UNFILTERED;
00235 }
00236
00237
00238 int direct_request_;
00239 };
00240
00241 #endif // ns_http_h