MCPcopy
hub / github.com/XTLS/REALITY / DetectPostHandshakeRecordsLens

Function DetectPostHandshakeRecordsLens

record_detect.go:21–102  ·  view source on GitHub ↗
(config *Config)

Source from the content-addressed store, hash-verified

19var GlobalMaxCSSMsgCount sync.Map
20
21func DetectPostHandshakeRecordsLens(config *Config) {
22 for sni := range config.ServerNames {
23 for alpn := range 3 { // 0, 1, 2
24 key := config.Dest + " " + sni + " " + strconv.Itoa(alpn)
25 if _, loaded := GlobalPostHandshakeRecordsLens.LoadOrStore(key, false); !loaded {
26 go func() {
27 defer func() {
28 val, _ := GlobalPostHandshakeRecordsLens.Load(key)
29 if _, ok := val.(bool); ok {
30 GlobalPostHandshakeRecordsLens.Store(key, []int{})
31 }
32 }()
33 target, err := net.Dial(config.Type, config.Dest)
34 if err != nil {
35 return
36 }
37 if config.Xver == 1 || config.Xver == 2 {
38 if _, err = proxyproto.HeaderProxyFromAddrs(config.Xver, target.LocalAddr(), target.RemoteAddr()).WriteTo(target); err != nil {
39 return
40 }
41 }
42 detectConn := &PostHandshakeRecordDetectConn{
43 Conn: target,
44 Key: key,
45 }
46 fingerprint := utls.HelloChrome_Auto
47 nextProtos := []string{"h2", "http/1.1"}
48 if alpn != 2 {
49 fingerprint = utls.HelloGolang
50 }
51 if alpn == 1 {
52 nextProtos = []string{"http/1.1"}
53 }
54 if alpn == 0 {
55 nextProtos = nil
56 }
57 uConn := utls.UClient(detectConn, &utls.Config{
58 ServerName: sni, // needs new loopvar behaviour
59 NextProtos: nextProtos,
60 }, fingerprint)
61 if err = uConn.Handshake(); err != nil {
62 return
63 }
64 io.Copy(io.Discard, uConn)
65 }()
66 go func() {
67 target, err := net.Dial(config.Type, config.Dest)
68 if err != nil {
69 return
70 }
71 if config.Xver == 1 || config.Xver == 2 {
72 if _, err = proxyproto.HeaderProxyFromAddrs(config.Xver, target.LocalAddr(), target.RemoteAddr()).WriteTo(target); err != nil {
73 return
74 }
75 }
76 fingerprint := utls.HelloChrome_Auto
77 nextProtos := []string{"h2", "http/1.1"}
78 if alpn != 2 {

Callers 1

NewListenerFunction · 0.85

Calls 4

DialMethod · 0.80
LocalAddrMethod · 0.80
RemoteAddrMethod · 0.80
HandshakeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…