@@ -237,6 +237,9 @@ class OutboundMode {
237237 this ->pacer_ .delay_ms ());
238238 // The next connection may be to a different server, so it is owed its own look.
239239 this ->remembered_this_connection_ = false ;
240+ // Whatever the last dial produced -- or failed to produce -- went with the
241+ // connection, so its URL must not describe whatever connects next.
242+ this ->last_dial_ .note_lost ();
240243 }
241244 // Covers an inbound connection too: a server that dialled us first is a connection,
242245 // and dialling out over the top of it would only fight with it.
@@ -249,8 +252,9 @@ class OutboundMode {
249252 }
250253
251254 std::string url;
255+ std::string server_id;
252256 if (this ->opts_ .discover ) {
253- if (!this ->choose (url)) {
257+ if (!this ->choose (url, server_id )) {
254258 return ;
255259 }
256260 } else {
@@ -262,25 +266,29 @@ class OutboundMode {
262266 // Stamped before the dial rather than after, so the backoff measures from when the
263267 // attempt started -- which is the whole point of pacing from the dial.
264268 this ->pacer_ .note_dial (now_ms);
265- this ->dialed_url_ = url;
269+ this ->last_dial_ . note_dial ( url, server_id) ;
266270 client.connect_to (url);
267271 }
268272
269- // / The URL this run last dialled, empty before the first dial. What the stream hooks
270- // / export as SENDSPIN_SERVER_URL .
273+ // / The URL to export as SENDSPIN_SERVER_URL for a stream arriving from `server_id`,
274+ // / empty when no dial of this run's plausibly produced that connection .
271275 // /
272- // / What was dialled, not what answered, and the two can differ: -s leaves the inbound
273- // / listener up, so a server that dialled in while an attempt of ours was outstanding or
274- // / had failed is a connection this cannot tell from its own. Telling them apart needs the
275- // / library to say where the live connection came from, which it does not -- there is no
276- // / connect callback, and nothing exposes a connection's URL or its direction.
277- const std::string& dialed_url () const {
278- return this ->dialed_url_ ;
276+ // / What was dialled, never a claim about what answered: a lost connection forgets the
277+ // / dial, and a discovery dial is answered only for the server_id it dialled. A literal
278+ // / -s URL is the case that cannot be verified -- -s leaves the inbound listener up, and
279+ // / telling an inbound connection from our own needs the library to say where the live
280+ // / connection came from, which it does not: there is no connect callback, and nothing
281+ // / exposes a connection's URL or its direction.
282+ std::string url_for (const std::string& server_id) const {
283+ return this ->last_dial_ .url_for (server_id);
279284 }
280285
281286private:
282287 // / Picks a discovered server, or reports that there is nothing to dial yet.
283- bool choose (std::string& url) {
288+ // /
289+ // / `server_id` is the chosen instance label, which is the protocol server_id -- the
290+ // / equality the remembered-server preference already stands on.
291+ bool choose (std::string& url, std::string& server_id) {
284292 const std::vector<DiscoveredServer> servers = this ->mdns_ .servers ();
285293 std::string reason;
286294 const DiscoveredServer* chosen =
@@ -293,6 +301,7 @@ class OutboundMode {
293301 // Discovery already said why, at debug, when the instance first resolved.
294302 return false ;
295303 }
304+ server_id = chosen->instance ;
296305 // A discovered URL has no userinfo to hide -- discovered_server_url() builds it from a
297306 // resolved address and a TXT path it requires to start with '/', so the authority is
298307 // always just that address. It goes through the helper anyway so that both "Connecting
@@ -342,7 +351,7 @@ class OutboundMode {
342351 MdnsService& mdns_;
343352 StateStore& store_;
344353 std::string remembered_;
345- std::string dialed_url_ ;
354+ LastDial last_dial_ ;
346355 bool remembered_this_connection_{false };
347356 RetryPacer pacer_;
348357};
@@ -951,7 +960,7 @@ int main(int argc, char* argv[]) {
951960 stream_context.server_name = info->name ;
952961 }
953962 if (outbound) {
954- stream_context.server_url = outbound->dialed_url ( );
963+ stream_context.server_url = outbound->url_for (stream_context. server_id );
955964 }
956965 }
957966 const std::string& command = started ? opts.hook_start : opts.hook_stop ;
0 commit comments