forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tls.go
42 lines (35 loc) · 1.06 KB
/
tls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package dialchain
import (
"net"
"time"
"github.com/elastic/beats/heartbeat/look"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs/transport"
)
// TLSLayer configures the TLS layer in a DialerChain.
//
// The layer will update the active event with:
//
// {
// "tls": {
// "rtt": { "handshake": { "us": ... }}
// }
// }
func TLSLayer(cfg *transport.TLSConfig, to time.Duration) Layer {
return func(event common.MapStr, next transport.Dialer) (transport.Dialer, error) {
var timer timer
// Wrap next dialer so to start the timer when 'next' returns.
// This gets us the timestamp for when the TLS layer will start the handshake.
next = startTimerAfterDial(&timer, next)
dialer, err := transport.TLSDialer(next, cfg, to)
if err != nil {
return nil, err
}
return afterDial(dialer, func(conn net.Conn) (net.Conn, error) {
// TODO: extract TLS connection parameters from connection object.
timer.stop()
event.Put("tls.rtt.handshake", look.RTT(timer.duration()))
return conn, nil
}), nil
}
}