Skip to content
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

Expose the TLS connection state of a broker connection #2051

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ func (b *Broker) Connected() (bool, error) {
return b.conn != nil, b.connErr
}

// TLSConnectionState returns the client's TLS connection state. The second return value is false if this is not a tls connection or the connection has not yet been established.
func (b *Broker) TLSConnectionState() (state tls.ConnectionState, ok bool) {
b.lock.Lock()
defer b.lock.Unlock()

if b.conn == nil {
return state, false
}
conn := b.conn
if bconn, ok := b.conn.(*bufConn); ok {
conn = bconn.Conn
}
if tc, ok := conn.(*tls.Conn); ok {
return tc.ConnectionState(), true
}
return state, false
}

// Close closes the broker resources
func (b *Broker) Close() error {
b.lock.Lock()
Expand Down