interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/vos/sitepeering.hh

Go to the documentation of this file.
00001 #ifndef _SITEPEERING_HH_
00002 #define _SITEPEERING_HH_
00003 
00004 #include <stdexcept>
00005 #include <set>
00006 
00007 #include <vos/vos/siteextension.hh>
00008 #include <vos/vos/remotesocketsite.hh>
00009 #include <vos/vos/localsite.hh>
00010 #include <vos/vos/iterator.hh>
00011 
00012 namespace VOS {
00013 
00014     /** @class PortBindingError sitepeering.hh vos/vos/sitepeering.hh
00015         @ingroup libvos
00016     */
00017     class VOS_API PortBindingError : public std::runtime_error
00018     {
00019     public:
00020         PortBindingError(const std::string& s) : std::runtime_error(s) { };
00021     };
00022 
00023     /** @class SitePeeringThread localsocketsite.hh vos/vos/localsocketsite.hh
00024         @ingroup libvos
00025 
00026         This may be used one of two ways.  It may be started as a
00027         separate thread by ListenerThread to handle an incoming
00028         connection, or it may be called directly by vop://
00029         SocketProtocolHandler to do site peering for an outgoing
00030         connection.
00031     */
00032     class VOS_API SitePeeringThread
00033     {
00034     private:
00035         void sendHello(const std::string& gotAntiSpoof = "");
00036         bool verifyAlias(VUtil::URL& url, std::string& checkid);
00037         void handleHello(Message* hello);
00038 
00039     protected:
00040         RemoteSiteExtension* rsse;
00041         LocalSiteExtension* lsse;
00042         bool isClient;
00043 
00044     public:
00045         SitePeeringThread(LocalSiteExtension* l, bool isCl);
00046 
00047         /** Copy constructor, required because boost::thread makes a
00048             copy of the thread object it runs.
00049          */
00050         SitePeeringThread(const SitePeeringThread& spt);
00051 
00052         virtual ~SitePeeringThread() { };
00053 
00054         /** If initialized to be a client it will make an outgoing
00055             connection with the supplied host and port.  Otherwise it
00056             uses the supplied socket.  In either event this will
00057             create a new remote Site with RemoteSocketSiteExtension
00058             attached.
00059 
00060             The site peering process involves sending the "core:hello"
00061             message, looking at the host aliases sent by the other
00062             site, and performing the anti-spoof verification check to
00063             ensure that the site aliases are valid.
00064 
00065            @throw NoSuchSiteError if the site could not be connected
00066            to or something failed during the site peering handshake
00067         */
00068         void operator()();
00069 
00070         /** The remote site created in operator()(). */
00071         VUtil::vRef<Site> remotesite;
00072 
00073         static std::string getProtoVersion();
00074         static bool checkProtoVersion(const std::string& s);
00075         static bool checkProtoVersion(Message* m);
00076 
00077         virtual void init() = 0;
00078         virtual void done() = 0;
00079     };
00080 }
00081 
00082 #endif