Skip to content

Commit

Permalink
Merge pull request #70 from joegasewicz/switch-to-libevent-#68
Browse files Browse the repository at this point in the history
Switch to libevent #68
  • Loading branch information
joegasewicz authored Oct 9, 2024
2 parents 28a3931 + 377b3f6 commit 0dbc9c2
Show file tree
Hide file tree
Showing 14 changed files with 440 additions and 279 deletions.
17 changes: 8 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ add_executable(forest_mq main.c
consumer.h
provider.c
provider.h
tcp.c
tcp.h
queue.c
queue.h
exchange.c
exchange.h
config.c
config.h
server.c
server.h
utils.c
utils.h
)

find_package(PkgConfig REQUIRED)
Expand All @@ -35,12 +37,8 @@ if (APPLE)
target_include_directories(
forest_mq
PRIVATE
${BREW_ROOT}/Cellar/yder/1.4.20/include
${BREW_ROOT}/Cellar/orcania/2.3.3/include
${BREW_ROOT}/Cellar/libmicrohttpd/1.0.1/include
${BREW_ROOT}/Cellar/jansson/2.14/include
${BREW_ROOT}/Cellar/gnutls/3.8.4/include
${BREW_ROOT}/Cellar/ulfius/2.7.15/include
${BREW_ROOT}/Cellar/libevent/2.1.12_1/include
)
elseif (UNIX)
target_include_directories(
Expand All @@ -57,13 +55,14 @@ if (APPLE)
forest_mq
PRIVATE
${BREW_ROOT}/Cellar/jansson/2.14/lib/libjansson.dylib
${BREW_ROOT}/Cellar/ulfius/2.7.15/lib/libulfius.dylib
${BREW_ROOT}/Cellar/libevent/2.1.12_1/lib/libevent.dylib

)
elseif(UNIX)
target_link_libraries(
forest_mq
PRIVATE
jansson
ulfius
event
)
endif ()
6 changes: 1 addition & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ ENV APPLE = 0
ENV UNIX = 1

RUN apt update
RUN apt install -y libulfius-dev uwsc
RUN apt install -y libmicrohttpd-dev
RUN apt install -y libjansson-dev
RUN apt install -y libcurl4-gnutls-dev
RUN apt install -y libgnutls28-dev
RUN apt install -y libgcrypt20-dev
RUN apt install -y libevent-dev
RUN apt install -y libsystemd-dev
RUN apt install -y pkg-config
RUN apt install -y cmake
Expand Down
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IMG_NAME=bandnoticeboard/forestmq:0.4.0
IMG_NAME=bandnoticeboard/forestmq:0.5.0

build:
mkdir build
Expand All @@ -9,21 +9,17 @@ build:
# Development requirements
# This will install all the required development libraries on a Mac.
install_deps_mac:
brew install gnutls
brew install ulfius
brew install check
brew install cmocka
brew install doxygen
brew install jansson
brew install libevent


install_deps_linux:
sudo apt install -y libulfius-dev uwsc
sudo apt install -y libmicrohttpd-dev
sudo apt install -y libjansson-dev
sudo apt install -y ibcurl4-gnutls-dev
sudo apt install -y ibgnutls28-dev
sudo apt install -y ibgcrypt20-dev
sudo apt install -y ibsystemd-dev
sudo apt install -y libsystemd-dev
sudo apt install -y libevent-dev

