feat: 接线 serve 真实 auth/注册/管理/MQTT 与消息循环

This commit is contained in:
Nixevol
2026-09-30 07:56:25 +08:00
parent 550ed534e4
commit 0efcfbb8b6
9 changed files with 699 additions and 80 deletions
+7
View File
@@ -58,11 +58,16 @@ func (AllowAuthenticator) Authenticate(context.Context, string, []byte, string)
return AuthResult{OK: true}, nil
}
// PublishDroppedFunc 下行未写入发送队列时回调(对接消息线 OnPublishDropped)。
type PublishDroppedFunc func(ctx context.Context, endpointID string, connID port.ConnID, payload []byte)
// Options 装配 broker。
type Options struct {
Authenticator Authenticator
Uplink port.UplinkHandler
Logger *slog.Logger
// OnPublishDropped 可选;nil 时仅打 debug 日志。
OnPublishDropped PublishDroppedFunc
}
// Broker 内置 mochi,不自带监听端口。
@@ -71,6 +76,7 @@ type Broker struct {
auth Authenticator
uplink port.UplinkHandler
log *slog.Logger
onDrop PublishDroppedFunc
hook *nixHook
@@ -144,6 +150,7 @@ func New(opts Options) (*Broker, error) {
auth: auth,
uplink: uplink,
log: log,
onDrop: opts.OnPublishDropped,
current: make(map[string]*connState),
byClient: make(map[*mqtt.Client]*connState),
queues: make(map[string]*uplinkQueue),