1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Log when a network connection succeeds.

Now I've got an enum for PlugLogType, it's easier to add things to it.
We were giving a blow-by-blow account of each connection attempt, and
when it failed, saying what went wrong before we moved on to the next
candidate address, but when one finally succeeded, we never logged
_that_. Now we do.
This commit is contained in:
Simon Tatham 2020-02-07 19:18:50 +00:00
parent 91bb475087
commit 630cac3aa2
5 changed files with 33 additions and 5 deletions

View File

@ -28,6 +28,10 @@ void backend_socket_log(Seat *seat, LogContext *logctx,
sk_getaddr(addr, addrbuf, lenof(addrbuf)); sk_getaddr(addr, addrbuf, lenof(addrbuf));
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg); msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
break; break;
case PLUGLOG_CONNECT_SUCCESS:
sk_getaddr(addr, addrbuf, lenof(addrbuf));
msg = dupprintf("Connected to %s", addrbuf);
break;
case PLUGLOG_PROXY_MSG: case PLUGLOG_PROXY_MSG:
/* Proxy-related log messages have their own identifying /* Proxy-related log messages have their own identifying
* prefix already, put on by our caller. */ * prefix already, put on by our caller. */

View File

@ -47,6 +47,7 @@ struct Plug {
typedef enum PlugLogType { typedef enum PlugLogType {
PLUGLOG_CONNECT_TRYING, PLUGLOG_CONNECT_TRYING,
PLUGLOG_CONNECT_FAILED, PLUGLOG_CONNECT_FAILED,
PLUGLOG_CONNECT_SUCCESS,
PLUGLOG_PROXY_MSG, PLUGLOG_PROXY_MSG,
} PlugLogType; } PlugLogType;
@ -66,6 +67,9 @@ struct PlugVtable {
* addresses to fall back to. When it _is_ fatal, the closing() * addresses to fall back to. When it _is_ fatal, the closing()
* function will be called. * function will be called.
* *
* - PLUGLOG_CONNECT_SUCCESS means we have succeeded in
* connecting to address `addr'.
*
* - PLUGLOG_PROXY_MSG means that error_msg contains a line of * - PLUGLOG_PROXY_MSG means that error_msg contains a line of
* logging information from whatever the connection is being * logging information from whatever the connection is being
* proxied through. This will typically be a wodge of * proxied through. This will typically be a wodge of

View File

@ -7,8 +7,8 @@
#include "putty.h" #include "putty.h"
static void nullplug_socket_log(Plug *plug, int type, SockAddr *addr, int port, static void nullplug_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
const char *error_msg, int error_code) int port, const char *err_msg, int err_code)
{ {
} }

View File

@ -733,6 +733,10 @@ static int try_connect(NetSocket *sock)
*/ */
sock->connected = true; sock->connected = true;
sock->writable = true; sock->writable = true;
SockAddr thisaddr = sk_extractaddr_tmp(sock->addr, &sock->step);
plug_log(sock->plug, PLUGLOG_CONNECT_SUCCESS,
&thisaddr, sock->port, NULL, 0);
} }
uxsel_tell(sock); uxsel_tell(sock);
@ -1435,6 +1439,13 @@ static void net_select_result(int fd, int event)
} }
if (!s->connected) if (!s->connected)
return; /* another async attempt in progress */ return; /* another async attempt in progress */
} else {
/*
* The connection attempt succeeded.
*/
SockAddr thisaddr = sk_extractaddr_tmp(s->addr, &s->step);
plug_log(s->plug, PLUGLOG_CONNECT_SUCCESS,
&thisaddr, s->port, NULL, 0);
} }
} }

View File

@ -1068,6 +1068,9 @@ static DWORD try_connect(NetSocket *sock)
* and we should set the socket as writable. * and we should set the socket as writable.
*/ */
sock->writable = true; sock->writable = true;
SockAddr thisaddr = sk_extractaddr_tmp(sock->addr, &sock->step);
plug_log(sock->plug, PLUGLOG_CONNECT_SUCCESS,
&thisaddr, sock->port, NULL, 0);
} }
err = 0; err = 0;
@ -1546,12 +1549,18 @@ void select_result(WPARAM wParam, LPARAM lParam)
case FD_CONNECT: case FD_CONNECT:
s->connected = true; s->connected = true;
s->writable = true; s->writable = true;
/* /*
* Once a socket is connected, we can stop falling * Once a socket is connected, we can stop falling back
* back through the candidate addresses to connect * through the candidate addresses to connect to. But first,
* to. * let the plug know we were successful.
*/ */
if (s->addr) { if (s->addr) {
SockAddr thisaddr = sk_extractaddr_tmp(
s->addr, &s->step);
plug_log(s->plug, PLUGLOG_CONNECT_SUCCESS,
&thisaddr, s->port, NULL, 0);
sk_addr_free(s->addr); sk_addr_free(s->addr);
s->addr = NULL; s->addr = NULL;
} }