mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Mon Nov 3 19:37:21 CET 2025
This commit is contained in:
@@ -51,26 +51,12 @@ func (p *Proxy) AliveForTestUrl(url string) bool {
|
||||
return p.alive.Load()
|
||||
}
|
||||
|
||||
// Dial implements C.Proxy
|
||||
func (p *Proxy) Dial(metadata *C.Metadata) (C.Conn, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultTCPTimeout)
|
||||
defer cancel()
|
||||
return p.DialContext(ctx, metadata)
|
||||
}
|
||||
|
||||
// DialContext implements C.ProxyAdapter
|
||||
func (p *Proxy) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error) {
|
||||
conn, err := p.ProxyAdapter.DialContext(ctx, metadata)
|
||||
return conn, err
|
||||
}
|
||||
|
||||
// DialUDP implements C.ProxyAdapter
|
||||
func (p *Proxy) DialUDP(metadata *C.Metadata) (C.PacketConn, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultUDPTimeout)
|
||||
defer cancel()
|
||||
return p.ListenPacketContext(ctx, metadata)
|
||||
}
|
||||
|
||||
// ListenPacketContext implements C.ProxyAdapter
|
||||
func (p *Proxy) ListenPacketContext(ctx context.Context, metadata *C.Metadata) (C.PacketConn, error) {
|
||||
pc, err := p.ProxyAdapter.ListenPacketContext(ctx, metadata)
|
||||
|
||||
@@ -263,7 +263,9 @@ func NewConn(c net.Conn, a C.ProxyAdapter) C.Conn {
|
||||
if _, ok := c.(syscall.Conn); !ok { // exclusion system conn like *net.TCPConn
|
||||
c = N.NewDeadlineConn(c) // most conn from outbound can't handle readDeadline correctly
|
||||
}
|
||||
return &conn{N.NewExtendedConn(c), []string{a.Name()}, a.Addr()}
|
||||
cc := &conn{N.NewExtendedConn(c), nil, a.Addr()}
|
||||
cc.AppendToChains(a)
|
||||
return cc
|
||||
}
|
||||
|
||||
type packetConn struct {
|
||||
@@ -320,7 +322,9 @@ func newPacketConn(pc net.PacketConn, a ProxyAdapter) C.PacketConn {
|
||||
if _, ok := pc.(syscall.Conn); !ok { // exclusion system conn like *net.UDPConn
|
||||
epc = N.NewDeadlineEnhancePacketConn(epc) // most conn from outbound can't handle readDeadline correctly
|
||||
}
|
||||
return &packetConn{epc, []string{a.Name()}, a.Name(), utils.NewUUIDV4().String(), a.Addr(), a.ResolveUDP}
|
||||
cpc := &packetConn{epc, nil, a.Name(), utils.NewUUIDV4().String(), a.Addr(), a.ResolveUDP}
|
||||
cpc.AppendToChains(a)
|
||||
return cpc
|
||||
}
|
||||
|
||||
type AddRef interface {
|
||||
|
||||
@@ -49,13 +49,7 @@ func ParseProxy(mapping map[string]any) (C.Proxy, error) {
|
||||
}
|
||||
proxy, err = outbound.NewHttp(*httpOption)
|
||||
case "vmess":
|
||||
vmessOption := &outbound.VmessOption{
|
||||
HTTPOpts: outbound.HTTPOptions{
|
||||
Method: "GET",
|
||||
Path: []string{"/"},
|
||||
},
|
||||
}
|
||||
|
||||
vmessOption := &outbound.VmessOption{}
|
||||
err = decoder.Decode(mapping, vmessOption)
|
||||
if err != nil {
|
||||
break
|
||||
|
||||
@@ -138,3 +138,5 @@ func escape[T any](x T) T {
|
||||
// ptrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant.
|
||||
// It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit).
|
||||
const ptrSize = 4 << (^uintptr(0) >> 63)
|
||||
|
||||
const testComparableAllocations = false
|
||||
|
||||
@@ -11,3 +11,5 @@ func Comparable[T comparable](seed Seed, v T) uint64 {
|
||||
func WriteComparable[T comparable](h *Hash, x T) {
|
||||
maphash.WriteComparable(h, x)
|
||||
}
|
||||
|
||||
const testComparableAllocations = true
|
||||
|
||||
@@ -423,7 +423,9 @@ func TestWriteComparableNoncommute(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestComparableAllocations(t *testing.T) {
|
||||
t.Skip("test broken in old golang version")
|
||||
if !testComparableAllocations {
|
||||
t.Skip("test broken in old golang version")
|
||||
}
|
||||
seed := MakeSeed()
|
||||
x := heapStr(t)
|
||||
allocs := testing.AllocsPerRun(10, func() {
|
||||
|
||||
@@ -53,6 +53,12 @@ func (d *Decoder) Decode(src map[string]any, dst any) error {
|
||||
key, omitKey, found := strings.Cut(tag, ",")
|
||||
omitempty := found && omitKey == "omitempty"
|
||||
|
||||
// As a special case, if the field tag is "-", the field is always omitted.
|
||||
// Note that a field with name "-" can still be generated using the tag "-,".
|
||||
if key == "-" {
|
||||
continue
|
||||
}
|
||||
|
||||
value, ok := src[key]
|
||||
if !ok {
|
||||
if d.option.KeyReplacer != nil {
|
||||
|
||||
@@ -288,3 +288,23 @@ func TestStructure_Null(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.Opt.Bar, "")
|
||||
}
|
||||
|
||||
func TestStructure_Ignore(t *testing.T) {
|
||||
rawMap := map[string]any{
|
||||
"-": "newData",
|
||||
}
|
||||
|
||||
s := struct {
|
||||
MustIgnore string `test:"-"`
|
||||
}{MustIgnore: "oldData"}
|
||||
|
||||
err := decoder.Decode(rawMap, &s)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
|
||||
// test omitempty
|
||||
delete(rawMap, "-")
|
||||
err = decoder.Decode(rawMap, &s)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
}
|
||||
|
||||
@@ -139,8 +139,11 @@ type ProxyAdapter interface {
|
||||
// SupportUOT return UDP over TCP support
|
||||
SupportUOT() bool
|
||||
|
||||
// SupportWithDialer only for deprecated relay group, the new protocol does not need to be implemented.
|
||||
SupportWithDialer() NetWork
|
||||
// DialContextWithDialer only for deprecated relay group, the new protocol does not need to be implemented.
|
||||
DialContextWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (Conn, error)
|
||||
// ListenPacketWithDialer only for deprecated relay group, the new protocol does not need to be implemented.
|
||||
ListenPacketWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (PacketConn, error)
|
||||
|
||||
// IsL3Protocol return ProxyAdapter working in L3 (tell dns module not pass the domain to avoid loopback)
|
||||
@@ -178,12 +181,6 @@ type Proxy interface {
|
||||
ExtraDelayHistories() map[string]ProxyState
|
||||
LastDelayForTestUrl(url string) uint16
|
||||
URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (uint16, error)
|
||||
|
||||
// Deprecated: use DialContext instead.
|
||||
Dial(metadata *Metadata) (Conn, error)
|
||||
|
||||
// Deprecated: use DialPacketConn instead.
|
||||
DialUDP(metadata *Metadata) (PacketConn, error)
|
||||
}
|
||||
|
||||
// AdapterType is enum of adapter type
|
||||
|
||||
@@ -3,7 +3,6 @@ package vmess
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -55,11 +54,11 @@ func (hc *httpConn) Write(b []byte) (int, error) {
|
||||
return hc.Conn.Write(b)
|
||||
}
|
||||
|
||||
if len(hc.cfg.Path) == 0 {
|
||||
return -1, errors.New("path is empty")
|
||||
path := "/"
|
||||
if len(hc.cfg.Path) > 0 {
|
||||
path = hc.cfg.Path[randv2.IntN(len(hc.cfg.Path))]
|
||||
}
|
||||
|
||||
path := hc.cfg.Path[randv2.IntN(len(hc.cfg.Path))]
|
||||
host := hc.cfg.Host
|
||||
if header := hc.cfg.Headers["Host"]; len(header) != 0 {
|
||||
host = header[randv2.IntN(len(header))]
|
||||
|
||||
Reference in New Issue
Block a user