mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
sspc: segregate client and proxy states properly
This commit is contained in:
parent
a6a9f22556
commit
3899a416a9
4 changed files with 69 additions and 54 deletions
|
@ -237,16 +237,17 @@ enum {
|
|||
};
|
||||
|
||||
typedef enum {
|
||||
LPCS_WAIT_INITIAL_TX = 1, /* after connect, must send streamtype */
|
||||
LPCS_REPORTING_FAIL, /* stream creation failed, wait to to tell */
|
||||
LPCS_REPORTING_OK, /* stream creation succeeded, wait to to tell */
|
||||
LPCS_OPERATIONAL, /* ready for payloads */
|
||||
LPCS_DESTROYED,
|
||||
LPCSPROX_WAIT_INITIAL_TX = 1, /* after connect, must send streamtype */
|
||||
LPCSPROX_REPORTING_FAIL, /* stream creation failed, wait to to tell */
|
||||
LPCSPROX_REPORTING_OK, /* stream creation succeeded, wait to to tell */
|
||||
LPCSPROX_OPERATIONAL, /* ready for payloads */
|
||||
LPCSPROX_DESTROYED,
|
||||
|
||||
LPCS_SENDING_INITIAL_TX = 1, /* after connect, must send streamtype */
|
||||
LPCS_WAITING_CREATE_RESULT, /* wait to hear if proxy ss create OK */
|
||||
LPCS_LOCAL_CONNECTED, /* we are in touch with the proxy */
|
||||
LPCS_ONWARD_CONNECT, /* request onward ss connection */
|
||||
LPCSCLI_SENDING_INITIAL_TX, /* after connect, must send streamtype */
|
||||
LPCSCLI_WAITING_CREATE_RESULT, /* wait to hear if proxy ss create OK */
|
||||
LPCSCLI_LOCAL_CONNECTED, /* we are in touch with the proxy */
|
||||
LPCSCLI_ONWARD_CONNECT, /* request onward ss connection */
|
||||
LPCSCLI_OPERATIONAL, /* ready for payloads */
|
||||
|
||||
} lws_ss_conn_states_t;
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
return -1;
|
||||
lwsl_info("%s: CONNECTED (%s)\n", __func__, h->ssi.streamtype);
|
||||
|
||||
h->state = LPCS_SENDING_INITIAL_TX;
|
||||
h->state = LPCSCLI_SENDING_INITIAL_TX;
|
||||
h->dsh = lws_dsh_create(NULL, (LWS_PRE + LWS_SS_MTU) * 160, 1);
|
||||
if (!h->dsh)
|
||||
return -1;
|
||||
|
@ -167,8 +167,8 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
(lws_ss_handle_t **)m, &h->ssi, 1))
|
||||
return -1;
|
||||
|
||||
if (wsi && (h->state == LPCS_LOCAL_CONNECTED ||
|
||||
h->state == LPCS_ONWARD_CONNECT))
|
||||
if (wsi && (h->state == LPCSCLI_LOCAL_CONNECTED ||
|
||||
h->state == LPCSCLI_ONWARD_CONNECT))
|
||||
lws_set_timeout(wsi, 0, 0);
|
||||
|
||||
break;
|
||||
|
@ -210,8 +210,16 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
}
|
||||
|
||||
s[1] = 0;
|
||||
/*
|
||||
* This is the state of the link that connects us to the onward
|
||||
* proxy
|
||||
*/
|
||||
switch (h->state) {
|
||||
case LPCS_SENDING_INITIAL_TX:
|
||||
case LPCSCLI_SENDING_INITIAL_TX:
|
||||
/*
|
||||
* We are negotating the opening of a particular
|
||||
* streamtype
|
||||
*/
|
||||
n = strlen(h->ssi.streamtype) + 4;
|
||||
|
||||
s[0] = LWSSS_SER_TXPRE_STREAMTYPE;
|
||||
|
@ -220,12 +228,12 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
//h->txcr_out = txc;
|
||||
lws_strncpy((char *)&s[7], h->ssi.streamtype, sizeof(s) - 7);
|
||||
n += 3;
|
||||
h->state = LPCS_WAITING_CREATE_RESULT;
|
||||
h->state = LPCSCLI_WAITING_CREATE_RESULT;
|
||||
break;
|
||||
|
||||
case LPCS_LOCAL_CONNECTED:
|
||||
if (!h->conn_req)
|
||||
break;
|
||||
case LPCSCLI_LOCAL_CONNECTED:
|
||||
|
||||
lwsl_notice("%s: LPCSCLI_LOCAL_CONNECTED\n", __func__);
|
||||
|
||||
/*
|
||||
* Do we need to prioritize sending any metadata
|
||||
|
|
|
@ -124,7 +124,7 @@ ss_proxy_onward_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf,
|
|||
void *p;
|
||||
size_t si;
|
||||
|
||||
if (!m->conn->ss || m->conn->state != LPCS_OPERATIONAL) {
|
||||
if (!m->conn->ss || m->conn->state != LPCSPROX_OPERATIONAL) {
|
||||
lwsl_notice("%s: ss not ready\n", __func__);
|
||||
*len = 0;
|
||||
|
||||
|
@ -272,7 +272,7 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
}
|
||||
|
||||
pss->conn->wsi = wsi;
|
||||
pss->conn->state = LPCS_WAIT_INITIAL_TX;
|
||||
pss->conn->state = LPCSPROX_WAIT_INITIAL_TX;
|
||||
|
||||
/*
|
||||
* Client is expected to follow the unix domain socket
|
||||
|
@ -312,7 +312,7 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
}
|
||||
|
||||
if (conn->state == LPCS_DESTROYED || !conn->ss) {
|
||||
if (conn->state == LPCSPROX_DESTROYED || !conn->ss) {
|
||||
/*
|
||||
* There's no onward secure stream and our client
|
||||
* connection is closing. Destroy the conn.
|
||||
|
@ -336,7 +336,7 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
// lwsl_hexdump_info(in, len);
|
||||
|
||||
if (conn->state == LPCS_WAIT_INITIAL_TX) {
|
||||
if (conn->state == LPCSPROX_WAIT_INITIAL_TX) {
|
||||
memset(&ssi, 0, sizeof(ssi));
|
||||
ssi.user_alloc = sizeof(ss_proxy_t);
|
||||
ssi.handle_offset = offsetof(ss_proxy_t, ss);
|
||||
|
@ -354,8 +354,8 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (conn->state == LPCS_REPORTING_FAIL ||
|
||||
conn->state == LPCS_REPORTING_OK)
|
||||
if (conn->state == LPCSPROX_REPORTING_FAIL ||
|
||||
conn->state == LPCSPROX_REPORTING_OK)
|
||||
lws_callback_on_writable(conn->wsi);
|
||||
|
||||
break;
|
||||
|
@ -376,10 +376,10 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
s[3] = 0;
|
||||
cp = (const uint8_t *)s;
|
||||
switch (conn->state) {
|
||||
case LPCS_REPORTING_FAIL:
|
||||
case LPCSPROX_REPORTING_FAIL:
|
||||
s[3] = 1;
|
||||
/* fallthru */
|
||||
case LPCS_REPORTING_OK:
|
||||
case LPCSPROX_REPORTING_OK:
|
||||
s[0] = LWSSS_SER_RXPRE_CREATE_RESULT;
|
||||
s[1] = 0;
|
||||
s[2] = 1;
|
||||
|
@ -404,10 +404,10 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
}
|
||||
}
|
||||
s[2] = n - 3;
|
||||
conn->state = LPCS_OPERATIONAL;
|
||||
conn->state = LPCSPROX_OPERATIONAL;
|
||||
lws_set_timeout(wsi, 0, 0);
|
||||
break;
|
||||
case LPCS_OPERATIONAL:
|
||||
case LPCSPROX_OPERATIONAL:
|
||||
if (lws_dsh_get_head(conn->dsh, KIND_SS_TO_P,
|
||||
(void **)&p, &si))
|
||||
break;
|
||||
|
@ -461,9 +461,9 @@ again:
|
|||
}
|
||||
|
||||
switch (conn->state) {
|
||||
case LPCS_REPORTING_FAIL:
|
||||
case LPCSPROX_REPORTING_FAIL:
|
||||
goto hangup;
|
||||
case LPCS_OPERATIONAL:
|
||||
case LPCSPROX_OPERATIONAL:
|
||||
if (pay)
|
||||
lws_dsh_free((void **)&p);
|
||||
if (!lws_dsh_get_head(conn->dsh, KIND_SS_TO_P,
|
||||
|
@ -490,7 +490,7 @@ again:
|
|||
|
||||
hangup:
|
||||
//lws_ss_destroy(&conn->ss);
|
||||
//conn->state = LPCS_DESTROYED;
|
||||
//conn->state = LPCSPROX_DESTROYED;
|
||||
|
||||
/* hang up on him */
|
||||
return -1;
|
||||
|
|
|
@ -87,16 +87,17 @@ typedef enum {
|
|||
static const char *sn[] = {
|
||||
"unset",
|
||||
|
||||
"LPCS_WAIT_INITIAL_TX",
|
||||
"LPCS_REPORTING_FAIL",
|
||||
"LPCS_REPORTING_OK",
|
||||
"LPCS_OPERATIONAL",
|
||||
"LPCS_DESTROYED",
|
||||
"LPCSPROX_WAIT_INITIAL_TX",
|
||||
"LPCSPROX_REPORTING_FAIL",
|
||||
"LPCSPROX_REPORTING_OK",
|
||||
"LPCSPROX_OPERATIONAL",
|
||||
"LPCSPROX_DESTROYED",
|
||||
|
||||
"LPCS_SENDING_INITIAL_TX",
|
||||
"LPCS_WAITING_CREATE_RESULT",
|
||||
"LPCS_LOCAL_CONNECTED",
|
||||
"LPCS_ONWARD_CONNECT",
|
||||
"LPCSCLI_SENDING_INITIAL_TX",
|
||||
"LPCSCLI_WAITING_CREATE_RESULT",
|
||||
"LPCSCLI_LOCAL_CONNECTED",
|
||||
"LPCSCLI_ONWARD_CONNECT",
|
||||
"LPCSCLI_OPERATIONAL",
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -334,7 +335,7 @@ lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par,
|
|||
case LWSSS_SER_TXPRE_TX_PAYLOAD:
|
||||
if (client)
|
||||
goto hangup;
|
||||
if (*state != LPCS_OPERATIONAL)
|
||||
if (*state != LPCSPROX_OPERATIONAL)
|
||||
goto hangup;
|
||||
par->ps = RPAR_FLAG_B3;
|
||||
break;
|
||||
|
@ -349,17 +350,18 @@ lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par,
|
|||
case LWSSS_SER_TXPRE_ONWARD_CONNECT:
|
||||
if (client)
|
||||
goto hangup;
|
||||
if (*state != LPCS_OPERATIONAL)
|
||||
if (*state != LPCSPROX_OPERATIONAL)
|
||||
goto hangup;
|
||||
par->ps = RPAR_TYPE;
|
||||
if (*pss)
|
||||
lwsl_notice("%s: LWSSS_SER_TXPRE_ONWARD_CONNECT\n", __func__);
|
||||
if (*pss && ! (*pss)->wsi)
|
||||
_lws_ss_client_connect(*pss, 0);
|
||||
break;
|
||||
|
||||
case LWSSS_SER_TXPRE_STREAMTYPE:
|
||||
if (client)
|
||||
goto hangup;
|
||||
if (*state != LPCS_WAIT_INITIAL_TX)
|
||||
if (*state != LPCSPROX_WAIT_INITIAL_TX)
|
||||
goto hangup;
|
||||
if (par->rem < 4)
|
||||
goto hangup;
|
||||
|
@ -395,8 +397,8 @@ lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par,
|
|||
case LWSSS_SER_RXPRE_RX_PAYLOAD:
|
||||
if (!client)
|
||||
goto hangup;
|
||||
if (*state != LPCS_OPERATIONAL &&
|
||||
*state != LPCS_LOCAL_CONNECTED)
|
||||
if (*state != LPCSCLI_OPERATIONAL &&
|
||||
*state != LPCSCLI_LOCAL_CONNECTED)
|
||||
goto hangup;
|
||||
|
||||
par->rideshare[0] = '\0';
|
||||
|
@ -406,7 +408,7 @@ lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par,
|
|||
case LWSSS_SER_RXPRE_CREATE_RESULT:
|
||||
if (!client)
|
||||
goto hangup;
|
||||
if (*state != LPCS_WAITING_CREATE_RESULT)
|
||||
if (*state != LPCSCLI_WAITING_CREATE_RESULT)
|
||||
goto hangup;
|
||||
|
||||
if (par->rem < 1)
|
||||
|
@ -418,8 +420,8 @@ lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par,
|
|||
case LWSSS_SER_RXPRE_CONNSTATE:
|
||||
if (!client)
|
||||
goto hangup;
|
||||
if (*state != LPCS_LOCAL_CONNECTED &&
|
||||
*state != LPCS_OPERATIONAL)
|
||||
if (*state != LPCSCLI_LOCAL_CONNECTED &&
|
||||
*state != LPCSCLI_OPERATIONAL)
|
||||
goto hangup;
|
||||
|
||||
if (par->rem < 4)
|
||||
|
@ -828,11 +830,11 @@ payload_ff:
|
|||
*/
|
||||
lwsl_err("%s: create '%s' fail\n",
|
||||
__func__, par->streamtype);
|
||||
*state = LPCS_REPORTING_FAIL;
|
||||
*state = LPCSPROX_REPORTING_FAIL;
|
||||
} else {
|
||||
lwsl_debug("%s: create '%s' OK\n",
|
||||
__func__, par->streamtype);
|
||||
*state = LPCS_REPORTING_OK;
|
||||
*state = LPCSPROX_REPORTING_OK;
|
||||
}
|
||||
|
||||
if (*pss) {
|
||||
|
@ -865,7 +867,7 @@ payload_ff:
|
|||
}
|
||||
|
||||
lws_ss_serialize_state_transition(state,
|
||||
LPCS_LOCAL_CONNECTED);
|
||||
LPCSCLI_LOCAL_CONNECTED);
|
||||
h = lws_container_of(par, lws_sspc_handle_t, parser);
|
||||
if (h->cwsi)
|
||||
lws_callback_on_writable(h->cwsi);
|
||||
|
@ -943,13 +945,17 @@ payload_ff:
|
|||
case LWSSSCS_UNREACHABLE:
|
||||
case LWSSSCS_AUTH_FAILED:
|
||||
lws_ss_serialize_state_transition(state,
|
||||
LPCS_LOCAL_CONNECTED);
|
||||
LPCSCLI_LOCAL_CONNECTED);
|
||||
((lws_sspc_handle_t *)*pss)->conn_req_state =
|
||||
LWSSSPC_ONW_NONE;
|
||||
break;
|
||||
case LWSSSCS_CONNECTED:
|
||||
lwsl_info("%s: CONNECTED %s\n", __func__,
|
||||
ssi->streamtype);
|
||||
lws_ss_serialize_state_transition(state,
|
||||
LPCS_OPERATIONAL);
|
||||
LPCSCLI_OPERATIONAL);
|
||||
((lws_sspc_handle_t *)*pss)->conn_req_state =
|
||||
LWSSSPC_ONW_CONN;
|
||||
break;
|
||||
case LWSSSCS_TIMEOUT:
|
||||
break;
|
||||
|
@ -962,7 +968,7 @@ payload_ff:
|
|||
|
||||
#if defined(_DEBUG)
|
||||
lwsl_info("%s: forwarding proxied state %s\n",
|
||||
__func__, sn[par->ctr]);
|
||||
__func__, lws_ss_state_name(par->ctr));
|
||||
#endif
|
||||
if (ssi->state((void *)pss, NULL, par->ctr, par->flags))
|
||||
goto hangup;
|
||||
|
|
Loading…
Add table
Reference in a new issue