while implementing a process that receives requests from ziti endpoints, forwards the (“de-zitified”) content to an upstream server and sends the response from that interaction back to the requesting ziti endpoint, I ran into an error when the size of the data parameter exceeded 32663 bytes. In those error cases, the client would not receive any data, yet the response/status code from the invocation of ziti-write()
would suggest success. I did not find any errors in the log that seemed relevant.
I arrived at the above number of bytes through trial and error and the lack of error response was definitely unexpected. Is that a known restriction?
In my code I started by essentially copying the on_client_data(ziti_connection clt, uint8_t *data, ssize_t len)
function from sample-host.c
. Are there more conditions to check around the existing ziti session / connection?
FYI, the current (working) code I have is:
ssize_t ngx_ziti_downstream_on_client_data(ziti_connection clt, uint8_t *data, ssize_t len) {
// ZITI_LOG(DEBUG, "--- ngx_ziti_downstream_on_client_data\n");
if (len > 0) {
ZITI_LOG(DEBUG, "client sent %d bytes", (int) len);
ZITI_LOG(TRACE, "client sent these %d bytes:\n%.*s", (int) len, (int) len, data);
// forward request to upstream server
char *reply = malloc(RCV_BUFFER_SIZE);
memset(reply,0,RCV_BUFFER_SIZE);
int reply_len = talk_to_upstream(reply, "odoo.bomk", 8069, len, data);
ZITI_LOG(DEBUG, "response from upstream server is %d bytes long.", reply_len);
ZITI_LOG(TRACE, "response from upstream server %d bytes:\n%.*s", reply_len, reply_len, reply);
/* send the reply via ziti */
int sent = 0;
// int ziti_chunk_len = 32663; //maximum allowed by ziti?
int ziti_chunk_len = 32000;
if (reply_len - sent < ziti_chunk_len){
ziti_chunk_len = reply_len - sent;
}
do {
char *ziti_chunk = malloc(ziti_chunk_len+1);
strncpy(ziti_chunk, reply+sent, ziti_chunk_len);
ZITI_LOG(TRACE, "ziti_chunk to write %d bytes:\n%.*s", ziti_chunk_len, ziti_chunk_len, ziti_chunk);
int rc = ziti_write(clt, (uint8_t *) ziti_chunk, ziti_chunk_len, ngx_ziti_downstream_on_client_write, ziti_chunk);
sent+=ziti_chunk_len;
ZITI_LOG(DEBUG, "ziti_write return code after writing %d of %d bytes: %d", sent, reply_len, rc);
if (reply_len - sent < ziti_chunk_len){
ziti_chunk_len = reply_len - sent;
}
} while (sent < reply_len);
free(reply);
}
else if (len == ZITI_EOF) {
ZITI_LOG(DEBUG, "client disconnected");
ziti_close(clt, NULL);
}
else {
ZITI_LOG(DEBUG, "error: %zd(%s)", len, ziti_errorstr(len));
}
return len;
}
Thanks,
Olaf