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