Comments (11)
@leijux If I understand correctly, you want to add some special tags while parsing the packet, so that you can filter them based on these tags during packet processing, right?
If that's the case, I suggest you store your own tag information here in cl.Properties.Props.User
, where you can save some Key-Value data for those users you want to filter.
from server.
@leijux If I understand correctly, you want to add some special tags while parsing the packet, so that you can filter them based on these tags during packet processing, right?
If that's the case, I suggest you store your own tag information here in
cl.Properties.Props.User
, where you can save some Key-Value data for those users you want to filter.
用户属性可以作为筛选条件,但是我不知道如何在数据包转发阶段对转发行为进行控制。如下图,主题中有三个客户端,我只想将数据发送给其中的某个客户端,我当前的实现是使用 OnPacketEncode hook 函数,将 包的 FixedHeader.Type 设置为无效的类型,让数据包无法转发出去,但是这样会引发 error 错误,有没有更好的办法,感谢。
from server.
@leijux 你这种的话,实现hook.OnACLCheck就行了,OnACLCheck会在发送给每个订阅者之前进行鉴权。
In your case, you can implement hook.OnACLCheck, which will authenticate before sending to each subscriber.
from server.
@leijux 你这种的话,实现hook.OnACLCheck就行了,OnACLCheck会在发送给每个订阅者之前进行鉴权。
Line 1011 in 6b3b30e
OnACLCheck 能控制是客户端是否有权限读取这个主题,但是我获取不到是谁发出的数据包,相同主题有时数据包可能要发送给client1,有时可能要发送给client2。
from server.
那你只能自己做一些改动了,自己增加一个类似OnACLCheck的钩子方法,比如OnSendToSubscriber,然后可以把发送者的信息(比如ID)保存到pk.Properties里面,将OnACLCheck的参数修改一下。传递的不是topic,而是整个pk。
In that case, you'll need to make some changes yourself. You can add a hook method similar to OnACLCheck, like OnSendToSubscriber. Then you can save the publisher's information (such as ID) into pk.Properties, and pass the entire packet to OnSendToSubscriber.
from server.
那你只能自己做一些改动了,自己增加一个类似OnACLCheck的钩子方法,比如OnSendToSubscriber,然后可以把发送者的信息(比如ID)保存到pk.Properties里面,将OnACLCheck的参数修改一下。传递的不是topic,而是整个pk。
感谢,我能在下方的位置增加一个hook方法并提交合并请求吗?
Line 1006 in 47162a3
from server.
@leijux 非常可以。我建议增加一个类似OnSendToSubscriber的钩子方法。类似鉴权,不过这个鉴权只针对发送给订阅者时。
from server.
@leijux 非常可以。我建议增加一个类似OnSendToSubscriber的钩子方法。类似鉴权,不过这个鉴权只针对发送给订阅者时。
好的,我来考虑实现它。😊
from server.
@leijux 我又琢磨了下,是不是可以将OnSendToSubscriber和onAclCheck合并会更好,只需要OnAclCheck的参数改变就可以了,这样就没必要多出一个hook方法,逻辑也更明了
from server.
@leijux 我又琢磨了下,是不是可以将OnSendToSubscriber和onAclCheck合并会更好,只需要OnAclCheck的参数改变就可以了,这样就没必要多出一个hook方法,逻辑也更明了
是一个更好的办法,但是会影响api的兼容性。
from server.
The cost of changing onAclCheck is still too high. It's possible to use a specific topic to forward to the corresponding clients.
type Hook struct {
......
clients *mqtt.Clients //Introducing mqtt.Clients at Init
}
func (h *Hook) OnPublish(cl *mqtt.Client, pk packets.Packet) (packets.Packet, error) {
if pk.TopicName != "/a/b/c" {
return pk, nil
}
id := string(pk.Payload)
if client, ok := h.clients.Get(id); ok {
client.WritePacket(packets.Packet{
FixedHeader: packets.FixedHeader{Type: packets.Publish},
TopicName: "/x/y/z",
Payload: nil,
})
}
return pk, nil
}
from server.
Related Issues (20)
- After enabled badger, the vlog file up to 700M one day and 4GB one week HOT 9
- Race condition when running the redis example HOT 4
- 遍历Clients时如何判断当前Client是否为Disconected状态 HOT 3
- 作者您好,请帮忙关注一下这个问题 HOT 3
- Hi, what is the simplest way to make messages can be restored when server cut off? HOT 5
- [badgerdb] vlog growing unbounded - consider adding GC and exposing options HOT 6
- The badge still getting vlog file keep growing infirnity HOT 7
- Does peddle perssistant released? HOT 5
- MQTTX cannot use Topic Alias. MQTT5.0 主题别名发送卡住,无法发布主题别名的消息 HOT 2
- How to use the new pessistent hook? HOT 1
- Reload auth fIle on the run HOT 2
- InlineClient模式下服务端订阅问题,inline subscribers do not receive messages HOT 5
- Merge 2 version of storm HOT 4
- Add Support for Disconnect With Will Message Reason Code
- Logging Level is not Configurable Via File Configuration
- Persistence storage did not work with SetCleanSession(false) HOT 3
- Don't allow inheriting session unless username matches HOT 5
- MessageExpiry Hook HOT 1
- OnConnectAuthenticate cannot specify an error code (like Client Identifier not valid)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from server.