Skip to content

Commit

Permalink
Defer passing a ConnectionLayer to sshshare.c.
Browse files Browse the repository at this point in the history
This paves the way for me to reorganise ssh.c in a way that will mean
I don't have a ConnectionLayer available yet at the time I have to
create the connshare. The constructor function now takes a mere
Frontend, for generating setup-time Event Log messages, and there's a
separate ssh_connshare_provide_connlayer() function I can call later
once I have the ConnectionLayer to provide.

NFC for the moment: the new provide_connlayer function is called
immediately after ssh_connection_sharing_init.
  • Loading branch information
sgtatham committed Sep 24, 2018
1 parent 54b300f commit a703f86
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
7 changes: 5 additions & 2 deletions ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,8 +1249,11 @@ static const char *connect_to_host(Ssh ssh, const char *host, int port,
ssh->connshare = NULL;
ssh->attempting_connshare = TRUE; /* affects socket logging behaviour */
ssh->s = ssh_connection_sharing_init(
ssh->savedhost, ssh->savedport, ssh->conf, &ssh->cl, &ssh->plugvt,
&ssh->connshare);
ssh->savedhost, ssh->savedport, ssh->conf, ssh->frontend,
&ssh->plugvt, &ssh->connshare);
if (ssh->connshare)
ssh_connshare_provide_connlayer(ssh->connshare, &ssh->cl);

ssh->attempting_connshare = FALSE;
if (ssh->s != NULL) {
/*
Expand Down
4 changes: 3 additions & 1 deletion ssh.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ PktOut *ssh_new_packet(void);
void ssh_free_pktout(PktOut *pkt);

extern Socket ssh_connection_sharing_init(
const char *host, int port, Conf *conf, ConnectionLayer *cl,
const char *host, int port, Conf *conf, Frontend *frontend,
Plug sshplug, ssh_sharing_state **state);
void ssh_connshare_provide_connlayer(ssh_sharing_state *sharestate,
ConnectionLayer *cl);
int ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
void share_got_pkt_from_server(ssh_sharing_connstate *ctx, int type,
const void *pkt, int pktlen);
Expand Down
20 changes: 13 additions & 7 deletions sshshare.c
Original file line number Diff line number Diff line change
Expand Up @@ -2052,6 +2052,12 @@ static const Plug_vtable ssh_sharing_listen_plugvt = {
share_listen_accepting
};

void ssh_connshare_provide_connlayer(ssh_sharing_state *sharestate,
ConnectionLayer *cl)
{
sharestate->cl = cl;
}

/*
* Init function for connection sharing. We either open a listening
* socket and become an upstream, or connect to an existing one and
Expand All @@ -2063,7 +2069,7 @@ static const Plug_vtable ssh_sharing_listen_plugvt = {
* upstream) we return NULL.
*/
Socket ssh_connection_sharing_init(
const char *host, int port, Conf *conf, ConnectionLayer *cl,
const char *host, int port, Conf *conf, Frontend *frontend,
Plug sshplug, ssh_sharing_state **state)
{
int result, can_upstream, can_downstream;
Expand All @@ -2090,6 +2096,7 @@ Socket ssh_connection_sharing_init(
sharestate = snew(struct ssh_sharing_state);
sharestate->plugvt = &ssh_sharing_listen_plugvt;
sharestate->listensock = NULL;
sharestate->cl = NULL;

/*
* Now hand off to a per-platform routine that either connects to
Expand All @@ -2115,16 +2122,16 @@ Socket ssh_connection_sharing_init(
/* For this result, if 'logtext' is not NULL then it is an
* error message indicating a reason why connection sharing
* couldn't be set up _at all_ */
logeventf(cl->frontend,
logeventf(frontend,
"Could not set up connection sharing: %s", logtext);
} else {
/* Failing that, ds_err and us_err indicate why we
* couldn't be a downstream and an upstream respectively */
if (ds_err)
logeventf(cl->frontend, "Could not set up connection sharing"
logeventf(frontend, "Could not set up connection sharing"
" as downstream: %s", ds_err);
if (us_err)
logeventf(cl->frontend, "Could not set up connection sharing"
logeventf(frontend, "Could not set up connection sharing"
" as upstream: %s", us_err);
}

Expand All @@ -2142,7 +2149,7 @@ Socket ssh_connection_sharing_init(
*/

/* 'logtext' is a local endpoint address */
logeventf(cl->frontend,
logeventf(frontend,
"Using existing shared connection at %s", logtext);

*state = NULL;
Expand All @@ -2159,12 +2166,11 @@ Socket ssh_connection_sharing_init(
*/

/* 'logtext' is a local endpoint address */
logeventf(cl->frontend, "Sharing this connection at %s", logtext);
logeventf(frontend, "Sharing this connection at %s", logtext);

*state = sharestate;
sharestate->listensock = sock;
sharestate->connections = newtree234(share_connstate_cmp);
sharestate->cl = cl;
sharestate->server_verstring = NULL;
sharestate->sockname = sockname;
sharestate->nextid = 1;
Expand Down

0 comments on commit a703f86

Please sign in to comment.