Skip to content

Commit

Permalink
Merge pull request #2051 from seveas/expose-tlsconnectionstate
Browse files Browse the repository at this point in the history
Expose the TLS connection state of a broker connection
  • Loading branch information
dnwe authored Jan 21, 2022
2 parents 4ee6656 + eae74a7 commit f1ea13a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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

0 comments on commit f1ea13a

Please sign in to comment.