Files
v2ray_simple/utils/error.go
hahahrfool f2adcdcd45 防止udp转发时被裸奔;修缮socks udp associate
修订代码,文档,示例

添加 NumErr 结构; 从 handshakeInserver_and_passToOutClient 函数 分离出一个 dialClient 函数。

在socks5包中添加 client.go 文件,以及三个udp相关的客户端请求udp函数

之前的udp associate代码被证明是有很多bug的,现在被我一一修复,并通过了 udp_test.go的测试。
2022-03-29 19:00:14 +08:00

94 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"bytes"
"fmt"
"strconv"
)
//没啥特殊的
type NumErr struct {
N int
Prefix string
}
func (ne *NumErr) Error() string {
return ne.Prefix + strconv.Itoa(ne.N)
}
//就是带个buffer的普通ErrInErr没啥特殊的
type ErrFirstBuffer struct {
Err error
First *bytes.Buffer
}
func (ef *ErrFirstBuffer) Unwarp() error {
return ef.Err
}
func (ef *ErrFirstBuffer) Error() string {
return ef.Err.Error()
}
func NewErr(desc string, e error) *ErrInErr {
return &ErrInErr{
ErrDesc: desc,
ErrDetail: e,
}
}
func NewDataErr(desc string, e error, data interface{}) *ErrInErr {
return &ErrInErr{
ErrDesc: desc,
ErrDetail: e,
Data: data,
}
}
// ErrInErr 很适合一个err包含另一个err并且提供附带数据的情况
type ErrInErr struct {
ErrDesc string
ErrDetail error
Data any
cachedStr string
}
func (e *ErrInErr) Error() string {
return e.String()
}
func (e *ErrInErr) Unwarp() error {
return e.ErrDetail
}
func (e *ErrInErr) String() string {
if e.cachedStr == "" {
e.cachedStr = e.string()
}
return e.cachedStr
}
func (e *ErrInErr) string() string {
if e.Data != nil {
if e.ErrDetail != nil {
return fmt.Sprintf("%s : %s, Data: %v", e.ErrDesc, e.ErrDetail.Error(), e.Data)
}
return fmt.Sprintf("%s , Data: %v", e.ErrDesc, e.Data)
}
if e.ErrDetail != nil {
return fmt.Sprintf("%s : %s", e.ErrDesc, e.ErrDetail.Error())
}
return e.ErrDesc
}