mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
修订文档;修订日志和error方面的代码
This commit is contained in:
@@ -223,7 +223,7 @@ func (c *Client) DialSubConn(underlay any) (net.Conn, error) {
|
||||
},
|
||||
}
|
||||
|
||||
go conn.handshakeOnce.Do(conn.handshake) //necessary
|
||||
go conn.handshakeOnce.Do(conn.handshake) //necessary。 因为 handshake不会立刻退出,所以必须要用 goroutine, 否则会卡住
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
@@ -148,9 +148,7 @@ func (c *Client) getCommonConn(_ net.Conn) (*connState, error) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if ce := utils.CanLogErr("QUIC: dial failed"); ce != nil {
|
||||
ce.Write(zap.Error(err))
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -191,10 +191,10 @@ func getExtra(extra map[string]any) (useHysteria, hysteria_manual bool,
|
||||
|
||||
if thing := extra["maxStreamsInOneConn"]; thing != nil {
|
||||
if count, ok := thing.(int64); ok && count > 0 {
|
||||
if ce := utils.CanLogInfo("maxStreamsInOneConn"); ce != nil {
|
||||
ce.Write(zap.Int("maxStreamsInOneConn,", int(count)))
|
||||
if ce := utils.CanLogInfo("quic max Streams In One Conn"); ce != nil {
|
||||
ce.Write(zap.Int("count,", int(count)))
|
||||
} else {
|
||||
log.Println("maxStreamsInOneConn,", count)
|
||||
log.Println("quic maxStreamsInOneConn,", count)
|
||||
|
||||
}
|
||||
maxStreamsInOneConn = count
|
||||
|
||||
@@ -29,14 +29,14 @@ func ListenInitialLayers(addr string, tlsConf tls.Config, arg arguments) (newCon
|
||||
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
if ce := utils.CanLogErr("quic, ResolveUDPAddr failed"); ce != nil {
|
||||
if ce := utils.CanLogErr("QUIC ResolveUDPAddr failed"); ce != nil {
|
||||
ce.Write(zap.Error(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
conn, err := net.ListenUDP("udp", udpAddr)
|
||||
if err != nil {
|
||||
if ce := utils.CanLogErr("quic, listen udp failed"); ce != nil {
|
||||
if ce := utils.CanLogErr("QUIC listen udp failed"); ce != nil {
|
||||
ce.Write(zap.Error(err))
|
||||
}
|
||||
return
|
||||
@@ -52,7 +52,7 @@ func ListenInitialLayers(addr string, tlsConf tls.Config, arg arguments) (newCon
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
if ce := utils.CanLogErr("quic listen"); ce != nil {
|
||||
if ce := utils.CanLogErr("QUIC listen failed"); ce != nil {
|
||||
ce.Write(zap.Error(err))
|
||||
}
|
||||
return
|
||||
@@ -84,7 +84,7 @@ func loopAccept(l quic.Listener, theChan chan net.Conn, useHysteria bool, hyster
|
||||
|
||||
conn, err := l.Accept(context.Background())
|
||||
if err != nil {
|
||||
if ce := utils.CanLogErr("quic accept failed"); ce != nil {
|
||||
if ce := utils.CanLogErr("QUIC accept failed"); ce != nil {
|
||||
ce.Write(zap.Error(err))
|
||||
}
|
||||
//close(theChan) //不应关闭chan,因为listen虽然不好使但是也许现存的stream还是好使的...
|
||||
@@ -107,7 +107,7 @@ func loopAcceptEarly(el quic.EarlyListener, theChan chan net.Conn, useHysteria b
|
||||
|
||||
conn, err := el.Accept(context.Background())
|
||||
if err != nil {
|
||||
if ce := utils.CanLogErr("quic early accept failed"); ce != nil {
|
||||
if ce := utils.CanLogErr("QUIC early accept failed"); ce != nil {
|
||||
ce.Write(zap.Error(err))
|
||||
}
|
||||
return
|
||||
@@ -140,7 +140,7 @@ func dealNewConn(conn quic.Connection, theChan chan net.Conn) {
|
||||
for {
|
||||
stream, err := conn.AcceptStream(context.Background())
|
||||
if err != nil {
|
||||
if ce := utils.CanLogDebug("quic stream accept failed"); ce != nil {
|
||||
if ce := utils.CanLogDebug("QUIC stream accept failed"); ce != nil {
|
||||
//只要某个连接idle时间一长,超过了idleTimeout,服务端就会出现此错误:
|
||||
// timeout: no recent network activity,即 quic.IdleTimeoutError
|
||||
//这不能说是错误, 而是quic的udp特性所致,所以放到debug 输出中.
|
||||
|
||||
@@ -3,6 +3,7 @@ package ws
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -99,17 +100,15 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) {
|
||||
var rp httpLayer.H1RequestParser
|
||||
re := rp.ReadAndParse(underlay)
|
||||
if re != nil {
|
||||
if re == httpLayer.ErrNotHTTP_Request {
|
||||
if ce := utils.CanLogErr("WS check ErrNotHTTP_Request"); ce != nil {
|
||||
ce.Write()
|
||||
}
|
||||
if errors.Is(re, httpLayer.ErrNotHTTP_Request) {
|
||||
|
||||
return nil, utils.ErrInErr{ErrDesc: "WS check parse http failed", ErrDetail: httpLayer.ErrNotHTTP_Request}
|
||||
|
||||
} else {
|
||||
if ce := utils.CanLogErr("WS check handshake read failed"); ce != nil {
|
||||
ce.Write(zap.Error(re))
|
||||
}
|
||||
|
||||
return nil, utils.ErrInErr{ErrDesc: "WS check handshake read failed", ErrDetail: re}
|
||||
|
||||
}
|
||||
return nil, utils.ErrInvalidData
|
||||
}
|
||||
|
||||
optionalFirstBuffer := rp.WholeRequestBuf
|
||||
@@ -222,9 +221,7 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) {
|
||||
// 传来的并不是base64数据,可能是其它访问我们网站websocket的情况,但是一般我们path复杂都会过滤掉,所以直接认为这是非法的
|
||||
return "", false
|
||||
}
|
||||
//if len(bs) != 0 && utils.CanLogDebug() {
|
||||
// log.Println("Got New ws earlydata", len(bs), bs)
|
||||
//}
|
||||
|
||||
thePotentialEarlyData = bs
|
||||
return "", true
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ package httpLayer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
@@ -55,7 +54,7 @@ const (
|
||||
var (
|
||||
HeaderENDING_bytes = []byte(HeaderENDING)
|
||||
|
||||
ErrNotHTTP_Request = errors.New("not http request")
|
||||
ErrNotHTTP_Request = utils.InvalidDataErr("not http request")
|
||||
|
||||
Err400response_golang string
|
||||
)
|
||||
@@ -116,7 +115,7 @@ type H1RequestParser struct {
|
||||
}
|
||||
|
||||
// 尝试读取数据并解析HTTP请求, 解析道道 数据会存入 RequestParser 结构中.
|
||||
//如果读取错误,会返回该错误; 如果读到的不是HTTP请求,返回 ErrNotHTTP_Request;
|
||||
//如果读取错误,会返回该错误; 如果读到的不是HTTP请求,返回 的err 的 errors.Is(err,ErrNotHTTP_Request) == true;
|
||||
func (rhr *H1RequestParser) ReadAndParse(r io.Reader) error {
|
||||
bs := utils.GetPacket()
|
||||
|
||||
|
||||
11
main.go
11
main.go
@@ -172,15 +172,14 @@ func ListenSer(inServer proxy.Server, defaultOutClient proxy.Client, env *proxy.
|
||||
func handleNewIncomeConnection(inServer proxy.Server, defaultClientForThis proxy.Client, thisLocalConnectionInstance net.Conn, env *proxy.RoutingEnv) {
|
||||
|
||||
iics := incomingInserverConnState{
|
||||
baseLocalConn: thisLocalConnectionInstance,
|
||||
inServer: inServer,
|
||||
defaultClient: defaultClientForThis,
|
||||
routingEnv: env,
|
||||
baseLocalConn: thisLocalConnectionInstance,
|
||||
inServer: inServer,
|
||||
defaultClient: defaultClientForThis,
|
||||
routingEnv: env,
|
||||
isTlsLazyServerEnd: inServer.IsLazyTls() && CanLazyEncrypt(inServer),
|
||||
}
|
||||
iics.genID()
|
||||
|
||||
iics.isTlsLazyServerEnd = inServer.IsLazyTls() && CanLazyEncrypt(inServer)
|
||||
|
||||
wrappedConn := thisLocalConnectionInstance
|
||||
|
||||
if ce := iics.CanLogInfo("New Accepted Conn"); ce != nil {
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/e1732a364fed/v2ray_simple/proxy/http"
|
||||
"github.com/e1732a364fed/v2ray_simple/proxy/socks5"
|
||||
"github.com/e1732a364fed/v2ray_simple/utils"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/e1732a364fed/v2ray_simple/netLayer"
|
||||
"github.com/e1732a364fed/v2ray_simple/proxy"
|
||||
@@ -68,9 +67,9 @@ func (s *Server) Handshake(underlay net.Conn) (newconn net.Conn, msgConn netLaye
|
||||
if be, ok := err.(utils.ErrBuffer); ok {
|
||||
buf := be.Buf
|
||||
|
||||
if ce := utils.CanLogDebug("socks5http: http failed, will try socks5"); ce != nil {
|
||||
ce.Write(zap.Int("buflen", buf.Len()))
|
||||
}
|
||||
//if ce := utils.CanLogDebug("socks5http: http failed, will try socks5"); ce != nil {
|
||||
// ce.Write(zap.Int("buflen", buf.Len()))
|
||||
//}
|
||||
|
||||
newConn := &netLayer.ReadWrapper{
|
||||
Conn: underlay,
|
||||
|
||||
@@ -20,6 +20,17 @@ var (
|
||||
ErrFailed = errors.New("failed") //最无脑的Err, 在能描述清楚错误时不要使用 ErrFailed
|
||||
)
|
||||
|
||||
type InvalidDataErr string
|
||||
|
||||
//return err == e || err == ErrInvalidData
|
||||
func (e InvalidDataErr) Is(err error) bool {
|
||||
return err == e || err == ErrInvalidData
|
||||
}
|
||||
|
||||
func (e InvalidDataErr) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
//nothing special
|
||||
type NumErr struct {
|
||||
N int
|
||||
|
||||
Reference in New Issue
Block a user