Skip to content

Commit 0dbc9c2

Browse files
authored
Merge pull request #70 from joegasewicz/switch-to-libevent-#68
Switch to libevent #68
2 parents 28a3931 + 377b3f6 commit 0dbc9c2

File tree

14 files changed

+440
-279
lines changed

14 files changed

+440
-279
lines changed

CMakeLists.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ add_executable(forest_mq main.c
88
consumer.h
99
provider.c
1010
provider.h
11-
tcp.c
12-
tcp.h
1311
queue.c
1412
queue.h
1513
exchange.c
1614
exchange.h
1715
config.c
1816
config.h
17+
server.c
18+
server.h
19+
utils.c
20+
utils.h
1921
)
2022

2123
find_package(PkgConfig REQUIRED)
@@ -35,12 +37,8 @@ if (APPLE)
3537
target_include_directories(
3638
forest_mq
3739
PRIVATE
38-
${BREW_ROOT}/Cellar/yder/1.4.20/include
39-
${BREW_ROOT}/Cellar/orcania/2.3.3/include
40-
${BREW_ROOT}/Cellar/libmicrohttpd/1.0.1/include
4140
${BREW_ROOT}/Cellar/jansson/2.14/include
42-
${BREW_ROOT}/Cellar/gnutls/3.8.4/include
43-
${BREW_ROOT}/Cellar/ulfius/2.7.15/include
41+
${BREW_ROOT}/Cellar/libevent/2.1.12_1/include
4442
)
4543
elseif (UNIX)
4644
target_include_directories(
@@ -57,13 +55,14 @@ if (APPLE)
5755
forest_mq
5856
PRIVATE
5957
${BREW_ROOT}/Cellar/jansson/2.14/lib/libjansson.dylib
60-
${BREW_ROOT}/Cellar/ulfius/2.7.15/lib/libulfius.dylib
58+
${BREW_ROOT}/Cellar/libevent/2.1.12_1/lib/libevent.dylib
59+
6160
)
6261
elseif(UNIX)
6362
target_link_libraries(
6463
forest_mq
6564
PRIVATE
6665
jansson
67-
ulfius
66+
event
6867
)
6968
endif ()

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ ENV APPLE = 0
99
ENV UNIX = 1
1010

1111
RUN apt update
12-
RUN apt install -y libulfius-dev uwsc
13-
RUN apt install -y libmicrohttpd-dev
1412
RUN apt install -y libjansson-dev
15-
RUN apt install -y libcurl4-gnutls-dev
16-
RUN apt install -y libgnutls28-dev
17-
RUN apt install -y libgcrypt20-dev
13+
RUN apt install -y libevent-dev
1814
RUN apt install -y libsystemd-dev
1915
RUN apt install -y pkg-config
2016
RUN apt install -y cmake

Makefile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
IMG_NAME=bandnoticeboard/forestmq:0.4.0
1+
IMG_NAME=bandnoticeboard/forestmq:0.5.0
22

33
build:
44
mkdir build
@@ -9,21 +9,17 @@ build:
99
# Development requirements
1010
# This will install all the required development libraries on a Mac.
1111
install_deps_mac:
12-
brew install gnutls
13-
brew install ulfius
1412
brew install check
1513
brew install cmocka
1614
brew install doxygen
15+
brew install jansson
16+
brew install libevent
1717

1818

1919
install_deps_linux:
20-
sudo apt install -y libulfius-dev uwsc
21-
sudo apt install -y libmicrohttpd-dev
2220
sudo apt install -y libjansson-dev
23-
sudo apt install -y ibcurl4-gnutls-dev
24-
sudo apt install -y ibgnutls28-dev
25-
sudo apt install -y ibgcrypt20-dev
26-
sudo apt install -y ibsystemd-dev
21+
sudo apt install -y libsystemd-dev
22+
sudo apt install -y libevent-dev
2723

