#define dout_prefix _conn_prefix(_dout)
ostream& AsyncConnection::_conn_prefix(std::ostream *_dout) {
return *_dout << "-- " << async_msgr->get_myaddrs() << " >> "
- << peer_addrs << " conn(" << this
+ << target_addr << " conn(" << this
<< (msgr2 ? " msgr2" : " legacy")
<< " :" << port
<< " s=" << get_state_name(state)
<< " (socket is " << socket_addr << ")" << dendl;
}
set_peer_addr(peer_addr); // so that connection_state gets set up
+ target_addr = peer_addr;
state = STATE_ACCEPTING_WAIT_CONNECT_MSG;
break;
}
std::lock_guard<std::mutex> l(lock);
cs = std::move(socket);
socket_addr = addr;
+ target_addr = addr; // until we know better
state = STATE_ACCEPTING;
// rescheduler connection in order to avoid lock dep
center->dispatch_event_external(read_handler);
}
// Only call when AsyncConnection first construct
- void connect(const entity_addrvec_t& addrs, int type) {
+ void connect(const entity_addrvec_t& addrs, int type, entity_addr_t& target) {
set_peer_type(type);
set_peer_addrs(addrs);
policy = msgr->get_policy(type);
+ target_addr = target;
_connect();
}
// Only call when AsyncConnection first construct
// Accepting state
bool msgr2 = false;
entity_addr_t socket_addr;
+ entity_addr_t target_addr; // which of the peer_addrs we're using
CryptoKey session_key;
bool replacing; // when replacing process happened, we will reply connect
// side with RETRY tag and accept side will clear replaced
ldout(cct, 10) << __func__ << " " << addrs
<< ", creating connection and registering" << dendl;
+ // here is where we decide which of the addrs to connect to. always prefer
+ // the first one, if we support it.
+ entity_addr_t target;
+ for (auto& a : addrs.v) {
+ if (!a.is_msgr2() && !a.is_legacy()) {
+ continue;
+ }
+ // FIXME: for ipv4 vs ipv6, check whether local host can handle ipv6 before
+ // trying it? for now, just pick whichever is listed first.
+ target = a;
+ }
+
// create connection
Worker *w = stack->get_worker();
AsyncConnectionRef conn = new AsyncConnection(cct, this, &dispatch_queue, w,
- addrs.front().is_msgr2());
- conn->connect(addrs, type);
+ target.is_msgr2());
+ conn->connect(addrs, type, target);
assert(!conns.count(addrs));
conns[addrs] = conn;
w->get_perf_counter()->inc(l_msgr_active_connections);