Skip to content

Commit

Permalink
Bringing in changes from develop.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-canaday committed Jun 10, 2024
1 parent c2979e6 commit cb3ff40
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/configure_make_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# Dependencies:
#------------------------------------
- name: Checkout libbsat
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: 'andrew-canaday/libbsat'
path: 'libbsat'
Expand All @@ -50,7 +50,7 @@ jobs:
# Checkout, configure, make, run tests, and make dist for libyimmo:
#--------------------------------------------------------------------
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: 'libyimmo'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/create_release_on_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Dependencies:
#------------------------------------
- name: Checkout libbsat
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: 'andrew-canaday/libbsat'
path: 'libbsat'
Expand All @@ -57,7 +57,7 @@ jobs:
# - signing
#--------------------------------------------------------------------
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.repository }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/server-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
IMAGE_NAME: "ghcr.io/${{ github.repository }}-ci:${{ github.ref_name }}"
steps:
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: 'libyimmo'
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
IMAGE_NAME: "ghcr.io/${{ github.repository }}-ci:${{ github.ref_name }}"
steps:
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: 'libyimmo'
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
IMAGE_NAME: "ghcr.io/${{ github.repository }}-ci:${{ github.ref_name }}"
steps:
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: 'libyimmo'
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
IMAGE_NAME: "ghcr.io/${{ github.repository }}-ci:${{ github.ref_name }}"
steps:
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: 'libyimmo'
Expand Down Expand Up @@ -262,7 +262,7 @@ jobs:
IMAGE_NAME: "ghcr.io/${{ github.repository }}-ci:${{ github.ref_name }}"
steps:
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: 'libyimmo'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Dependencies:
#------------------------------------
- name: Checkout libbsat
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: 'andrew-canaday/libbsat'
path: 'libbsat'
Expand All @@ -54,7 +54,7 @@ jobs:
# Build libyimmo:
#--------------------------------------------------------------------
- name: Checkout libyimmo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
path: 'libyimmo'
Expand Down
54 changes: 1 addition & 53 deletions src/core/ymo_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
#include <string.h>
#include <assert.h>

#if YMO_ENABLE_TLS
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif /* YMO_ENABLE_TLS */

#include "yimmo.h"
#include "ymo_log.h"
#include "ymo_conn.h"
Expand Down Expand Up @@ -210,53 +204,7 @@ ymo_status_t ymo_conn_send_buckets(
#if !(YMO_ENABLE_TLS)
return ymo_net_send_buckets(conn->fd, head_p);
#else
/* HACK HACK HACK HACK
* TODO: add ymo_net_send_tls or similar to ymo_net.
*/
ymo_status_t status = YMO_OKAY;

if( !conn->ssl ) {
return ymo_net_send_buckets(conn->fd, head_p);
}

ymo_bucket_t* cur = *head_p;
size_t bytes_sent = 0;

do {
int send_rc = SSL_write_ex(conn->ssl,
(const char*)(cur->data + cur->bytes_sent),
cur->len - cur->bytes_sent,
&bytes_sent);

if( send_rc > 0 ) {
cur->bytes_sent += bytes_sent;

if( cur->bytes_sent < cur->len ) {
status = EAGAIN;
break;
}
ymo_bucket_t* done = cur;
cur = cur->next;
ymo_bucket_free(done);
} else {
int ssl_err = SSL_get_error(conn->ssl, send_rc);
if( YMO_SSL_WANT_RW(ssl_err) ) {
ymo_log_debug("SSL buffering on write to %i", conn->fd);
status = EAGAIN;
break;
} else {
ymo_log_debug(
"SSL write for connection on fd %i "
"failed error code %i: (%s)",
conn->fd, ssl_err, ERR_reason_error_string(ssl_err));
status = ECONNABORTED;
break;
}
}
} while( cur );

*head_p = cur;
return status;
return ymo_net_send_buckets_tls(conn->ssl, conn->fd, head_p);
#endif /* YMO_ENABLE_TLS */
}

Expand Down
60 changes: 60 additions & 0 deletions src/core/ymo_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
#include <sys/uio.h>
#endif /* HAVE_DECL_SENDFILE */

#if YMO_ENABLE_TLS
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif /* YMO_ENABLE_TLS */


#include "yimmo.h"
#include "ymo_util.h"
#include "ymo_log.h"
Expand Down Expand Up @@ -164,6 +171,59 @@ ymo_status_t ymo_net_send_buckets(int fd, ymo_bucket_t** head_p)
}