docs_init:
doxygen -g Doxyfile
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![ForestMQ](assets/fmq_logo.png?raw=true "ForestMQ")
Message Queue 🌲
Message Queue built on [libevent](https://libevent.org/)

⚠️ Production ready in v1.0.0

Expand All @@ -17,14 +17,15 @@ Message Queue 🌲
- Docker ✅
- Daemon ✅
- Topics `TODO`
- MacOS distribution with brew `TODO`
- Linux distribution with snap `TODO`
- MacOS distribution with brew `TODO`*
- Linux distribution with snap `TODO`*
- Message encryption `TODO`

\* *ForestMQ currently only support UNIX like systems.*
### Quick Start
#### Run with Docker
```
docker run -p 8005:8005 bandnoticeboard/forestmq:0.4.0 -d
docker run -p 8005:8005 bandnoticeboard/forestmq:0.5.0
```

Forest MQ is still in very early stages of development, but
Expand Down Expand Up @@ -80,6 +81,17 @@ ForestMQ will respond with the following JSON response
```
{"queue_empty":true,"queue_length": 0,"status":"OK","request_start":"Sun Jul 28 18:59:44 2024\n","request_end":"Sun Jul 28 18:59:44 2024\n"}
```

### Security
Currently, ForestMQ provides the following security features
*Users will be able to define their own list of hosts in the next release*
- Only allowed hosts can make requests to any of ForestMQ's endpoints.
- Allowed hosts:
- `localhost`
- `0.0.0.0`
- `127.0.0.1`


### Support
TODO

Expand All @@ -88,3 +100,6 @@ TODO

### Contact
TODO

### Acknowledgement
- [libevent](https://libevent.org/)
3 changes: 3 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@

/* TCP configs */
#define FMQ_TCP_PORT 8005
#define FMQ_MESSAGE_SIZE 1024

#define FMQ_ALLOWED_HOSTS_LENGTH 20

#endif //CONFIG_H
20 changes: 10 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
#include <unistd.h>
#include <stdbool.h>
#include "config.h"
#include "tcp.h"
#include "queue.h"
#include "server.h"

int main(int argc, char *argv[])
{
u_int16_t msg_size = 1024;
u_int16_t msg_size = FMQ_MESSAGE_SIZE;
u_int16_t port = FMQ_TCP_PORT;
int8_t log_level = FMQ_LOG_LEVEL_NONE;
bool run_as_daemon = false;
Expand Down Expand Up @@ -104,8 +104,8 @@ int main(int argc, char *argv[])
}

FMQ_Queue *queue = FMQ_Queue_new(msg_size, log_level);
FMQ_TCP *tcp = FMQ_TCP_new(queue, port, log_level, run_as_daemon);
if (tcp->run_as_daemon)
FMQ_Server *server = FMQ_Server_new(queue, port, log_level, run_as_daemon);
if (server->run_as_daemon)
{
daemon_pid = fork();
if (daemon_pid == -1)
Expand All @@ -115,10 +115,10 @@ int main(int argc, char *argv[])
}
if (daemon_pid == 0)
{
const int err = tcp->start(tcp);
if (tcp != NULL)
const int err = server->start(server);
if (server != NULL)
{
free(tcp);
free(server);
}
free(queue);
if (err)
Expand All @@ -130,10 +130,10 @@ int main(int argc, char *argv[])
}
else
{
const int err = tcp->start(tcp);
if (tcp != NULL)
const int err = server->start(server);
if (server != NULL)
{
free(tcp);
free(server);
}
free(queue);
if (err)
Expand Down
10 changes: 5 additions & 5 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ FMQ_QNode *FMQ_QNode_new(void *data)
FMQ_QNode *n = (FMQ_QNode*)malloc(sizeof(FMQ_QNode));
if (n == NULL)
{
printf("Couldn't allocate memory for new node\n");
printf("{queue}: Couldn't allocate memory for new node\n");
exit(EXIT_FAILURE);
}
n->data = data;
Expand All @@ -46,7 +46,7 @@ FMQ_Queue *FMQ_Queue_new(const u_int16_t msg_size, const int8_t log_level)
FMQ_Queue *q = (FMQ_Queue*)malloc(sizeof(FMQ_Queue));
if (q == NULL)
{
printf("Couldn't allocate memory for new queue\n");
printf("{queue}: Couldn't allocate memory for new queue\n");
exit(EXIT_FAILURE);
}
q->head = NULL;
Expand Down Expand Up @@ -75,8 +75,8 @@ void FMQ_Queue_enqueue(FMQ_Queue *queue, void *data)
}
tmpHeadNode->next = node;
queue->tail = node;
FMQ_LOGGER(queue->log_level, "Queue successfully updated\n"
"Queue size: %d\n", queue->size);
FMQ_LOGGER(queue->log_level, "{queue}: Queue successfully updated\n"
"{queue}: Queue size: %d\n", queue->size);
}

FMQ_QNode *FMQ_Queue_dequeue(FMQ_Queue *queue)
Expand All @@ -99,7 +99,7 @@ void FMQ_QUEUE_destroy(FMQ_Queue *queue)
FMQ_QNode *tmpNodePtr;
if (queue->head == NULL)
{
FMQ_LOGGER(queue->log_level, "Cannot destroy a queue that is NULL\n");
FMQ_LOGGER(queue->log_level, "{queue}: Cannot destroy a queue that is NULL\n");
return;
}
tmpNodePtr = queue->head;
Expand Down
6 changes: 3 additions & 3 deletions queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct FMQ_Queue
char *status;
FMQ_QNode *head;
FMQ_QNode *tail;
u_int16_t msg_size;
int8_t log_level;
uint16_t msg_size;
int8_t log_level;
};

struct FMQ_Data
Expand All @@ -54,7 +54,7 @@ struct FMQ_Data
#define FMQ_QUEUE_PEEK(queue) ((queue)->head)
#define FMQ_QUEUE_SIZE(queue) ((queue)->size)
FMQ_QNode *FMQ_QNode_new(void *data);
FMQ_Queue *FMQ_Queue_new(const u_int16_t msg_size, const int8_t log_level);
FMQ_Queue *FMQ_Queue_new(const uint16_t msg_size, const int8_t log_level);
void FMQ_Queue_enqueue(FMQ_Queue *queue, void *data);
FMQ_QNode *FMQ_Queue_dequeue(FMQ_Queue *queue);
void FMQ_QUEUE_destroy(FMQ_Queue *queue);
Expand Down
Loading

0 comments on commit 0dbc9c2

Please sign in to comment.