00001 /* 00002 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By 00003 * downloading, copying, installing or using the software you agree to 00004 * this license. If you do not agree to this license, do not download, 00005 * install, copy or use the software. 00006 * 00007 * University of Waterloo Open Source License 00008 * 00009 * Copyright (c) 2005 University of Waterloo. All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are 00013 * met: 00014 * 00015 * Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * 00018 * Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * 00022 * Neither the name of the University of Waterloo nor the names of its 00023 * contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00027 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00028 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00029 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY 00030 * OF WATERLOO OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00031 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00032 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00033 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00034 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00035 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00036 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 */ 00038 00039 #ifndef _TCA_REGISTRY_H_ 00040 #define _TCA_REGISTRY_H_ 00041 00042 #include <netinet/in.h> 00043 #include <string> 00044 #include <vector> 00045 #include <rpc/rpc.h> 00046 00047 00048 00049 class RegRecord 00050 { 00051 public: 00052 RegRecord() : host_(), link_addr_() { } 00053 00054 RegRecord(const std::string& host, const std::string& link_addr) 00055 : host_(host), link_addr_(link_addr) { } 00056 00057 std::string host_; // partial eid, eg. "tca://host" 00058 std::string link_addr_; 00059 00060 const std::string str() const { return host_ + " -> " + link_addr_; } 00061 }; 00062 00063 00064 00065 class TcaRegistry 00066 { 00067 public: 00068 00069 TcaRegistry() : last_node_(0) { } 00070 00071 bool init_nodes(); 00072 bool init_addrs(); 00073 00074 bool write(const RegRecord& rr, int ttl); 00075 bool read(RegRecord& rr); 00076 00077 protected: 00078 00079 std::vector<std::string> dht_nodes_; // all available node names 00080 std::vector<sockaddr_in> dht_addrs_; // all available node addrs 00081 00082 unsigned int last_node_; // index of last node used 00083 00084 CLIENT* get_node(); // get next available node, starting at cur_node_ 00085 00086 }; 00087 00088 00089 #endif /* _TCA_REGISTRY_H_ */