TcaRegistry.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 University of Waterloo
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #ifndef _TCA_REGISTRY_H_
00019 #define _TCA_REGISTRY_H_
00020 
00021 #include <netinet/in.h>
00022 #include <string>
00023 #include <vector>
00024 #include <rpc/rpc.h>
00025 
00026 
00027 
00028 class RegRecord
00029 {
00030 public:
00031     RegRecord() : host_(), link_addr_() { }
00032 
00033     RegRecord(const std::string& host, const std::string& link_addr)
00034         : host_(host), link_addr_(link_addr) { }
00035 
00036     std::string     host_;          // partial eid, eg.  "tca://host"
00037     std::string     link_addr_;
00038 
00039     const std::string str() const { return host_ + " -> " + link_addr_; }
00040 };
00041 
00042 
00043 
00044 class TcaRegistry
00045 {
00046 public:
00047 
00048     TcaRegistry() : last_node_(0) { }
00049 
00050     bool init_nodes();
00051     bool init_addrs();
00052 
00053     bool write(const RegRecord& rr, int ttl);
00054     bool read(RegRecord& rr);
00055 
00056 protected:
00057 
00058     std::vector<std::string> dht_nodes_;    // all available node names
00059     std::vector<sockaddr_in> dht_addrs_;    // all available node addrs
00060 
00061     unsigned int last_node_;                // index of last node used
00062 
00063     CLIENT* get_node(); // get next available node, starting at cur_node_
00064 
00065 };
00066 
00067 
00068 #endif /* _TCA_REGISTRY_H_ */

Generated on Thu Jun 7 12:54:29 2007 for DTN Reference Implementation by  doxygen 1.5.1