Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ratelimiting rewrite #55

Merged
merged 7 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,26 @@ THIRDP_OBJS = $(THIRDP_DIR)/sha1.o \
$(THIRDP_DIR)/curl-websocket.o \
$(THIRDP_DIR)/threadpool.o \
$(THIRDP_DIR)/priority_queue.o
DISCORD_OBJS = $(SRC_DIR)/concord-once.o \
$(SRC_DIR)/discord-adapter.o \
$(SRC_DIR)/discord-ratelimit.o \
$(SRC_DIR)/discord-client.o \
$(SRC_DIR)/discord-gateway.o \
$(SRC_DIR)/discord-timer.o \
$(SRC_DIR)/discord-misc.o \
$(SRC_DIR)/application_command.o \
$(SRC_DIR)/interaction.o \
$(SRC_DIR)/audit_log.o \
$(SRC_DIR)/channel.o \
$(SRC_DIR)/emoji.o \
$(SRC_DIR)/gateway.o \
$(SRC_DIR)/guild.o \
$(SRC_DIR)/guild_template.o \
$(SRC_DIR)/invite.o \
$(SRC_DIR)/user.o \
$(SRC_DIR)/voice.o \
$(SRC_DIR)/webhook.o \
DISCORD_OBJS = $(SRC_DIR)/concord-once.o \
$(SRC_DIR)/discord-adapter.o \
$(SRC_DIR)/discord-adapter_ratelimit.o \
$(SRC_DIR)/discord-adapter_refcount.o \
$(SRC_DIR)/discord-client.o \
$(SRC_DIR)/discord-gateway.o \
$(SRC_DIR)/discord-timer.o \
$(SRC_DIR)/discord-misc.o \
$(SRC_DIR)/application_command.o \
$(SRC_DIR)/interaction.o \
$(SRC_DIR)/audit_log.o \
$(SRC_DIR)/channel.o \
$(SRC_DIR)/emoji.o \
$(SRC_DIR)/gateway.o \
$(SRC_DIR)/guild.o \
$(SRC_DIR)/guild_template.o \
$(SRC_DIR)/invite.o \
$(SRC_DIR)/user.o \
$(SRC_DIR)/voice.o \
$(SRC_DIR)/webhook.o \
$(XOBJ)

OBJS := $(COGUTILS_OBJS) $(CORE_OBJS) $(THIRDP_OBJS) $(DISCORD_OBJS) \
Expand Down
245 changes: 0 additions & 245 deletions core/third-party/heap-inl.h

This file was deleted.

3 changes: 3 additions & 0 deletions core/third-party/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

typedef void *QUEUE[2];

/* Improve readability by letting user specify underlying type. */
#define QUEUE(type) QUEUE

/* Private macros. */
#define QUEUE_NEXT(q) (*(QUEUE **) &((*(q))[0]))
#define QUEUE_PREV(q) (*(QUEUE **) &((*(q))[1]))
Expand Down
24 changes: 12 additions & 12 deletions core/user-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ struct user_agent {

struct ua_conn_queue {
/** idle connections */
QUEUE idle;
QUEUE(struct ua_conn) idle;
/* busy connections */
QUEUE busy;
QUEUE(struct ua_conn) busy;
/** total amount of created connection handles */
int total;
/** lock for blocking queue operations */
Expand Down Expand Up @@ -408,8 +408,8 @@ _ua_conn_cleanup(struct ua_conn *conn)
struct ua_conn *
ua_conn_start(struct user_agent *ua)
{
QUEUE(struct ua_conn) *qelem = NULL;
struct ua_conn *conn = NULL;
QUEUE *q;

pthread_mutex_lock(&ua->connq->lock);

Expand All @@ -419,10 +419,10 @@ ua_conn_start(struct user_agent *ua)
}
else {
/* remove from idle queue */
q = QUEUE_HEAD(&ua->connq->idle);
QUEUE_REMOVE(q);
qelem = QUEUE_HEAD(&ua->connq->idle);
QUEUE_REMOVE(qelem);

conn = QUEUE_DATA(q, struct ua_conn, entry);
conn = QUEUE_DATA(qelem, struct ua_conn, entry);
}
QUEUE_INSERT_TAIL(&ua->connq->busy, &conn->entry);

Expand Down Expand Up @@ -513,21 +513,21 @@ ua_init(struct ua_attr *attr)
void
ua_cleanup(struct user_agent *ua)
{
QUEUE *ua_queues[] = { &ua->connq->idle, &ua->connq->busy };
QUEUE(struct ua_conn)
* ua_queues[] = { &ua->connq->idle, &ua->connq->busy };
size_t i;

/* cleanup connection queues */
for (i = 0; i < sizeof(ua_queues) / sizeof(QUEUE *); ++i) {
QUEUE(struct ua_conn) queue, *qelem;
struct ua_conn *conn;
QUEUE queue;
QUEUE *q;

QUEUE_MOVE(ua_queues[i], &queue);
while (!QUEUE_EMPTY(&queue)) {
q = QUEUE_HEAD(&queue);
QUEUE_REMOVE(q);
qelem = QUEUE_HEAD(&queue);
QUEUE_REMOVE(qelem);

conn = QUEUE_DATA(q, struct ua_conn, entry);
conn = QUEUE_DATA(qelem, struct ua_conn, entry);
_ua_conn_cleanup(conn);
}
}
Expand Down
Loading