|
@@ -27,25 +27,25 @@ func main() {
|
|
|
Hash: "xor:1qaz2wsx3edc",
|
|
Hash: "xor:1qaz2wsx3edc",
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- hub := tinymq.NewHub(cf, localChannel, func(channel string, hostType tinymq.HostType) (hostInfo *tinymq.HostInfo, err error) {
|
|
|
|
|
- return host, nil
|
|
|
|
|
- }, func(client bool, proto string, version uint8, channel string, remoteAuth []byte) (auth []byte) {
|
|
|
|
|
- log.Println("[AuthFunc]", client, proto, version, channel, string(remoteAuth))
|
|
|
|
|
- return []byte("tinymq-client")
|
|
|
|
|
- // 从 remoteAuth 是否为空来判断是否需要返回信息
|
|
|
|
|
- // if len(remoteAuth) <= 0 {
|
|
|
|
|
- // // 客户端调用,返回验证信息
|
|
|
|
|
- // return []byte("tinymq")
|
|
|
|
|
- // } else {
|
|
|
|
|
- // // 服务端调用,返回验证token,或者其他信息
|
|
|
|
|
- // return nil
|
|
|
|
|
- // }
|
|
|
|
|
- }, func(client bool, proto string, version uint8, channel string, auth []byte) bool {
|
|
|
|
|
- log.Println("[CheckAuthFunc]", client, proto, version, channel, string(auth))
|
|
|
|
|
- return string(auth) == "tinymq-server"
|
|
|
|
|
- }, func(conn *tinymq.Line) {
|
|
|
|
|
- log.Println("connect state", conn.Channel(), conn.State(), time.Since(conn.Updated()))
|
|
|
|
|
- }, nil)
|
|
|
|
|
|
|
+ hub := tinymq.NewHub(
|
|
|
|
|
+ cf,
|
|
|
|
|
+ localChannel,
|
|
|
|
|
+ func(channel string, hostType tinymq.HostType) (hostInfo *tinymq.HostInfo, err error) {
|
|
|
|
|
+ return host, nil
|
|
|
|
|
+ },
|
|
|
|
|
+ func(client bool, proto string, version uint8, channel string, remoteAuth []byte) (auth []byte) {
|
|
|
|
|
+ log.Println("[AuthFunc]", client, proto, version, channel, string(remoteAuth))
|
|
|
|
|
+ return []byte("tinymq-client")
|
|
|
|
|
+ },
|
|
|
|
|
+ func(client bool, proto string, version uint8, channel string, auth []byte) bool {
|
|
|
|
|
+ log.Println("[CheckAuthFunc]", client, proto, version, channel, string(auth))
|
|
|
|
|
+ return string(auth) == "tinymq-server"
|
|
|
|
|
+ },
|
|
|
|
|
+ func(conn *tinymq.Line) {
|
|
|
|
|
+ log.Println("connect state", conn.Channel(), conn.State(), time.Since(conn.Updated()))
|
|
|
|
|
+ },
|
|
|
|
|
+ nil,
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
// 订阅频道
|
|
// 订阅频道
|
|
|
hub.Subscribe(remoteFilter, "hello", func(request *tinymq.RequestData) (state uint8, result any) {
|
|
hub.Subscribe(remoteFilter, "hello", func(request *tinymq.RequestData) (state uint8, result any) {
|