msg/msg_types: prefix addr with type; - for none

Previously entityt_addr_t() rendered as ":/0".  Now it is
"-".

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2016-06-18 12:45:11 -04:00
parent 19f48b35f7
commit 3561eb380a
5 changed files with 45 additions and 7 deletions

View File

@ -65,6 +65,17 @@ bool entity_addr_t::parse(const char *s, const char **end)
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++;
@ -140,10 +151,24 @@ bool entity_addr_t::parse(const char *s, const char **end)
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 };

View File

@ -207,8 +207,16 @@ WRITE_CLASS_ENCODER(ceph_sockaddr_storage)
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;
@ -446,10 +454,7 @@ struct entity_addr_t {
};
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; }

View File

@ -84,7 +84,7 @@ TEST_F(DNSResolverTest, resolve_ip_addr_fail) {
ASSERT_EQ(ret, -1);
std::ostringstream os;
os << addr;
ASSERT_EQ(os.str(), ":/0");
ASSERT_EQ(os.str(), "-");
}

View File

@ -49,7 +49,7 @@ int TestWatchNotify::list_watchers(const std::string& o,
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;

View File

@ -36,6 +36,14 @@ const char *addr_checks[][3] = {
{ "::", "[::]: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 },
};