1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include "include/Spinlock.h"
8 #include "include/types.h"
11 #include "msg/simple/SimpleMessenger.h"
12 #include "msg/async/AsyncMessenger.h"
14 #include "msg/xio/XioMessenger.h"
17 Messenger *Messenger::create_client_messenger(CephContext *cct, string lname)
19 std::string public_msgr_type = cct->_conf->ms_public_type.empty() ? cct->_conf->get_val<std::string>("ms_type") : cct->_conf->ms_public_type;
21 get_random_bytes((char*)&nonce, sizeof(nonce));
22 return Messenger::create(cct, public_msgr_type, entity_name_t::CLIENT(),
23 std::move(lname), nonce, 0);
26 Messenger *Messenger::create(CephContext *cct, const string &type,
27 entity_name_t name, string lname,
28 uint64_t nonce, uint64_t cflags)
31 if (type == "random") {
32 static std::random_device seed;
33 static std::default_random_engine random_engine(seed());
34 static Spinlock random_lock;
36 std::lock_guard<Spinlock> lock(random_lock);
37 std::uniform_int_distribution<> dis(0, 1);
38 r = dis(random_engine);
40 if (r == 0 || type == "simple")
41 return new SimpleMessenger(cct, name, std::move(lname), nonce);
42 else if (r == 1 || type.find("async") != std::string::npos)
43 return new AsyncMessenger(cct, name, type, std::move(lname), nonce);
45 else if ((type == "xio") &&
46 cct->check_experimental_feature_enabled("ms-type-xio"))
47 return new XioMessenger(cct, name, std::move(lname), nonce, cflags);
49 lderr(cct) << "unrecognized ms_type '" << type << "'" << dendl;
53 void Messenger::set_endpoint_addr(const entity_addr_t& a,
54 const entity_name_t &name)
57 if (a.get_family() == AF_INET)
58 hostlen = sizeof(struct sockaddr_in);
59 else if (a.get_family() == AF_INET6)
60 hostlen = sizeof(struct sockaddr_in6);
65 char buf[NI_MAXHOST] = { 0 };
66 getnameinfo(a.get_sockaddr(), hostlen, buf, sizeof(buf),
67 NULL, 0, NI_NUMERICHOST);
69 trace_endpoint.copy_ip(buf);
71 trace_endpoint.set_port(a.get_port());
75 * Pre-calculate desired software CRC settings. CRC computation may
76 * be disabled by default for some transports (e.g., those with strong
77 * hardware checksum support).
79 int Messenger::get_default_crc_flags(md_config_t * conf)
82 if (conf->ms_crc_data)
84 if (conf->ms_crc_header)