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 #ifndef _VOS_HH_
00027 #error Please only include "vos.hh"!
00028 #endif
00029
00030
00031
00032
00033
00034 typedef MetaObject* (*metaobject_extender_t)(MetaObject* superobject, const string& type);
00035
00036
00037
00038
00039
00040
00041 class VOS_API LocalSite : public virtual Site, public virtual LocalMetaObject
00042 {
00043 private:
00044 typedef multimap<string, metaobject_extender_t>::iterator MI;
00045 static multimap<string, metaobject_extender_t> localObjectExtensionTable;
00046 public:
00047 class PortBindingError : public runtime_error {
00048 public:
00049 PortBindingError(const string& s) : runtime_error(s) { }
00050 };
00051 protected:
00052 struct SiteTableEntry {
00053 string localPeerName;
00054 MessageBlock* partialMessage;
00055 };
00056 int iteratorsUsingPeerSites;
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 deque<RemoteSite*> peerSitesBuffer_rs;
00072 deque<struct SiteTableEntry*> peerSitesBuffer_st;
00073 deque<RemoteSite*> peerSitesBuffer_remove;
00074
00075 boost::mutex peerSitesBuffer_mutex;
00076
00077
00078 map<RemoteSite*, struct SiteTableEntry*> peerSites;
00079
00080
00081 map<double, list<Message*> > siteMessageQueue;
00082 list<Message*> msgsReady;
00083
00084 struct ::timeval* selectwait;
00085
00086 map<string, RemoteSite*> prioritized;
00087
00088 typedef void (*callback_t)(void* userdata);
00089 struct Callback {
00090 bool repeat;
00091 double timeout;
00092 callback_t callback;
00093 void* userdata;
00094 };
00095
00096 bool callbacklock;
00097 map<double, Callback> callbacks;
00098 queue<pair<double, Callback> > callbackaddqueue;
00099 queue<callback_t> callbackremovequeue;
00100
00101 queue<NotifyEvent*> notifyEvents;
00102 bool notifyflushlock;
00103
00104 map<string, string> antiSpoofMap;
00105
00106 void verifyCheckIDPair(RemoteSocketSite* rss, const string& spoofID);
00107
00108 struct ValidationEntry
00109 {
00110 string checkid;
00111 string hostalias;
00112 vRef<RemoteSocketSite> realsite;
00113 bool favored;
00114 };
00115 map<RemoteSocketSite*, ValidationEntry> pendingValidations;
00116 set<string> pendingValidationHosts;
00117
00118 list< pair<string, RemoteSite*> > needSpoofIDreply;
00119
00120
00121 LocalSite();
00122 public:
00123
00124 virtual ~LocalSite();
00125
00126 virtual void flushIncomingBuffers() = 0;
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 virtual void scheduleMessageBlock(MessageBlock* mb, MessageContext* mc, Site* ss,
00137 double plustime=0.0, const char* extradependency=0);
00138
00139
00140
00141 virtual void runSchedule();
00142
00143 void doCallbacks();
00144 void addCallback(callback_t callback, void* userdata, double timeout, bool repeat);
00145 void removeCallback(callback_t callback);
00146
00147
00148 virtual void removeRemotePeer(RemoteSite* rs);
00149
00150 virtual bool checkScheduleHoldsSite(Site* site);
00151
00152 virtual void sendMessage(Message* m);
00153 virtual void sendMessage(MessageBlock* m);
00154 virtual void setURL(const URL& u);
00155
00156 virtual bool isConnected() {
00157 return true;
00158 }
00159
00160 virtual Site& getSite() { return Site::getSite(); }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 void setTimeoutOnSelect(double sec);
00171
00172
00173
00174 double getTimeoutOnSelect();
00175
00176 virtual void addPrioritizedNonce(const string& nonce, RemoteSite* source);
00177 virtual void removePrioritizedNonce(const string& nonce, RemoteSite* source);
00178
00179 static void extendMetaObject(LocalMetaObject* root, const char* type);
00180
00181
00182
00183 virtual MetaObject* createMetaObject(const char* name, const char* type0, ...);
00184 virtual MetaObject* createMetaObject(const char* name, const deque<string>& typelist);
00185
00186
00187
00188
00189
00190 virtual MetaObject* createMetaObject(const char* name, VobjectAccessControl* ac, const char* type0, ...);
00191
00192
00193
00194
00195
00196
00197 virtual MetaObject* createMetaObject(const char* name, VobjectAccessControl* ac, const deque<string>& typelist);
00198
00199 static void addLocalObjectExtension(const char* type, metaobject_extender_t newmethod);
00200 static bool hasLocalObjectExtension(const char* type);
00201 static void removeLocalObjectExtension(const char* type, metaobject_extender_t oldmethod);
00202
00203 static void printExtensionTable(ostream& stream = std::cerr);
00204
00205 virtual void addNotification(NotifyEvent* ev);
00206 virtual void flushNotifications();
00207 virtual void lockNotificationFlush();
00208 virtual void unlockNotificationFlush();
00209
00210 virtual void insertChild(int position, const string& contextual_name, Vobject* child)
00211 throw (AccessControlError, RemoteError);
00212 virtual void setChild(int position, const string& contextual_name, Vobject* child)
00213 throw (AccessControlError, RemoteError);
00214 virtual void removeChild(int position)
00215 throw (AccessControlError, RemoteError);
00216
00217
00218 void setAntiSpoofIDMapping(const string& recv, const string& sent) { antiSpoofMap[recv] = sent; }
00219
00220
00221 const string& getAntiSpoofIDMapping(const string& recv) { return antiSpoofMap[recv]; }
00222
00223 void takeOverMessages(Site* was, Site* now);
00224
00225 virtual void setPrimaryHostname(string s);
00226
00227 friend void Site::doSitePeering(LocalSite* localsite, RemoteSite* remotesite, bool isspooftest, bool waitforhello);
00228 };
00229
00230 #endif