memset(this, 0, sizeof(*this));
const char *start = s;
+
+ int newtype = TYPE_DEFAULT;
+ if (strncmp("legacy:", s, 7) == 0) {
+ start += 7;
+ newtype = TYPE_LEGACY;
+ } else if (*s == '-') {
+ *this = entity_addr_t();
+ *end = s + 1;
+ return true;
+ }
+
bool brackets = false;
if (*start == '[') {
start++;
if (end)
*end = p;
+ type = newtype;
+
//cout << *this << std::endl;
return true;
}
+ostream& operator<<(ostream& out, const entity_addr_t &addr)
+{
+ if (addr.type == entity_addr_t::TYPE_NONE) {
+ return out << "-";
+ }
+ if (addr.type != entity_addr_t::TYPE_DEFAULT) {
+ out << entity_addr_t::get_type_name(addr.type) << ":";
+ }
+ out << addr.get_sockaddr() << '/' << addr.nonce;
+ return out;
+}
+
ostream& operator<<(ostream& out, const sockaddr_storage &ss)
{
char buf[NI_MAXHOST] = { 0 };
struct entity_addr_t {
typedef enum {
TYPE_NONE = 0,
- TYPE_LEGACY = 1,
+ TYPE_LEGACY = 1, ///< legacy msgr1 protocol (ceph jewel and older)
} type_t;
+ static const type_t TYPE_DEFAULT = TYPE_LEGACY;
+ static const char *get_type_name(int t) {
+ switch (t) {
+ case TYPE_NONE: return "none";
+ case TYPE_LEGACY: return "legacy";
+ default: return "???";
+ }
+ };
__u32 type;
__u32 nonce;
};
WRITE_CLASS_ENCODER_FEATURES(entity_addr_t)
-inline ostream& operator<<(ostream& out, const entity_addr_t &addr)
-{
- return out << addr.get_sockaddr() << '/' << addr.nonce;
-}
+ostream& operator<<(ostream& out, const entity_addr_t &addr);
inline bool operator==(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) == 0; }
inline bool operator!=(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) != 0; }
ASSERT_EQ(ret, -1);
std::ostringstream os;
os << addr;
- ASSERT_EQ(os.str(), ":/0");
+ ASSERT_EQ(os.str(), "-");
}
watcher->watch_handles.begin();
it != watcher->watch_handles.end(); ++it) {
obj_watch_t obj;
- strcpy(obj.addr, ":/0");
+ strcpy(obj.addr, "-");
obj.watcher_id = static_cast<int64_t>(it->second.gid);
obj.cookie = it->second.handle;
obj.timeout_seconds = 30;
{ "::", "[::]:0/0", "" },
{ "::zz", "[::]:0/0", "zz" },
{ ":: 12:34", "[::]:0/0", " 12:34" },
+ { "-", "-", "" },
+ { "-asdf", "-", "asdf" },
+ { "legacy:1.2.3.4", "1.2.3.4:0/0", "" },
+ { "legacy:1.2.3.4:12", "1.2.3.4:12/0", "" },
+ { "legacy:1.2.3.4:12/34", "1.2.3.4:12/34", "" },
+ { "msgr2:1.2.3.4", "msgr2:1.2.3.4:0/0", "" },
+ { "msgr2:1.2.3.4:12", "msgr2:1.2.3.4:12/0", "" },
+ { "msgr2:1.2.3.4:12/34", "msgr2:1.2.3.4:12/34", "" },
{ NULL, NULL, NULL },
};