forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socks5.go
38 lines (32 loc) · 948 Bytes
/
socks5.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
package dialchain
import (
"net"
"github.com/elastic/beats/heartbeat/look"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs/transport"
)
// SOCKS5Layer configures a SOCKS5 proxy layer in a DialerChain.
//
// The layer will update the active event with:
//
// {
// "socks5": {
// "rtt": { "connect": { "us": ... }}
// }
// }
func SOCKS5Layer(config *transport.ProxyConfig) Layer {
return func(event common.MapStr, next transport.Dialer) (transport.Dialer, error) {
var timer timer
dialer, err := transport.ProxyDialer(config, startTimerAfterDial(&timer, next))
if err != nil {
return nil, err
}
return afterDial(dialer, func(conn net.Conn) (net.Conn, error) {
// TODO: extract connection parameter from connection object?
// TODO: add proxy url to event?
timer.stop()
event.Put("socks5.rtt.connect", look.RTT(timer.duration()))
return conn, nil
}), nil
}
}