#if YMO_ENABLE_TLS
/** Send buckets over the wire using TLS. */
ymo_status_t ymo_net_send_buckets_tls(SSL* ssl, int fd, ymo_bucket_t** head)
{
ymo_status_t status = YMO_OKAY;

if( !ssl ) {
return ymo_net_send_buckets(fd, head);
}

ymo_bucket_t* cur = *head;
size_t bytes_sent = 0;

do {
int send_rc = SSL_write_ex(ssl,
(const char*)(cur->data + cur->bytes_sent),
cur->len - cur->bytes_sent,
&bytes_sent);

if( send_rc > 0 ) {
cur->bytes_sent += bytes_sent;

if( cur->bytes_sent < cur->len ) {
status = EAGAIN;
break;
}
ymo_bucket_t* done = cur;
cur = cur->next;
ymo_bucket_free(done);
} else {
int ssl_err = SSL_get_error(ssl, send_rc);
if( YMO_SSL_WANT_RW(ssl_err) ) {
ymo_log_debug("SSL buffering on write to %i", fd);
status = EAGAIN;
break;
} else {
ymo_log_debug(
"SSL write for connection on fd %i "
"failed error code %i: (%s)",
fd, ssl_err, ERR_reason_error_string(ssl_err));
status = ECONNABORTED;
break;
}
}
} while( cur );

*head = cur;
return status;
}


#endif /* YMO_ENABLE_TLS */

#if YMO_BUCKET_FROM_FILE == YMO_BUCKET_SENDFILE
static ymo_status_t ymo_net_bucket_sendfile(int fd, ymo_bucket_t** head_p)
{
Expand Down
12 changes: 12 additions & 0 deletions src/core/ymo_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include <sys/ioctl.h>
#endif /* HAVE_SYS_IOCTL_H */

#if YMO_ENABLE_TLS
#include <openssl/ssl.h>
#endif /* YMO_ENABLE_TLS */


#include "yimmo.h"
#include "ymo_log.h"
#include "ymo_bucket.h"
Expand Down Expand Up @@ -115,6 +120,13 @@
*/
ymo_status_t ymo_net_send_buckets(int fd, ymo_bucket_t** head);

#if YMO_ENABLE_TLS
/** Send a bucket chain over the socket given by ``fd``.
*/
ymo_status_t ymo_net_send_buckets_tls(SSL* ssl, int fd, ymo_bucket_t** head);
#endif /* YMO_ENABLE_TLS */


/**---------------------------------------------------------------
* Socket Trait Functions
*---------------------------------------------------------------*/
Expand Down
4 changes: 1 addition & 3 deletions src/core/ymo_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ const ymo_queue_node_t* ymo_queue_tail(ymo_queue_t* queue)
}


/** Remove an item from the queue:
* TODO: clean up branching
**/
/** Remove an item from the queue: */
ymo_status_t ymo_queue_remove(ymo_queue_t* queue, ymo_queue_node_t** node_ptr)
{
ymo_queue_node_t* node = *node_ptr;
Expand Down
6 changes: 5 additions & 1 deletion src/protocol/http/test/test_hdr_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ static int test_collisions()
}
}

ymo_log_debug("Total collisions: %zu\n", no_collisions);
ymo_log_debug("Total collisions: %zu over the following %zu headers",
no_collisions, no_hdrs);
for( size_t i = 0; i < no_hdrs; i++ ) {
ymo_log_debug(" ✅ %s (%i)", LOTS_OF_HEADERS[i], hdr_ids[i]);
}
ymo_assert(no_collisions == 0);
YMO_TAP_PASS(__func__);
}
Expand Down
21 changes: 15 additions & 6 deletions src/protocol/http/ymo_http_hdr_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ ymo_http_hdr_id_t ymo_http_hdr_hash(
}


#endif /* HAVE_FUNC_ATTRIBUTE_WEAK */
__attribute__((YMO_FUNC_PURE_P weak))
int ymo_http_hdr_cmp(
ymo_http_hdr_table_node_t* current,
const char*hdr,
ymo_http_hdr_id_t h_id)
{
return current->h_id == h_id;
}

/* TODO: allow override for this too / optional strcmp, at least! */
#define YMO_HTTP_HDR_CMP(current, hdr, h_id) \
current->h_id == h_id

#endif /* HAVE_FUNC_ATTRIBUTE_WEAK */

ymo_http_hdr_table_t* ymo_http_hdr_table_create()
{
Expand Down Expand Up @@ -350,8 +356,11 @@ const char* ymo_http_hdr_table_get_id(
ymo_http_hdr_id_t index = h_id % YMO_HDR_TABLE_BUCKET_SIZE;
ymo_http_hdr_table_node_t* current = table->bucket[index];
while( current ) {
/* TODO: compare strings to ensure it's not just hash collision. */
if( YMO_HTTP_HDR_CMP(current, hdr, h_id) ) {
/* TODO: compare strings to ensure it's not just hash collision.
*
* NOTE: this means we probably need to pass in the const char* anyway.
*/
if( YMO_HTTP_HDR_CMP(current, NULL, h_id) ) {
if( !current->buffer ) {
data = current->value;
} else {
Expand Down
Loading

0 comments on commit cb3ff40

Please sign in to comment.