Browse Source

developing: Add ResponseBuffer explanation

tags/v0.11.0-beta
Daniel Oaks 6 years ago
parent
commit
fcd0a75469
1 changed files with 20 additions and 0 deletions
  1. 20
    0
      DEVELOPING.md

+ 20
- 0
DEVELOPING.md View File

@@ -99,3 +99,23 @@ In consequence, there is a lot of state (in particular, server and channel state
99 99
 There are some mutexes that are "tier 0": anything in a subpackage of `irc` (e.g., `irc/logger` or `irc/connection_limits`) shouldn't acquire mutexes defined in `irc`.
100 100
 
101 101
 We are using `buntdb` for persistence; a `buntdb.DB` has an `RWMutex` inside it, with read-write transactions getting the `Lock()` and read-only transactions getting the `RLock()`. We haven't completely decided where this lock fits into the overall lock model. For now, it's probably better to err on the side of caution: if possible, don't acquire new locks inside the `buntdb` transaction, and be careful about what locks are held around the transaction as well.
102
+
103
+## Command handlers and ResponseBuffer
104
+
105
+We support a lot of IRCv3 specs. Pretty much all of them, in fact. And a lot of proposed/draft ones. One of the draft specifications that we support is called ["labeled responses"](https://ircv3.net/specs/extensions/labeled-response.html).
106
+
107
+With labeled responses, when a client sends a label along with their command, they are assured that they will receive the response messages with that same label.
108
+
109
+For example, if the client sends this to the server:
110
+
111
+    @label=pQraCjj82e PRIVMSG #channel :hi!
112
+
113
+They will expect to receive this (with echo-message also enabled):
114
+
115
+    @label=pQraCjj82e :nick!user@host PRIVMSG #channel :hi!
116
+
117
+They receive the response with the same label, so they can match the sent command to the received response. They can also do the same with any other command.
118
+
119
+In order to allow this, in command handlers we don't send responses directly back to the user. Instead, we buffer the responses in an object called a ResponseBuffer. When the command handler returns, the contents of the ResponseBuffer is sent to the user with the appropriate label (and batches, if they're required).
120
+
121
+Basically, if you're in a command handler and you're sending a response back to the requesting client, use `rb.Add*` instead of `client.Send*`. Doing this makes sure the labeled responses feature above works as expected. The handling around `PRIVMSG`/`NOTICE`/`TAGMSG` is strange, so simply defer to [irctest](https://github.com/DanielOaks/irctest)'s judgement about whether that's correct for the most part.

Loading…
Cancel
Save