Hunter0x7c7
2022-08-11 b8230139fb40edea387617b6accd8371e37eda58
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package v4_test
 
import (
    "encoding/json"
    "testing"
 
    "github.com/golang/protobuf/proto"
 
    "github.com/v2fly/v2ray-core/v5/common/protocol"
    "github.com/v2fly/v2ray-core/v5/common/serial"
    "github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon/socketcfg"
    "github.com/v2fly/v2ray-core/v5/infra/conf/cfgcommon/testassist"
    v4 "github.com/v2fly/v2ray-core/v5/infra/conf/v4"
    "github.com/v2fly/v2ray-core/v5/transport"
    "github.com/v2fly/v2ray-core/v5/transport/internet"
    "github.com/v2fly/v2ray-core/v5/transport/internet/headers/http"
    "github.com/v2fly/v2ray-core/v5/transport/internet/headers/noop"
    "github.com/v2fly/v2ray-core/v5/transport/internet/headers/tls"
    "github.com/v2fly/v2ray-core/v5/transport/internet/kcp"
    "github.com/v2fly/v2ray-core/v5/transport/internet/quic"
    "github.com/v2fly/v2ray-core/v5/transport/internet/tcp"
    "github.com/v2fly/v2ray-core/v5/transport/internet/websocket"
)
 
func TestSocketConfig(t *testing.T) {
    createParser := func() func(string) (proto.Message, error) {
        return func(s string) (proto.Message, error) {
            config := new(socketcfg.SocketConfig)
            if err := json.Unmarshal([]byte(s), config); err != nil {
                return nil, err
            }
            return config.Build()
        }
    }
 
    testassist.RunMultiTestCase(t, []testassist.TestCase{
        {
            Input: `{
                "mark": 1,
                "tcpFastOpen": true,
                "tcpFastOpenQueueLength": 1024
            }`,
            Parser: createParser(),
            Output: &internet.SocketConfig{
                Mark:           1,
                Tfo:            internet.SocketConfig_Enable,
                TfoQueueLength: 1024,
            },
        },
    })
}
 
func TestTransportConfig(t *testing.T) {
    createParser := func() func(string) (proto.Message, error) {
        return func(s string) (proto.Message, error) {
            config := new(v4.TransportConfig)
            if err := json.Unmarshal([]byte(s), config); err != nil {
                return nil, err
            }
            return config.Build()
        }
    }
 
    testassist.RunMultiTestCase(t, []testassist.TestCase{
        {
            Input: `{
                "tcpSettings": {
                    "header": {
                        "type": "http",
                        "request": {
                            "version": "1.1",
                            "method": "GET",
                            "path": "/b",
                            "headers": {
                                "a": "b",
                                "c": "d"
                            }
                        },
                        "response": {
                            "version": "1.0",
                            "status": "404",
                            "reason": "Not Found"
                        }
                    }
                },
                "kcpSettings": {
                    "mtu": 1200,
                    "header": {
                        "type": "none"
                    }
                },
                "wsSettings": {
                    "path": "/t"
                },
                "quicSettings": {
                    "key": "abcd",
                    "header": {
                        "type": "dtls"
                    }
                }
            }`,
            Parser: createParser(),
            Output: &transport.Config{
                TransportSettings: []*internet.TransportConfig{
                    {
                        ProtocolName: "tcp",
                        Settings: serial.ToTypedMessage(&tcp.Config{
                            HeaderSettings: serial.ToTypedMessage(&http.Config{
                                Request: &http.RequestConfig{
                                    Version: &http.Version{Value: "1.1"},
                                    Method:  &http.Method{Value: "GET"},
                                    Uri:     []string{"/b"},
                                    Header: []*http.Header{
                                        {Name: "a", Value: []string{"b"}},
                                        {Name: "c", Value: []string{"d"}},
                                    },
                                },
                                Response: &http.ResponseConfig{
                                    Version: &http.Version{Value: "1.0"},
                                    Status:  &http.Status{Code: "404", Reason: "Not Found"},
                                    Header: []*http.Header{
                                        {
                                            Name:  "Content-Type",
                                            Value: []string{"application/octet-stream", "video/mpeg"},
                                        },
                                        {
                                            Name:  "Transfer-Encoding",
                                            Value: []string{"chunked"},
                                        },
                                        {
                                            Name:  "Connection",
                                            Value: []string{"keep-alive"},
                                        },
                                        {
                                            Name:  "Pragma",
                                            Value: []string{"no-cache"},
                                        },
                                        {
                                            Name:  "Cache-Control",
                                            Value: []string{"private", "no-cache"},
                                        },
                                    },
                                },
                            }),
                        }),
                    },
                    {
                        ProtocolName: "mkcp",
                        Settings: serial.ToTypedMessage(&kcp.Config{
                            Mtu:          &kcp.MTU{Value: 1200},
                            HeaderConfig: serial.ToTypedMessage(&noop.Config{}),
                        }),
                    },
                    {
                        ProtocolName: "websocket",
                        Settings: serial.ToTypedMessage(&websocket.Config{
                            Path: "/t",
                        }),
                    },
                    {
                        ProtocolName: "quic",
                        Settings: serial.ToTypedMessage(&quic.Config{
                            Key: "abcd",
                            Security: &protocol.SecurityConfig{
                                Type: protocol.SecurityType_NONE,
                            },
                            Header: serial.ToTypedMessage(&tls.PacketConfig{}),
                        }),
                    },
                },
            },
        },
    })
}