Skip to content

thinkty/bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bridge

screenshot

Bridge is a simple topic-based pub/sub broker on top of TCP with a very simple application protocol. It uses ncurses for the terminal UI. It utilizes linear probing hash map (defined in table.h) to insert/remove the topics, subscribe/unsubscribe new connections. It is built on a TCP server that handles new connections in new threads.

This is just a personal project and has a lot of limitations (which could be future plans?). Some of the limits that I can think of at the moment are:

  • Spawning threads on new connection (instead of pool of threads)
  • No encryption or integrity checks
  • QoS level 0 (send at most once and if an error occurs, just unsubscribe)
  • Not so interactive UI (only able to move in the table)
  • Memory leaks (valgrind) within ncurses itself but this seems like a different issue
  • No options to set port, connections, etc.

Install

Clone or download the repository and run make to create the executable bridge.

Protocol

This is a pub/sub protocol based on TCP with focus on simplicity and readability. Every scenario begins with the 1 byte of command to indicate operation.

Subscribe

For subscribing to a new topic, the command has to be S, followed by 7 bytes to specify the topic.

Command (1 byte) | Topic (7 bytes)

Unsubscribe

For unsubscribing to a topic, the command has to be U, followed by 7 bytes to specify the topic to unsubscribe.

Command (1 byte) | Topic (7 bytes)

Publish

For publishing to a topic, the command has to be P, followed by 7 bytes to specify the topic to publish to. Then it is followed by variable length of data and finish with an EOF to indicate the end.

Command (1 byte) | Topic (7 bytes) | Data (variable length)

After the broker receives the publish data, it chunks into an arbitrary length and propagates it to the subscribed hosts. For the hosts receiving the published data, the format will be as follows (unsigned short indicating size and bytes of data at maximum 128 bytes).

Length (2 bytes) | Data (at maximum 128 bytes)

To indicate the end of stream, it will be followed by two carriage-return|new-line similar to HTTP.

License

MIT

About

A simple pub/sub broker

Resources

License

Stars

Watchers

Forks