00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _LOCALSITE_HH_
00024 #define _LOCALSITE_HH_
00025
00026 #include <vos/corelibs/vos/vosdefs.hh>
00027 #include <vos/corelibs/vos/site.hh>
00028 #include <vos/corelibs/vos/localmetaobject.hh>
00029
00030 #include <map>
00031 #include <queue>
00032 #include <iostream>
00033
00034 namespace VOS
00035 {
00036 class RemoteSite;
00037 class RemoteSocketSite;
00038
00039 typedef MetaObject* (*metaobject_extender_t)(MetaObject* superobject, const string& type);
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class VOS_API LocalSite : public virtual Site, public virtual LocalMetaObject
00050 {
00051 private:
00052 typedef multimap<string, metaobject_extender_t>::iterator MI;
00053 static multimap<string, metaobject_extender_t> localObjectExtensionTable;
00054 public:
00055 class PortBindingError : public runtime_error {
00056 public:
00057 PortBindingError(const string& s) : runtime_error(s) { }
00058 };
00059 protected:
00060 struct SiteTableEntry {
00061 string localPeerName;
00062 MessageBlock* partialMessage;
00063 };
00064 int iteratorsUsingPeerSites;
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 deque<RemoteSite*> peerSitesBuffer_rs;
00080 deque<struct SiteTableEntry*> peerSitesBuffer_st;
00081 deque<RemoteSite*> peerSitesBuffer_remove;
00082
00083 boost::mutex peerSitesBuffer_mutex;
00084
00085
00086 map<RemoteSite*, struct SiteTableEntry*> peerSites;
00087
00088
00089 map<double, list<Message*> > siteMessageQueue;
00090 list<Message*> msgsReady;
00091 list<Message*> prioritizedQueue;
00092
00093 struct ::timeval* selectwait;
00094
00095 map<string, RemoteSite*> prioritized;
00096
00097 public:
00098
00099
00100
00101
00102 typedef void (*callback_t)(void* userdata);
00103
00104
00105
00106
00107 class CallbackListener {
00108 public:
00109 virtual void notifySiteCallback() = 0;
00110 };
00111
00112 protected:
00113 struct CallbackInfo {
00114 bool repeat;
00115 double timeout;
00116 callback_t callback;
00117 void* userdata;
00118 CallbackListener* listener;
00119 };
00120
00121 bool callbacklock;
00122 map<double, CallbackInfo> callbacks;
00123 queue<pair<double, CallbackInfo> > callbackaddqueue;
00124 queue<callback_t> callbackremovequeue;
00125 queue<CallbackListener*> callback_listener_remove_queue;
00126 void scheduleCallback(callback_t callback, CallbackListener* listener, void* userdata, double timeout, bool repeat);
00127
00128 queue<NotifyEvent*> notifyEvents;
00129 bool notifyflushlock;
00130
00131 map<string, string> antiSpoofMap;
00132
00133 void verifyCheckIDPair(RemoteSocketSite* rss, const string& spoofID);
00134
00135 struct ValidationEntry
00136 {
00137 string checkid;
00138 string hostalias;
00139 vRef<RemoteSocketSite> realsite;
00140 bool favored;
00141 };
00142 map<RemoteSocketSite*, ValidationEntry> pendingValidations;
00143 set<string> pendingValidationHosts;
00144
00145 list< pair<string, RemoteSite*> > needSpoofIDreply;
00146
00147
00148 LocalSite();
00149 public:
00150
00151 virtual ~LocalSite();
00152
00153 virtual void flushIncomingBuffers() = 0;
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 virtual void scheduleMessageBlock(MessageBlock* mb, MessageContext* mc, Site* ss,
00164 double plustime=0.0, const char* extradependency=0);
00165
00166
00167 virtual void runSchedule();
00168
00169
00170 void doCallbacks();
00171
00172
00173
00174
00175 void addCallback(CallbackListener* listener, double timeout, bool repeat = true);
00176
00177
00178 void addCallback(callback_t callback, void* userdata, double timeout, bool repeat = true);
00179
00180
00181 void removeCallback(callback_t callback);
00182
00183
00184 void removeCallback(CallbackListener* listener);
00185
00186
00187 virtual void removeRemotePeer(RemoteSite* rs);
00188
00189
00190
00191
00192
00193 virtual bool checkScheduleHoldsSite(Site* site);
00194
00195 virtual void sendMessage(Message* m);
00196 virtual void sendMessage(MessageBlock* m);
00197 virtual void setURL(const URL& u);
00198
00199
00200 virtual bool isConnected() {
00201 return true;
00202 }
00203
00204 virtual Site& getSite() { return Site::getSite(); }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 void setTimeoutOnSelect(double sec);
00217
00218
00219
00220
00221 double getTimeoutOnSelect();
00222
00223 virtual void addPrioritizedNonce(const string& nonce, RemoteSite* source);
00224 virtual void removePrioritizedNonce(const string& nonce, RemoteSite* source);
00225
00226
00227 static void extendMetaObject(LocalMetaObject* root, const char* type);
00228
00229
00230
00231
00232
00233 virtual MetaObject* createMetaObject(const char* name, const char* type0, ...);
00234 virtual MetaObject* createMetaObject(const char* name, const deque<string>& typelist);
00235
00236
00237
00238
00239
00240
00241 virtual MetaObject* createMetaObject(const char* name, VobjectAccessControl* ac, const char* type0, ...);
00242
00243
00244
00245
00246
00247
00248 virtual MetaObject* createMetaObject(const char* name, VobjectAccessControl* ac, const deque<string>& typelist);
00249
00250
00251
00252
00253
00254
00255
00256 template<class T> T* createMetaObject(const char* name = 0, VobjectAccessControl* ac = 0) {
00257 if(ac)
00258 return meta_cast<T*>(createMetaObject(name, ac, typeid(T).name(), 0));
00259 else
00260 return meta_cast<T*>(createMetaObject(name, typeid(T).name(), 0));
00261 }
00262
00263
00264 static void addLocalObjectExtension(const char* type, metaobject_extender_t newmethod);
00265 static void removeLocalObjectExtension(const char* type, metaobject_extender_t oldmethod);
00266
00267 static void printExtensionTable(ostream& stream = std::cerr);
00268
00269
00270
00271
00272
00273 virtual void addNotification(NotifyEvent* ev);
00274
00275
00276 virtual void flushNotifications();
00277
00278
00279
00280
00281 virtual void lockNotificationFlush();
00282
00283
00284 virtual void unlockNotificationFlush();
00285
00286 virtual void insertChild(int position, const string& contextual_name, Vobject* child)
00287 throw (AccessControlError, RemoteError);
00288 virtual void setChild(int position, const string& contextual_name, Vobject* child)
00289 throw (AccessControlError, RemoteError);
00290 virtual void removeChild(int position)
00291 throw (AccessControlError, RemoteError);
00292
00293
00294 void setAntiSpoofIDMapping(const string& recv, const string& sent) { antiSpoofMap[recv] = sent; }
00295
00296
00297 const string& getAntiSpoofIDMapping(const string& recv) { return antiSpoofMap[recv]; }
00298
00299
00300
00301
00302
00303 void takeOverMessages(Site* was, Site* now);
00304
00305
00306
00307 virtual void setPrimaryHostname(string s);
00308
00309 friend void Site::doSitePeering(LocalSite* localsite, RemoteSite* remotesite, bool isspooftest, bool waitforhello);
00310 };
00311 }
00312
00313 #endif