2824
docs_init:
2925
doxygen -g Doxyfile

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
![ForestMQ](assets/fmq_logo.png?raw=true "ForestMQ")
2-
Message Queue 🌲
2+
Message Queue built on [libevent](https://libevent.org/)
33

44
⚠️ Production ready in v1.0.0
55

@@ -17,14 +17,15 @@ Message Queue 🌲
1717
- Docker ✅
1818
- Daemon ✅
1919
- Topics `TODO`
20-
- MacOS distribution with brew `TODO`
21-
- Linux distribution with snap `TODO`
20+
- MacOS distribution with brew `TODO`*
21+
- Linux distribution with snap `TODO`*
2222
- Message encryption `TODO`
2323

24+
\* *ForestMQ currently only support UNIX like systems.*
2425
### Quick Start
2526
#### Run with Docker
2627
```
27-
docker run -p 8005:8005 bandnoticeboard/forestmq:0.4.0 -d
28+
docker run -p 8005:8005 bandnoticeboard/forestmq:0.5.0
2829
```
2930

3031
Forest MQ is still in very early stages of development, but
@@ -80,6 +81,17 @@ ForestMQ will respond with the following JSON response
8081
```
8182
{"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"}
8283
```
84+
85+
### Security
86+
Currently, ForestMQ provides the following security features
87+
*Users will be able to define their own list of hosts in the next release*
88+
- Only allowed hosts can make requests to any of ForestMQ's endpoints.
89+
- Allowed hosts:
90+
- `localhost`
91+
- `0.0.0.0`
92+
- `127.0.0.1`
93+
94+
8395
### Support
8496
TODO
8597

@@ -88,3 +100,6 @@ TODO
88100

89101
### Contact
90102
TODO
103+
104+
### Acknowledgement
105+
- [libevent](https://libevent.org/)

config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424

2525
/* TCP configs */
2626
#define FMQ_TCP_PORT 8005
27+
#define FMQ_MESSAGE_SIZE 1024
28+
29+
#define FMQ_ALLOWED_HOSTS_LENGTH 20
2730

2831
#endif //CONFIG_H

main.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
#include <unistd.h>
3030
#include <stdbool.h>
3131
#include "config.h"
32-
#include "tcp.h"
3332
#include "queue.h"
33+
#include "server.h"
3434

3535
int main(int argc, char *argv[])
3636
{
37-
u_int16_t msg_size = 1024;
37+
u_int16_t msg_size = FMQ_MESSAGE_SIZE;
3838
u_int16_t port = FMQ_TCP_PORT;
3939
int8_t log_level = FMQ_LOG_LEVEL_NONE;
4040
bool run_as_daemon = false;
@@ -104,8 +104,8 @@ int main(int argc, char *argv[])
104104
}
105105

106106
FMQ_Queue *queue = FMQ_Queue_new(msg_size, log_level);
107-
FMQ_TCP *tcp = FMQ_TCP_new(queue, port, log_level, run_as_daemon);
108-
if (tcp->run_as_daemon)
107+
FMQ_Server *server = FMQ_Server_new(queue, port, log_level, run_as_daemon);
108+
if (server->run_as_daemon)
109109
{
110110
daemon_pid = fork();
111111
if (daemon_pid == -1)
@@ -115,10 +115,10 @@ int main(int argc, char *argv[])
115115
}
116116
if (daemon_pid == 0)
117117
{
118-
const int err = tcp->start(tcp);
119-
if (tcp != NULL)
118+
const int err = server->start(server);
119+
if (server != NULL)
120120
{
121-
free(tcp);
121+
free(server);
122122
}
123123
free(queue);
124124
if (err)
@@ -130,10 +130,10 @@ int main(int argc, char *argv[])
130130
}
131131
else
132132
{
133-
const int err = tcp->start(tcp);
134-
if (tcp != NULL)
133+
const int err = server->start(server);
134+
if (server != NULL)
135135
{
136-
free(tcp);
136+
free(server);
137137
}
138138
free(queue);
139139
if (err)

queue.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ FMQ_QNode *FMQ_QNode_new(void *data)
3333
FMQ_QNode *n = (FMQ_QNode*)malloc(sizeof(FMQ_QNode));
3434
if (n == NULL)
3535
{
36-
printf("Couldn't allocate memory for new node\n");
36+
printf("{queue}: Couldn't allocate memory for new node\n");
3737
exit(EXIT_FAILURE);
3838
}
3939
n->data = data;
@@ -46,7 +46,7 @@ FMQ_Queue *FMQ_Queue_new(const u_int16_t msg_size, const int8_t log_level)
4646
FMQ_Queue *q = (FMQ_Queue*)malloc(sizeof(FMQ_Queue));
4747
if (q == NULL)
4848
{
49-
printf("Couldn't allocate memory for new queue\n");
49+
printf("{queue}: Couldn't allocate memory for new queue\n");
5050
exit(EXIT_FAILURE);
5151
}
5252
q->head = NULL;
@@ -75,8 +75,8 @@ void FMQ_Queue_enqueue(FMQ_Queue *queue, void *data)
7575
}
7676
tmpHeadNode->next = node;
7777
queue->tail = node;
78-
FMQ_LOGGER(queue->log_level, "Queue successfully updated\n"
79-
"Queue size: %d\n", queue->size);
78+
FMQ_LOGGER(queue->log_level, "{queue}: Queue successfully updated\n"
79+
"{queue}: Queue size: %d\n", queue->size);
8080
}
8181

8282
FMQ_QNode *FMQ_Queue_dequeue(FMQ_Queue *queue)
@@ -99,7 +99,7 @@ void FMQ_QUEUE_destroy(FMQ_Queue *queue)
9999
FMQ_QNode *tmpNodePtr;
100100
if (queue->head == NULL)
101101
{
102-
FMQ_LOGGER(queue->log_level, "Cannot destroy a queue that is NULL\n");
102+
FMQ_LOGGER(queue->log_level, "{queue}: Cannot destroy a queue that is NULL\n");
103103
return;
104104
}
105105
tmpNodePtr = queue->head;

queue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ struct FMQ_Queue
4242
char *status;
4343
FMQ_QNode *head;
4444
FMQ_QNode *tail;
45-
u_int16_t msg_size;
46-
int8_t log_level;
45+
uint16_t msg_size;
46+
int8_t log_level;
4747
};
4848

4949
struct FMQ_Data
@@ -54,7 +54,7 @@ struct FMQ_Data
5454
#define FMQ_QUEUE_PEEK(queue) ((queue)->head)
5555
#define FMQ_QUEUE_SIZE(queue) ((queue)->size)
5656
FMQ_QNode *FMQ_QNode_new(void *data);
57-
FMQ_Queue *FMQ_Queue_new(const u_int16_t msg_size, const int8_t log_level);
57+
FMQ_Queue *FMQ_Queue_new(const uint16_t msg_size, const int8_t log_level);
5858
void FMQ_Queue_enqueue(FMQ_Queue *queue, void *data);
5959
FMQ_QNode *FMQ_Queue_dequeue(FMQ_Queue *queue);
6060
void FMQ_QUEUE_destroy(FMQ_Queue *queue);

0 commit comments

Comments
 (0)