return out << '[' << buf << "]:" << serv;
return out << buf << ':' << serv;
}
+
+// entity_addrvec_t
+
+void entity_addrvec_t::encode(bufferlist& bl, uint64_t features) const
+{
+ if ((features & CEPH_FEATURE_MSG_ADDR2) == 0) {
+ // encode a single legacy entity_addr_t for unfeatured peers
+ if (v.size() > 0) {
+ for (vector<entity_addr_t>::const_iterator p = v.begin();
+ p != v.end(); ++p) {
+ if ((*p).type == (*p).TYPE_LEGACY) {
+ ::encode(*p, bl, 0);
+ return;
+ }
+ }
+ ::encode(v[0], bl, 0);
+ } else {
+ ::encode(entity_addr_t(), bl, 0);
+ }
+ return;
+ }
+ ::encode((__u8)2, bl);
+ ::encode(v, bl, features);
+}
+
+void entity_addrvec_t::decode(bufferlist::iterator& bl)
+{
+ __u8 marker;
+ ::decode(marker, bl);
+ if (marker == 0) {
+ // legacy!
+ ::decode(marker, bl);
+ __u16 rest;
+ ::decode(rest, bl);
+ entity_addr_t addr;
+ addr.type = addr.TYPE_LEGACY;
+ ::decode(addr.nonce, bl);
+ sockaddr_storage ss;
+#if defined(__linux__) || defined(DARWIN) || defined(__FreeBSD__)
+ ::decode(ss, bl);
+#else
+ ceph_sockaddr_storage wireaddr;
+ ::memset(&wireaddr, '\0', sizeof(wireaddr));
+ ::decode(wireaddr, bl);
+ unsigned copysize = MIN(sizeof(wireaddr), sizeof(ss));
+ ::memcpy(&ss, &wireaddr, copysize);
+#endif
+ addr.set_sockaddr((sockaddr*)&ss);
+ v.clear();
+ v.push_back(addr);
+ return;
+ }
+ if (marker == 1) {
+ entity_addr_t addr;
+ DECODE_START(1, bl);
+ ::decode(addr.type, bl);
+ ::decode(addr.nonce, bl);
+ __u32 elen;
+ ::decode(elen, bl);
+ if (elen) {
+ bl.copy(elen, (char*)addr.get_sockaddr());
+ }
+ DECODE_FINISH(bl);
+ v.clear();
+ v.push_back(addr);
+ return;
+ }
+ if (marker > 2)
+ throw buffer::malformed_input("entity_addrvec_marker > 2");
+ ::decode(v, bl);
+}
+
+void entity_addrvec_t::dump(Formatter *f) const
+{
+ f->open_array_section("addrvec");
+ for (vector<entity_addr_t>::const_iterator p = v.begin();
+ p != v.end(); ++p) {
+ f->dump_object("addr", *p);
+ }
+ f->close_section();
+}
+
+void entity_addrvec_t::generate_test_instances(list<entity_addrvec_t*>& ls)
+{
+ ls.push_back(new entity_addrvec_t());
+ ls.push_back(new entity_addrvec_t());
+ ls.back()->v.push_back(entity_addr_t());
+ ls.push_back(new entity_addrvec_t());
+ ls.back()->v.push_back(entity_addr_t());
+ ls.back()->v.push_back(entity_addr_t());
+}
};
} // namespace std
+struct entity_addrvec_t {
+ vector<entity_addr_t> v;
+
+ unsigned size() const { return v.size(); }
+ bool empty() const { return v.empty(); }
+
+ void encode(bufferlist& bl, uint64_t features) const;
+ void decode(bufferlist::iterator& bl);
+ void dump(Formatter *f) const;
+ static void generate_test_instances(list<entity_addrvec_t*>& ls);
+};
+WRITE_CLASS_ENCODER_FEATURES(entity_addrvec_t);
/*
* a particular entity instance