Skip to content

Instantly share code, notes, and snippets.

@tjstebbing
Last active November 10, 2018 08:41
Show Gist options
  • Select an option

  • Save tjstebbing/8ebd6a4d6fa16159cb9f98a17ea67ec7 to your computer and use it in GitHub Desktop.

Select an option

Save tjstebbing/8ebd6a4d6fa16159cb9f98a17ea67ec7 to your computer and use it in GitHub Desktop.

๐Ÿš MINI BUS

Mini Bus is a drastically simplified version of D-BUS, specifically for plain text communication between terminal UIs / shell scripts and terminal multiplexers.

minibusd

Minibus daemon monitors /tmp/minibus for newly created UNIX Domain sockets (SOCK_STREAM) and connects to them based on their location:

/tmp/minibus/<channel>/in/*

minibusd connects to any IN sockets and listens for data

/tmp/minibus/<channel>/out/*

minibusd connects to any OUT sockets and sequentially publishes data recieved from any IN socket for this channel.

Protocol

The minibus protocol is ridiculously simple, each message is \n\n terminated, further protocol layers are at the discretion of both sender and reciever.

@raffecat

raffecat commented Nov 8, 2018

Copy link
Copy Markdown

So it's a pub-sub mechanism?

How will you handle text encoding? Traditionally each terminal has its own active text-encoding. It might be enough to say all protocols must use UTF-8, or it's up to the protocol as long as '\n' is encoded as a single byte 0x0A in the protocol's encoding.

Edit: this is so mini-bus can recognise the message boundaries, regardless of the text-encoding being sent across the bus.

@raffecat

raffecat commented Nov 8, 2018

Copy link
Copy Markdown

I guess the points to think about are the edge cases:

  • When you place your in socket in the dir, how long does it take mini-bus to notice (i.e. how long do you have to sleep for?)
  • Likewise when you put your socket in the out dir.
  • Also, how do you catch up after you've put your socket in the out dir? (i.e. catch up on the messages you've missed so far)

Edit: these are questions about timing when you first connect - how long do you have to wait after you create your listening out socket, before you are guaranteed to start receiving new messages, so you won't miss any that you provoke from following commands in your script.

@tjstebbing

Copy link
Copy Markdown
Author

If it were a single SOCK_STREAM (bi-directional) with connection signaled to the other side, some of these would be elevated. I considered TLV or just length prefix but thought: this is something that needs to support echo '{"foo":123}\n\n' | nc -U /file/name from a shell script for ease of use so counting bytes etc would be to much of a burden for your average shell scripter?

@raffecat

raffecat commented Nov 10, 2018

Copy link
Copy Markdown

I'm not sure I follow. Using '\n\n' between messages seems fine?
(as long as mini-bus never sends half a message, i.e. newly arrived sockets start receiving on the next message boundary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment