Skip to content

zlxqur/sol

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sol

Oversimplified MQTT broker written from scratch, which mimic mosquitto features. Implemented to learning how the protocol works, for now it supports almost all MQTT v3.1.1 commands on linux platform; it relies on EPOLL interface for multiplexing I/O. Development process is documented in this series of posts. Not for production use.

Build

$ cmake .
$ make

Quickstart play

The broker can be tested using mosquitto_sub and mosquitto_pub or with paho-mqtt python driver.

To run the broker with DEBUG logging on:

$ ./sol -v

A simple configuration can be passed in with -c flag:

$ ./sol -c path/to/sol.conf

As of now the configuration is very small and it's possible to set some of the most common parameters, default path is located to /etc/sol/sol.conf:

# Sol configuration file, uncomment and edit desired configuration

# Network configuration

# Uncomment ip_address and ip_port to set socket family to TCP, if unix_socket
# is set, UNIX family socket will be used

# ip_address 127.0.0.1
# ip_port 9090

unix_socket /tmp/sol.sock

# Logging configuration

# Could be either DEBUG, INFO/INFORMATION, WARNING, ERROR
log_level DEBUG

log_path /tmp/sol.log

# Max memory to be used, after which the system starts to reclaim memory by
# freeing older items stored
max_memory 2GB

# Max memory that will be allocated for each request
max_request_size 2MB

# TCP backlog, size of the complete connection queue
tcp_backlog 128

# Interval of time between one stats publish on $SOL topics and the subsequent
stats_publish_interval 10s

# SSL certs paths, certfile act as a flag as well to set TLS/SSL ON
certfile /etc/sol/certs/cert.pem

keyfile /etc/sol/certs/key.pem

# Authentication
allow_anonymous false
password_file /etc/sol/passwd

If allow_anonymous if false, a password file have to be specyfied. The password file follow the standard format of username:password line by line. To generate one just add all entries needed in a file and run passwd.py after it:

$ cat sample_passwd_file
user1:pass1
user2:pass2
$ python passwd.py sample_passwd_file
$ cat sample_passwd_file
user1:$6$69qVAELLWuKXWQPQ$oO7lP/hNS4WPABTyK4nkJs4bcRLYFi365YX13cEc/QBJtQgqf2d5rOIUdqoUin.YVGXC3OXY9MSz7Z66ZDkCW/
user2:$6$vtHdafhGhxpXwgBa$Y3Etz8koC1YPSYhXpTnhz.2vJTZvCUGk3xUdjyLr9z9XgE8asNwfYDRLIKN4Apz48KKwKz0YntjHsPRiE6r3g/

Features roadmap

It's still a work in progress but it already handles the most of the basic features expected from an MQTT broker.

  • Unix/TCP sockets
  • Pub/Sub working fine
  • QoS 0, 1, 2 are correctly parsed, 0 and 1 handled as well
  • Retained messages
  • Trie as underlying structure to handle topic hierarchies
  • Periodic tasks like stats publishing
  • Wildcards (#) on subscriptions
  • Wildcards (+) on subscriptions
  • QoS 2 tracking of pending clients and re-send
  • Session present check and handling
  • Authentication
  • SSL/TLS connections
  • Last will & Testament
  • Check on max memory used

It apparently not leak memory as of now, there's probably some corner cases, not deeply investigated yet.

Contributing

Pull requests are welcome, just create an issue and fork it.

About

Lightweight MQTT broker, written from scratch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 94.3%
  • Python 4.2%
  • Other 1.5%