Signed-off-by: Sage Weil <sage@redhat.com>
using ceph::encode;
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 == entity_addr_t::TYPE_LEGACY) {
- encode(*p, bl, 0);
- return;
- }
- }
- encode(v[0], bl, 0);
- } else {
- encode(entity_addr_t(), bl, 0);
- }
+ encode(legacy_addr(), bl, 0);
return;
}
encode((__u8)2, bl);
unsigned size() const { return v.size(); }
bool empty() const { return v.empty(); }
+ entity_addr_t legacy_addr() const {
+ for (auto& a : v) {
+ if (a.type == entity_addr_t::TYPE_LEGACY) {
+ return a;
+ }
+ }
+ return entity_addr_t();
+ }
+
bool parse(const char *s, const char **end = 0);
void encode(bufferlist& bl, uint64_t features) const;