Liu Song’s Projects


~/Projects/mochi-mqtt

git clone https://code.lsong.org/mochi-mqtt

Commit

Commit
e60b8ff0c989a3a36dc2b5595d46a160b10eeb2b
Author
mochi-co <[email protected]>
Date
2023-06-14 20:12:52 +0100 +0100
Diffstat
 README.md | 76 +++++++++++++++++++++++++++++---------------------------

Update Hooks List


diff --git a/README.md b/README.md
index ea68731a5080cecc09c0a424cc32328f26ce42dc..d7c3d404affc4880c9e6117e37db2524702fe0a4 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@     - Will Delay Intervals
     - Plus all the original MQTT features of Mochi MQTT v1, such as Full QoS(0,1,2), $SYS topics, retained messages, etc. 
 - Developer-centric:
     - Most core broker code is now exported and accessible, for total developer control.
-    - Full featured and flexible Hook-based interfacing system to provide easy 'plugin' development.
+    - Full-featured and flexible Hook-based interfacing system to provide easy 'plugin' development.
     - Direct Packet Injection using special inline client, or masquerade as existing clients.
 - Performant and Stable:
     - Our classic trie-based Topic-Subscription model.
@@ -277,70 +277,72 @@ The function signatures for all the hooks and `mqtt.Hook` interface can be found in [hooks.go](hooks.go).
 
 > The most flexible event hooks are OnPacketRead, OnPacketEncode, and OnPacketSent - these hooks be used to control and modify all incoming and outgoing packets.
 
+| Function               | Usage                                                                                                                                                                                                                                                                                                      | 
+|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+    - Server-side Disconnect and Auth Packets
 
+| OnStopped              | Called when the server has successfully stopped.                                                                                                                                                                                                                                                           | 
+| OnConnectAuthenticate  | Called when a user attempts to authenticate with the server. An implementation of this method MUST be used to allow or deny access to the server (see hooks/auth/allow_all or basic). It can be used in custom hooks to check connecting users against an existing user database. Returns true if allowed. |
+| OnACLCheck             | Called when a user attempts to publish or subscribe to a topic filter. As above.                                                                                                                                                                                                                           |
+| OnSysInfoTick          | Called when the $SYS topic values are published out.                                                                                                                                                                                                                                                       |
+| OnConnect              | Called when a new client connects, may return an error or packet code to halt the client connection process.                                                                                                                                                                                               | 
+| OnSessionEstablished   | Called when a new client successfully establishes a session (after OnConnect)                                                                                                                                                                                                                              | 
+| OnDisconnect           | Called when a client is disconnected for any reason.                                                                                                                                                                                                                                                       | 
+<p align="center">
 | Listener | Usage |
-
+<p align="center">
 | --- | --- |
-
+<p align="center">
 | listeners.NewTCP | A TCP listener |
-
+<p align="center">
 | listeners.NewUnixSock | A Unix Socket listener |
-
+<p align="center">
 | listeners.NewNet | A net.Listener listener |
-
+<p align="center">
 | listeners.NewWebsocket | A Websocket listener |
-
+<p align="center">
 | listeners.NewHTTPStats | An HTTP $SYS info dashboard |
-
+<p align="center">
 > Use the `listeners.Listener` interface to develop new listeners. If you do, please let us know!
-
+<p align="center">
 A `*listeners.Config` may be passed to configure TLS. 
-
+<p align="center">
 Examples of usage can be found in the [examples](examples) folder or [cmd/main.go](cmd/main.go).
-
+<p align="center">
 ### Server Options and Capabilities
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 <p align="center">
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 ![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 [![Coverage Status](https://coveralls.io/repos/github/mochi-co/mqtt/badge.svg?branch=master&v2)](https://coveralls.io/github/mochi-co/mqtt?branch=master)
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 [![Go Report Card](https://goreportcard.com/badge/github.com/mochi-co/mqtt)](https://goreportcard.com/report/github.com/mochi-co/mqtt/v2)
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 [![Go Reference](https://pkg.go.dev/badge/github.com/mochi-co/mqtt.svg)](https://pkg.go.dev/github.com/mochi-co/mqtt/v2)
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/mochi-co/mqtt/issues)
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 </p>
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 # Mochi MQTT Broker
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 ## The fully compliant, embeddable high-performance Go MQTT v5 (and v3.1.1) broker server 
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 Mochi MQTT is an embeddable [fully compliant](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html) MQTT v5 broker server written in Go, designed for the development of telemetry and internet-of-things projects. The server can be used either as a standalone binary or embedded as a library in your own applications, and has been designed to be as lightweight and fast as possible, with great care taken to ensure the quality and maintainability of the project. 
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 ### What is MQTT?
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 MQTT stands for [MQ Telemetry Transport](https://en.wikipedia.org/wiki/MQTT). It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks ([Learn more](https://mqtt.org/faq)). Mochi MQTT fully implements version 5.0.0 of the MQTT protocol.
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 ## What's new in Version 2.0.0?
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 Version 2.0.0 takes all the great things we loved about Mochi MQTT v1.0.0, learns from the mistakes, and improves on the things we wished we'd had. It's a total from-scratch rewrite, designed to fully implement MQTT v5 as a first-class feature. 
-<p align="center">
+![build status](https://github.com/mochi-co/mqtt/actions/workflows/build.yml/badge.svg) 
 Don't forget to use the new v2 import paths:
-| OnWill | Called when a client disconnects and intends to issue a will message. Allows packet modification. | 
-| OnWillSent | Called when an LWT message has been issued from a disconnecting client. | 
-| OnClientExpired | Called when a client session has expired and should be deleted. | 
-| OnRetainedExpired | Called when a retained message has expired and should be deleted. | 
-| StoredClients |  Returns clients, eg. from a persistent store. | 
-| StoredSubscriptions |  Returns client subscriptions, eg. from a persistent store. | 
-| StoredInflightMessages | Returns inflight messages, eg. from a persistent store.  | 
-| StoredRetainedMessages | Returns retained messages, eg. from a persistent store. | 
-| StoredSysInfo | Returns stored system info values, eg. from a persistent store. | 
 
 If you are building a persistent storage hook, see the existing persistent hooks for inspiration and patterns. If you are building an auth hook, you will need `OnACLCheck` and `OnConnectAuthenticate`.