-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pass *url.URL
to ConnectPacketBuilder
#206
Conversation
@@ -79,7 +79,7 @@ type ClientConfig struct { | |||
WillMessage *paho.WillMessage | |||
WillProperties *paho.WillProperties | |||
|
|||
ConnectPacketBuilder func(*paho.Connect) *paho.Connect // called prior to connection allowing customisation of the CONNECT packet | |||
ConnectPacketBuilder func(*paho.Connect, *url.URL) *paho.Connect // called prior to connection allowing customisation of the CONNECT packet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should pass a struct
instead? Trying to think of any other data that might be of use to ConnectPacketBuilder
in the future (using a struct
would mean future additions would be non-breaking) but cannot currently think of anything else that would be useful...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably fine as is (unless you can think of other data that could be useful).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could just be passed entire ClientConfig
, although only other useful thing to configure before connection that I can think of is TLS configuration and it's too late for that in buildConnectPacket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But URL is really only thing different between each connection attempt so any other external info user might want in that function could just be provided by the user when defining the function. Nothing really stops hook from looking like this
config := autopaho.ClientConfig{
ServerUrls: []*url.URL{serverURL},
ConnectRetryDelay: 5 * time.Second,
ConnectTimeout: 5 * time.Second,
ClientConfig: paho.ClientConfig{
ClientID: "test",
},
}
config.ConnectPacketBuilder = func(c *paho.Connect, u *url.URL) *paho.Connect {
doSomethingWith(config)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, something to do with the TLS connection (or the net.Conn
itself) was what I was thinking of. However having thought of this I could not come up with a real use-case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the simplest one would be different server cert/client cert/ca per server but if ever someone had that use case AttemptConnection
hook can cater for that just fine.
I guess one thing that could be improved is making attemptXXXConnection()
functions public so someone making custom AttemptConnection
hook could reuse it, I can add a commit changing it here if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - however I feel that the attemptXXXConnection
functions are pretty simple & generic (also easy to copy/modify) so it's best to leave them private (making them public may make future changes more difficult because changing a public interface = breaking change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I suggested it because the packets.NewThreadSafeConn()
in attemptTLSConnection
might be not very obvious on first look but the comment on callback itself explains it well enough
autopaho/auto.go
Outdated
@@ -157,7 +157,7 @@ func (cfg *ClientConfig) SetWillMessage(topic string, payload []byte, qos byte, | |||
// | |||
// Deprecated: Set ConnectPacketBuilder directly instead. This function exists for | |||
// backwards compatibility only (and may be removed in the future). | |||
func (cfg *ClientConfig) SetConnectPacketConfigurator(fn func(*paho.Connect) *paho.Connect) bool { | |||
func (cfg *ClientConfig) SetConnectPacketConfigurator(fn func(*paho.Connect, *url.URL) *paho.Connect) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change this; it's an unnecessary breaking change to a depreciated function. Just wrap the function the user passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
As per discussion in eclipse-paho#192 I've added URL as a parameter, and also an example on how to use it to extract password from URL
3f3e8d9
to
0385235
Compare
As per discussion in #192 I've added URL as a parameter, and also an example on how to use it to extract password from URL