| 1 |
# Handlers |
| 2 |
|
| 3 |
## Query Processing |
| 4 |
|
| 5 |
Once atomdns has been started and has parsed the configuration, it runs a server with handlers chains. |
| 6 |
Each handler chain is tied to a set of zones it serves. |
| 7 |
|
| 8 |
When a query is being processed by atomdns, the following steps are performed: |
| 9 |
|
| 10 |
- It will check which one has the most specific zone for this query (longest suffix match). E.g. if there are |
| 11 |
two handler chains, one for example.org and one for a.example.org, and the query is for www.a.example.org, it |
| 12 |
will be routed to the latter. |
| 13 |
|
| 14 |
- Once a handler chains has been found, it will be routed through that chain. This happens in the order as |
| 15 |
defined in the configuration file (atomdns-conffile(5)). |
| 16 |
|
| 17 |
- Each handler in the chain will inspect the query and determine if it should process it. A couple of things |
| 18 |
can now happen: |
| 19 |
1. The query is processed by this handler.. |
| 20 |
2. The query is not processed by this handler. |
| 21 |
3. The query is processed by this handler, but it decides it needs to call the next handler. |
| 22 |
4. The query is processed by this handler, a key/value (see [dnsctx])is added to the context and the next |
| 23 |
handler is called. |
| 24 |
|
| 25 |
Processing a query means a handler will respond to the client with a reply. |
| 26 |
|
| 27 |
Note that a handler is free to deviate from the above list as it wishes. Currently, all handlers that come |
| 28 |
with atomdns fall into one of these four groups though. |
| 29 |
|
| 30 |
## Logging |
| 31 |
|
| 32 |
Each handler has a generated `zerr.go` file that defines a log function. This function should be used when |
| 33 |
logging from within the handler, this uses the standard library `log/slog` package: |
| 34 |
|
| 35 |
```go |
| 36 |
alog := log().With(slog.String("path", filepath.Base(d.Path))) |
| 37 |
alog.Error("Failed to reload", Err(err)) |
| 38 |
// or |
| 39 |
alog.Info("Successful reload") |
| 40 |
``` |
| 41 |
|
| 42 |
## Adding a New Handler |
| 43 |
|
| 44 |
There are some minimum requirements before a handler can be added to the main source tree. |
| 45 |
It basically boils down to: "it should add something unique and useful to atomdns". Furthermore documentation, |
| 46 |
tests and functionality should all be excellent. |
| 47 |
|
| 48 |
It is easier to list when a handler can be included in atomdns than to say it should stay external, so: |
| 49 |
|
| 50 |
- First, the handler should be useful for other people. "Useful" is a subjective term, but the handler needs to |
| 51 |
fill a niche that appeals to more than one person. |
| 52 |
- It should be sufficiently different from other handlers. |
| 53 |
- Current internet standards need be supported: IPv4 and IPv6 are minimally required. |
| 54 |
- It must have tests. |
| 55 |
- It must have a README.md for documentation. |
| 56 |
- Care must be taken to make it efficient in both memory and CPU. |