mirror of https://github.com/v2ray/v2ray-core
Guess protocol
parent
7b3cf631c2
commit
de28198234
|
@ -53,7 +53,28 @@ func wsDial(src v2net.Address, dest v2net.Destination) (*wsconn, error) {
|
||||||
|
|
||||||
dialer := websocket.Dialer{NetDial: commonDial, ReadBufferSize: 65536, WriteBufferSize: 65536, TLSClientConfig: tlsconf}
|
dialer := websocket.Dialer{NetDial: commonDial, ReadBufferSize: 65536, WriteBufferSize: 65536, TLSClientConfig: tlsconf}
|
||||||
|
|
||||||
effpto := func(dst v2net.Destination) string {
|
effpto := calcPto(dest)
|
||||||
|
|
||||||
|
uri := func(dst v2net.Destination, pto string, path string) string {
|
||||||
|
return fmt.Sprintf("%v://%v/%v", pto, dst.NetAddr(), path)
|
||||||
|
}(dest, effpto, effectiveConfig.Path)
|
||||||
|
|
||||||
|
conn, resp, err := dialer.Dial(uri, nil)
|
||||||
|
if err != nil {
|
||||||
|
if resp != nil {
|
||||||
|
reason, reasonerr := ioutil.ReadAll(resp.Body)
|
||||||
|
log.Info(string(reason), reasonerr)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return func() internet.Connection {
|
||||||
|
connv2ray := &wsconn{wsc: conn, connClosing: false}
|
||||||
|
connv2ray.setup()
|
||||||
|
return connv2ray
|
||||||
|
}().(*wsconn), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func calcPto(dst v2net.Destination) string {
|
||||||
|
|
||||||
if effectiveConfig.Pto != "" {
|
if effectiveConfig.Pto != "" {
|
||||||
return effectiveConfig.Pto
|
return effectiveConfig.Pto
|
||||||
|
@ -87,41 +108,32 @@ func wsDial(src v2net.Address, dest v2net.Destination) (*wsconn, error) {
|
||||||
We will return "CRASH"turn "unknown" if we can't guess it, cause Dial to fail.
|
We will return "CRASH"turn "unknown" if we can't guess it, cause Dial to fail.
|
||||||
*/
|
*/
|
||||||
case 80:
|
case 80:
|
||||||
|
fallthrough
|
||||||
case 8080:
|
case 8080:
|
||||||
|
fallthrough
|
||||||
case 8880:
|
case 8880:
|
||||||
|
fallthrough
|
||||||
case 2052:
|
case 2052:
|
||||||
|
fallthrough
|
||||||
case 2082:
|
case 2082:
|
||||||
|
fallthrough
|
||||||
case 2086:
|
case 2086:
|
||||||
|
fallthrough
|
||||||
case 2095:
|
case 2095:
|
||||||
return "ws"
|
return "ws"
|
||||||
case 443:
|
case 443:
|
||||||
|
fallthrough
|
||||||
case 2053:
|
case 2053:
|
||||||
|
fallthrough
|
||||||
case 2083:
|
case 2083:
|
||||||
|
fallthrough
|
||||||
case 2087:
|
case 2087:
|
||||||
|
fallthrough
|
||||||
case 2096:
|
case 2096:
|
||||||
|
fallthrough
|
||||||
case 8443:
|
case 8443:
|
||||||
return "wss"
|
return "wss"
|
||||||
default:
|
default:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
panic("Runtime unstable. Please report this bug to developers.")
|
|
||||||
}(dest)
|
|
||||||
|
|
||||||
uri := func(dst v2net.Destination, pto string, path string) string {
|
|
||||||
return fmt.Sprintf("%v://%v/%v", pto, dst.NetAddr(), path)
|
|
||||||
}(dest, effpto, effectiveConfig.Path)
|
|
||||||
|
|
||||||
conn, resp, err := dialer.Dial(uri, nil)
|
|
||||||
if err != nil {
|
|
||||||
if resp != nil {
|
|
||||||
reason, reasonerr := ioutil.ReadAll(resp.Body)
|
|
||||||
log.Info(string(reason), reasonerr)
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return func() internet.Connection {
|
|
||||||
connv2ray := &wsconn{wsc: conn, connClosing: false}
|
|
||||||
connv2ray.setup()
|
|
||||||
return connv2ray
|
|
||||||
}().(*wsconn), nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue