docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []string `yaml:"nameserver"` Fallback []string `yaml:"fallback"` FallbackFilter rawFallbackFilter `yaml:"fallback-filter"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange string `yaml:"fake-ip-range"` } type rawFallbackFilter struct { GeoIP bool `yaml:"geoip"` IPCIDR []string `yaml:"ipcidr"`
<mask> Proxies map[string]C.Proxy <mask> } <mask> <mask> type rawDNS struct { <mask> Enable bool `yaml:"enable"` <mask> IPv6 bool `yaml:"ipv6"` <mask> NameServer []string `yaml:"nameserver"` <mask> Fallback []string `yaml:"fallback"` <mask> Listen string `yaml:"listen"` <mask> EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` <mask> FakeIPRange string `yaml:"fake-ip-range"` <mask> } <mask> <mask> type rawConfig struct { <mask> Port int `yaml:"port"` <mask> SocksPort int `yaml:"socks-port"` </s> Feature: add fallback filters (#105) </s> remove Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool </s> add Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` FallbackFilter FallbackFilter `yaml:"fallback-filter"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool } // FallbackFilter config type FallbackFilter struct { GeoIP bool `yaml:"geoip"` IPCIDR []*net.IPNet `yaml:"ipcidr"` </s> remove ipv6 bool mapping bool fakeip bool pool *fakeip.Pool fallback []resolver main []resolver group singleflight.Group cache *cache.Cache </s> add ipv6 bool mapping bool fakeip bool pool *fakeip.Pool main []resolver fallback []resolver fallbackFilters []fallbackFilter group singleflight.Group cache *cache.Cache
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
config/config.go
FallbackFilter: rawFallbackFilter{ GeoIP: true, IPCIDR: []string{}, },
<mask> }, <mask> DNS: rawDNS{ <mask> Enable: false, <mask> FakeIPRange: "198.18.0.1/16", <mask> }, <mask> } <mask> err = yaml.Unmarshal([]byte(data), &rawConfig) <mask> return rawConfig, err <mask> } </s> Feature: add fallback filters (#105) </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
config/config.go
func parseFallbackIPCIDR(ips []string) ([]*net.IPNet, error) { ipNets := []*net.IPNet{} for idx, ip := range ips { _, ipnet, err := net.ParseCIDR(ip) if err != nil { return nil, fmt.Errorf("DNS FallbackIP[%d] format error: %s", idx, err.Error()) } ipNets = append(ipNets, ipnet) } return ipNets, nil }
<mask> return nameservers, nil <mask> } <mask> <mask> func parseDNS(cfg rawDNS) (*DNS, error) { <mask> if cfg.Enable && len(cfg.NameServer) == 0 { <mask> return nil, fmt.Errorf("If DNS configuration is turned on, NameServer cannot be empty") <mask> } </s> Feature: add fallback filters (#105) </s> remove if mmdb == nil { return nil, errors.New("GeoIP cannot use") } </s> add </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
config/config.go
FallbackFilter: FallbackFilter{ IPCIDR: []*net.IPNet{}, },
<mask> IPv6: cfg.IPv6, <mask> EnhancedMode: cfg.EnhancedMode, <mask> } <mask> var err error <mask> if dnsCfg.NameServer, err = parseNameServer(cfg.NameServer); err != nil { <mask> return nil, err <mask> } </s> Feature: add fallback filters (#105) </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) {
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
config/config.go
dnsCfg.FallbackFilter.GeoIP = cfg.FallbackFilter.GeoIP if fallbackip, err := parseFallbackIPCIDR(cfg.FallbackFilter.IPCIDR); err == nil { dnsCfg.FallbackFilter.IPCIDR = fallbackip }
<mask> <mask> dnsCfg.FakeIPRange = pool <mask> } <mask> <mask> return dnsCfg, nil <mask> } <mask> <mask> func parseAuthentication(rawRecords []string) []auth.AuthUser { <mask> users := make([]auth.AuthUser, 0) </s> Feature: add fallback filters (#105) </s> remove ipv6 bool mapping bool fakeip bool pool *fakeip.Pool fallback []resolver main []resolver group singleflight.Group cache *cache.Cache </s> add ipv6 bool mapping bool fakeip bool pool *fakeip.Pool main []resolver fallback []resolver fallbackFilters []fallbackFilter group singleflight.Group cache *cache.Cache </s> remove if mmdb == nil { return nil, errors.New("GeoIP cannot use") } </s> add </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
config/config.go
ipv6 bool mapping bool fakeip bool pool *fakeip.Pool main []resolver fallback []resolver fallbackFilters []fallbackFilter group singleflight.Group cache *cache.Cache
<mask> Error error <mask> } <mask> <mask> type Resolver struct { <mask> ipv6 bool <mask> mapping bool <mask> fakeip bool <mask> pool *fakeip.Pool <mask> fallback []resolver <mask> main []resolver <mask> group singleflight.Group <mask> cache *cache.Cache <mask> } <mask> <mask> // ResolveIP request with TypeA and TypeAAAA, priority return TypeAAAA <mask> func (r *Resolver) ResolveIP(host string) (ip net.IP, err error) { <mask> ch := make(chan net.IP) </s> Feature: add fallback filters (#105) </s> remove Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool </s> add Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` FallbackFilter FallbackFilter `yaml:"fallback-filter"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool } // FallbackFilter config type FallbackFilter struct { GeoIP bool `yaml:"geoip"` IPCIDR []*net.IPNet `yaml:"ipcidr"`
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
func (r *Resolver) shouldFallback(ip net.IP) bool { for _, filter := range r.fallbackFilters { if filter.Match(ip) { return true } } return false }
<mask> func (r *Resolver) ResolveIPv6(host string) (ip net.IP, err error) { <mask> return r.resolveIP(host, D.TypeAAAA) <mask> } <mask> <mask> // Exchange a batch of dns request, and it use cache <mask> func (r *Resolver) Exchange(m *D.Msg) (msg *D.Msg, err error) { <mask> if len(m.Question) == 0 { <mask> return nil, errors.New("should have one question at least") <mask> } <mask> </s> Feature: add fallback filters (#105) </s> remove ipv6 bool mapping bool fakeip bool pool *fakeip.Pool fallback []resolver main []resolver group singleflight.Group cache *cache.Cache </s> add ipv6 bool mapping bool fakeip bool pool *fakeip.Pool main []resolver fallback []resolver fallbackFilters []fallbackFilter group singleflight.Group cache *cache.Cache </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) { </s> remove if mmdb == nil { return nil, errors.New("GeoIP cannot use") } </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
<mask> } <mask> fallbackMsg := r.asyncExchange(r.fallback, m) <mask> res := <-msgCh <mask> if res.Error == nil { <mask> if mmdb == nil { <mask> return nil, errors.New("GeoIP cannot use") <mask> } <mask> <mask> if ips := r.msgToIP(res.Msg); len(ips) != 0 { <mask> if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { <mask> // release channel <mask> go func() { <-fallbackMsg }() <mask> msg = res.Msg </s> Feature: add fallback filters (#105) </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
if r.shouldFallback(ips[0]) {
<mask> return nil, errors.New("GeoIP cannot use") <mask> } <mask> <mask> if ips := r.msgToIP(res.Msg); len(ips) != 0 { <mask> if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { <mask> // release channel <mask> go func() { <-fallbackMsg }() <mask> msg = res.Msg <mask> return msg, err <mask> } <mask> } </s> Feature: add fallback filters (#105) </s> remove if mmdb == nil { return nil, errors.New("GeoIP cannot use") } </s> add
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
type FallbackFilter struct { GeoIP bool IPCIDR []*net.IPNet }
<mask> Addr string <mask> } <mask> <mask> type Config struct { <mask> Main, Fallback []NameServer <mask> IPv6 bool <mask> EnhancedMode EnhancedMode <mask> FallbackFilter FallbackFilter <mask> Pool *fakeip.Pool </s> Feature: add fallback filters (#105) </s> remove Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool </s> add Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` FallbackFilter FallbackFilter `yaml:"fallback-filter"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool } // FallbackFilter config type FallbackFilter struct { GeoIP bool `yaml:"geoip"` IPCIDR []*net.IPNet `yaml:"ipcidr"` </s> remove Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []string `yaml:"nameserver"` Fallback []string `yaml:"fallback"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange string `yaml:"fake-ip-range"` </s> add Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []string `yaml:"nameserver"` Fallback []string `yaml:"fallback"` FallbackFilter rawFallbackFilter `yaml:"fallback-filter"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange string `yaml:"fake-ip-range"` } type rawFallbackFilter struct { GeoIP bool `yaml:"geoip"` IPCIDR []string `yaml:"ipcidr"` </s> remove ipv6 bool mapping bool fakeip bool pool *fakeip.Pool fallback []resolver main []resolver group singleflight.Group cache *cache.Cache </s> add ipv6 bool mapping bool fakeip bool pool *fakeip.Pool main []resolver fallback []resolver fallbackFilters []fallbackFilter group singleflight.Group cache *cache.Cache </s> remove once.Do(func() { mmdb, _ = geoip2.Open(C.Path.MMDB()) }) </s> add
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
FallbackFilter FallbackFilter
<mask> type Config struct { <mask> Main, Fallback []NameServer <mask> IPv6 bool <mask> EnhancedMode EnhancedMode <mask> Pool *fakeip.Pool <mask> } <mask> <mask> func New(config Config) *Resolver { <mask> r := &Resolver{ </s> Feature: add fallback filters (#105) </s> remove once.Do(func() { mmdb, _ = geoip2.Open(C.Path.MMDB()) }) </s> add </s> remove Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool </s> add Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []dns.NameServer `yaml:"nameserver"` Fallback []dns.NameServer `yaml:"fallback"` FallbackFilter FallbackFilter `yaml:"fallback-filter"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange *fakeip.Pool } // FallbackFilter config type FallbackFilter struct { GeoIP bool `yaml:"geoip"` IPCIDR []*net.IPNet `yaml:"ipcidr"` </s> remove Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []string `yaml:"nameserver"` Fallback []string `yaml:"fallback"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange string `yaml:"fake-ip-range"` </s> add Enable bool `yaml:"enable"` IPv6 bool `yaml:"ipv6"` NameServer []string `yaml:"nameserver"` Fallback []string `yaml:"fallback"` FallbackFilter rawFallbackFilter `yaml:"fallback-filter"` Listen string `yaml:"listen"` EnhancedMode dns.EnhancedMode `yaml:"enhanced-mode"` FakeIPRange string `yaml:"fake-ip-range"` } type rawFallbackFilter struct { GeoIP bool `yaml:"geoip"` IPCIDR []string `yaml:"ipcidr"` </s> remove ipv6 bool mapping bool fakeip bool pool *fakeip.Pool fallback []resolver main []resolver group singleflight.Group cache *cache.Cache </s> add ipv6 bool mapping bool fakeip bool pool *fakeip.Pool main []resolver fallback []resolver fallbackFilters []fallbackFilter group singleflight.Group cache *cache.Cache
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
<mask> Pool *fakeip.Pool <mask> } <mask> <mask> func New(config Config) *Resolver { <mask> once.Do(func() { <mask> mmdb, _ = geoip2.Open(C.Path.MMDB()) <mask> }) <mask> <mask> r := &Resolver{ <mask> ipv6: config.IPv6, <mask> main: transform(config.Main), <mask> cache: cache.New(time.Second * 60), <mask> mapping: config.EnhancedMode == MAPPING, </s> Feature: add fallback filters (#105) </s> remove if mmdb == nil { return nil, errors.New("GeoIP cannot use") } </s> add </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
fallbackFilters := []fallbackFilter{} if config.FallbackFilter.GeoIP { once.Do(func() { mmdb, _ = geoip2.Open(C.Path.MMDB()) }) fallbackFilters = append(fallbackFilters, &geoipFilter{}) } for _, ipnet := range config.FallbackFilter.IPCIDR { fallbackFilters = append(fallbackFilters, &ipnetFilter{ipnet: ipnet}) } r.fallbackFilters = fallbackFilters
<mask> if len(config.Fallback) != 0 { <mask> r.fallback = transform(config.Fallback) <mask> } <mask> return r <mask> } </s> Feature: add fallback filters (#105) </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) { </s> remove if mmdb == nil { return nil, errors.New("GeoIP cannot use") } </s> add
[ "keep", "keep", "add", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
dns/resolver.go
FallbackFilter: dns.FallbackFilter{ GeoIP: c.FallbackFilter.GeoIP, IPCIDR: c.FallbackFilter.IPCIDR, },
<mask> Fallback: c.Fallback, <mask> IPv6: c.IPv6, <mask> EnhancedMode: c.EnhancedMode, <mask> Pool: c.FakeIPRange, <mask> }) <mask> dns.DefaultResolver = r <mask> if err := dns.ReCreateServer(c.Listen, r); err != nil { <mask> log.Errorln("Start DNS server error: %s", err.Error()) <mask> return </s> Feature: add fallback filters (#105) </s> remove if record, _ := mmdb.Country(ips[0]); record.Country.IsoCode == "CN" || record.Country.IsoCode == "" { // release channel </s> add if r.shouldFallback(ips[0]) {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b76737bdbbce7cb2e6b380e33b77e5cb37c70c40
hub/executor/executor.go
<mask> package outbound <mask> <mask> import ( <mask> "bytes" <mask> "net" <mask> "strconv" <mask> "time" <mask> <mask> "github.com/Dreamacro/clash/component/resolver" </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "bytes" </s> add </s> remove "bytes" "encoding/binary" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add </s> remove "encoding/binary" </s> add
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
"github.com/Dreamacro/protobytes"
<mask> <mask> "github.com/Dreamacro/clash/component/resolver" <mask> C "github.com/Dreamacro/clash/constant" <mask> "github.com/Dreamacro/clash/transport/socks5" <mask> ) <mask> <mask> func tcpKeepAlive(c net.Conn) { <mask> if tcp, ok := c.(*net.TCPConn); ok { <mask> tcp.SetKeepAlive(true) <mask> tcp.SetKeepAlivePeriod(30 * time.Second) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "github.com/Dreamacro/clash/common/pool" </s> add </s> remove var bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} </s> add var ( bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} bytesBufferPool = sync.Pool{New: func() any { return &protobytes.BytesWriter{} }} )
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
buf := protobytes.BytesWriter{}
<mask> } <mask> } <mask> <mask> func serializesSocksAddr(metadata *C.Metadata) []byte { <mask> var buf [][]byte <mask> addrType := metadata.AddrType() <mask> aType := uint8(addrType) <mask> p, _ := strconv.ParseUint(metadata.DstPort, 10, 16) <mask> port := []byte{uint8(p >> 8), uint8(p & 0xff)} <mask> switch addrType { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove aType := uint8(addrType) </s> add buf.PutUint8(uint8(addrType)) </s> remove port := []byte{uint8(p >> 8), uint8(p & 0xff)} </s> add </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host) </s> remove buf := &bytes.Buffer{} binary.Write(buf, binary.BigEndian, time) random := make([]byte, 4) rand.Read(random) buf.Write(random) </s> add buf := protobytes.BytesWriter{} buf.PutUint64be(uint64(time)) buf.ReadFull(rand.Reader, 4) </s> remove random := make([]byte, 28) sessionID := make([]byte, 32) rand.Read(random) rand.Read(sessionID) buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
buf.PutUint8(uint8(addrType))
<mask> <mask> func serializesSocksAddr(metadata *C.Metadata) []byte { <mask> var buf [][]byte <mask> addrType := metadata.AddrType() <mask> aType := uint8(addrType) <mask> p, _ := strconv.ParseUint(metadata.DstPort, 10, 16) <mask> port := []byte{uint8(p >> 8), uint8(p & 0xff)} <mask> switch addrType { <mask> case socks5.AtypDomainName: <mask> len := uint8(len(metadata.Host)) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove var buf [][]byte </s> add buf := protobytes.BytesWriter{} </s> remove port := []byte{uint8(p >> 8), uint8(p & 0xff)} </s> add </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host) </s> remove host := metadata.DstIP.To4() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To4()) </s> remove buf.Write(socks5Addr[1 : 1+1+hostLen+2]) </s> add buf.PutSlice(socks5Addr[1 : 1+1+hostLen+2])
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
<mask> var buf [][]byte <mask> addrType := metadata.AddrType() <mask> aType := uint8(addrType) <mask> p, _ := strconv.ParseUint(metadata.DstPort, 10, 16) <mask> port := []byte{uint8(p >> 8), uint8(p & 0xff)} <mask> switch addrType { <mask> case socks5.AtypDomainName: <mask> len := uint8(len(metadata.Host)) <mask> host := []byte(metadata.Host) <mask> buf = [][]byte{{aType, len}, host, port} </s> Chore: use protobytes replace most of bytes.Buffer </s> remove aType := uint8(addrType) </s> add buf.PutUint8(uint8(addrType)) </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host) </s> remove var buf [][]byte </s> add buf := protobytes.BytesWriter{} </s> remove host := metadata.DstIP.To4() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To4()) </s> remove host := metadata.DstIP.To16() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To16())
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host)
<mask> p, _ := strconv.ParseUint(metadata.DstPort, 10, 16) <mask> port := []byte{uint8(p >> 8), uint8(p & 0xff)} <mask> switch addrType { <mask> case socks5.AtypDomainName: <mask> len := uint8(len(metadata.Host)) <mask> host := []byte(metadata.Host) <mask> buf = [][]byte{{aType, len}, host, port} <mask> case socks5.AtypIPv4: <mask> host := metadata.DstIP.To4() <mask> buf = [][]byte{{aType}, host, port} <mask> case socks5.AtypIPv6: <mask> host := metadata.DstIP.To16() </s> Chore: use protobytes replace most of bytes.Buffer </s> remove port := []byte{uint8(p >> 8), uint8(p & 0xff)} </s> add </s> remove host := metadata.DstIP.To4() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To4()) </s> remove aType := uint8(addrType) </s> add buf.PutUint8(uint8(addrType)) </s> remove host := metadata.DstIP.To16() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To16()) </s> remove var buf [][]byte </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
buf.PutSlice(metadata.DstIP.To4())
<mask> len := uint8(len(metadata.Host)) <mask> host := []byte(metadata.Host) <mask> buf = [][]byte{{aType, len}, host, port} <mask> case socks5.AtypIPv4: <mask> host := metadata.DstIP.To4() <mask> buf = [][]byte{{aType}, host, port} <mask> case socks5.AtypIPv6: <mask> host := metadata.DstIP.To16() <mask> buf = [][]byte{{aType}, host, port} <mask> } <mask> return bytes.Join(buf, nil) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove host := metadata.DstIP.To16() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To16()) </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host) </s> remove return bytes.Join(buf, nil) </s> add buf.PutUint16be(uint16(p)) return buf.Bytes() </s> remove port := []byte{uint8(p >> 8), uint8(p & 0xff)} </s> add </s> remove aType := uint8(addrType) </s> add buf.PutUint8(uint8(addrType))
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
buf.PutSlice(metadata.DstIP.To16())
<mask> case socks5.AtypIPv4: <mask> host := metadata.DstIP.To4() <mask> buf = [][]byte{{aType}, host, port} <mask> case socks5.AtypIPv6: <mask> host := metadata.DstIP.To16() <mask> buf = [][]byte{{aType}, host, port} <mask> } <mask> return bytes.Join(buf, nil) <mask> } <mask> <mask> func resolveUDPAddr(network, address string) (*net.UDPAddr, error) { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove host := metadata.DstIP.To4() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To4()) </s> remove return bytes.Join(buf, nil) </s> add buf.PutUint16be(uint16(p)) return buf.Bytes() </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host) </s> remove port := []byte{uint8(p >> 8), uint8(p & 0xff)} </s> add </s> remove var addr Addr </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
buf.PutUint16be(uint16(p)) return buf.Bytes()
<mask> case socks5.AtypIPv6: <mask> host := metadata.DstIP.To16() <mask> buf = [][]byte{{aType}, host, port} <mask> } <mask> return bytes.Join(buf, nil) <mask> } <mask> <mask> func resolveUDPAddr(network, address string) (*net.UDPAddr, error) { <mask> host, port, err := net.SplitHostPort(address) <mask> if err != nil { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove host := metadata.DstIP.To16() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To16()) </s> remove host := metadata.DstIP.To4() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To4()) </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host) </s> remove var addr Addr </s> add buf := protobytes.BytesWriter{} </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
adapter/outbound/util.go
"github.com/Dreamacro/protobytes"
<mask> "bytes" <mask> "sync" <mask> ) <mask> <mask> var ( <mask> bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} <mask> bytesBufferPool = sync.Pool{New: func() any { return &protobytes.BytesWriter{} }} </s> Chore: use protobytes replace most of bytes.Buffer </s> remove var bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} </s> add var ( bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} bytesBufferPool = sync.Pool{New: func() any { return &protobytes.BytesWriter{} }} ) </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove var ( dstIP = req[4:8] // [4]byte dstPort = req[2:4] // [2]byte ) </s> add </s> remove if command = req[1]; command != CmdConnect { </s> add if command = r.ReadUint8(); command != CmdConnect {
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
common/pool/buffer.go
var ( bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} bytesBufferPool = sync.Pool{New: func() any { return &protobytes.BytesWriter{} }} )
<mask> "bytes" <mask> "sync" <mask> ) <mask> <mask> var bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} <mask> <mask> func GetBuffer() *bytes.Buffer { <mask> return bufferPool.Get().(*bytes.Buffer) <mask> } <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
common/pool/buffer.go
func GetBytesBuffer() *protobytes.BytesWriter { return bytesBufferPool.Get().(*protobytes.BytesWriter) } func PutBytesBuffer(buf *protobytes.BytesWriter) { buf.Reset() bufferPool.Put(buf) }
<mask> func PutBuffer(buf *bytes.Buffer) { <mask> buf.Reset() <mask> bufferPool.Put(buf) <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(Traffic{ </s> add if err := json.NewEncoder(&buf).Encode(Traffic{ </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(socks5Addr) binary.Write(buf, binary.BigEndian, uint16(len(payload))) buf.Write(crlf) buf.Write(payload) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(socks5Addr) buf.PutUint16be(uint16(len(payload))) buf.PutSlice(crlf) buf.PutSlice(payload) </s> remove return parsed </s> add return Addr(parsed)
[ "keep", "keep", "keep", "add" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
common/pool/buffer.go
github.com/Dreamacro/protobytes v0.0.0-20230324064118-87bc784139cd // indirect
<mask> gopkg.in/yaml.v3 v3.0.1 <mask> ) <mask> <mask> require ( <mask> github.com/ajg/form v1.5.1 // indirect <mask> github.com/davecgh/go-spew v1.1.1 // indirect <mask> github.com/google/go-cmp v0.5.9 // indirect <mask> github.com/josharian/native v1.1.0 // indirect </s> Chore: use protobytes replace most of bytes.Buffer </s> remove var ( dstIP = req[4:8] // [4]byte dstPort = req[2:4] // [2]byte ) </s> add </s> remove "bytes" </s> add
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
go.mod
<mask> package route <mask> <mask> import ( <mask> "bytes" <mask> "encoding/json" <mask> "net/http" <mask> "strconv" <mask> "time" <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "bytes" </s> add </s> remove "bytes" "encoding/binary" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
hub/route/connections.go
"github.com/Dreamacro/protobytes"
<mask> "github.com/Dreamacro/clash/tunnel/statistic" <mask> <mask> "github.com/go-chi/chi/v5" <mask> "github.com/go-chi/render" <mask> "github.com/gorilla/websocket" <mask> ) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "github.com/Dreamacro/clash/common/pool" </s> add </s> remove "bytes" </s> add
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
hub/route/connections.go
buf := protobytes.BytesWriter{}
<mask> <mask> interval = t <mask> } <mask> <mask> buf := &bytes.Buffer{} <mask> sendSnapshot := func() error { <mask> buf.Reset() <mask> snapshot := statistic.DefaultManager.Snapshot() <mask> if err := json.NewEncoder(buf).Encode(snapshot); err != nil { <mask> return err </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(Traffic{ </s> add if err := json.NewEncoder(&buf).Encode(Traffic{ </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
hub/route/connections.go
if err := json.NewEncoder(&buf).Encode(snapshot); err != nil {
<mask> buf := &bytes.Buffer{} <mask> sendSnapshot := func() error { <mask> buf.Reset() <mask> snapshot := statistic.DefaultManager.Snapshot() <mask> if err := json.NewEncoder(buf).Encode(snapshot); err != nil { <mask> return err <mask> } <mask> <mask> return conn.WriteMessage(websocket.TextMessage, buf.Bytes()) <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(Traffic{ </s> add if err := json.NewEncoder(&buf).Encode(Traffic{ </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove buf.Write(fnv1a.Sum(nil)) </s> add buf.PutSlice(fnv1a.Sum(nil))
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
hub/route/connections.go
"github.com/Dreamacro/protobytes"
<mask> C "github.com/Dreamacro/clash/constant" <mask> "github.com/Dreamacro/clash/log" <mask> "github.com/Dreamacro/clash/tunnel/statistic" <mask> <mask> "github.com/go-chi/chi/v5" <mask> "github.com/go-chi/cors" <mask> "github.com/go-chi/render" <mask> "github.com/gorilla/websocket" </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "github.com/Dreamacro/clash/common/pool" </s> add </s> remove var ( dstIP = req[4:8] // [4]byte dstPort = req[2:4] // [2]byte ) </s> add </s> remove if command = req[1]; command != CmdConnect { </s> add if command = r.ReadUint8(); command != CmdConnect {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
hub/route/server.go
buf := protobytes.BytesWriter{}
<mask> <mask> tick := time.NewTicker(time.Second) <mask> defer tick.Stop() <mask> t := statistic.DefaultManager <mask> buf := &bytes.Buffer{} <mask> var err error <mask> for range tick.C { <mask> buf.Reset() <mask> up, down := t.Now() <mask> if err := json.NewEncoder(buf).Encode(Traffic{ </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if err := json.NewEncoder(buf).Encode(Traffic{ </s> add if err := json.NewEncoder(&buf).Encode(Traffic{ </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(grpcHeader) buf.Write(protobufHeader[:varuintSize+1]) buf.Write(b) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutSlice(grpcHeader) buf.PutSlice(protobufHeader[:varuintSize+1]) buf.PutSlice(b)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
hub/route/server.go
if err := json.NewEncoder(&buf).Encode(Traffic{
<mask> var err error <mask> for range tick.C { <mask> buf.Reset() <mask> up, down := t.Now() <mask> if err := json.NewEncoder(buf).Encode(Traffic{ <mask> Up: up, <mask> Down: down, <mask> }); err != nil { <mask> break <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
hub/route/server.go
buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutSlice(grpcHeader) buf.PutSlice(protobufHeader[:varuintSize+1]) buf.PutSlice(b)
<mask> grpcHeader := make([]byte, 5) <mask> grpcPayloadLen := uint32(varuintSize + 1 + len(b)) <mask> binary.BigEndian.PutUint32(grpcHeader[1:5], grpcPayloadLen) <mask> <mask> buf := pool.GetBuffer() <mask> defer pool.PutBuffer(buf) <mask> buf.Write(grpcHeader) <mask> buf.Write(protobufHeader[:varuintSize+1]) <mask> buf.Write(b) <mask> <mask> _, err = g.writer.Write(buf.Bytes()) <mask> if err == io.ErrClosedPipe && g.err != nil { <mask> err = g.err <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write([]byte{0x17, 0x03, 0x03}) binary.Write(buf, binary.BigEndian, uint16(len(b))) buf.Write(b) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutSlice([]byte{0x17, 0x03, 0x03}) buf.PutUint16be(uint16(len(b))) buf.PutSlice(b) </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove random := make([]byte, 28) sessionID := make([]byte, 32) rand.Read(random) rand.Read(sessionID) buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2) </s> remove _, wErr := rw.Write(reply[:]) </s> add _, wErr := rw.Write(reply.Bytes())
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/gun/gun.go
<mask> package obfs <mask> <mask> import ( <mask> "bytes" <mask> "crypto/rand" <mask> "encoding/binary" <mask> "io" <mask> "net" <mask> "time" </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "bytes" </s> add </s> remove "bytes" "encoding/binary" </s> add </s> remove "encoding/binary" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
"github.com/Dreamacro/protobytes"
<mask> <mask> "github.com/Dreamacro/clash/common/pool" <mask> ) <mask> <mask> const ( <mask> chunkSize = 1 << 14 // 2 ** 14 == 16 * 1024 <mask> ) <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "github.com/Dreamacro/clash/common/pool" </s> add
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutSlice([]byte{0x17, 0x03, 0x03}) buf.PutUint16be(uint16(len(b))) buf.PutSlice(b)
<mask> to.firstRequest = false <mask> return len(b), err <mask> } <mask> <mask> buf := pool.GetBuffer() <mask> defer pool.PutBuffer(buf) <mask> buf.Write([]byte{0x17, 0x03, 0x03}) <mask> binary.Write(buf, binary.BigEndian, uint16(len(b))) <mask> buf.Write(b) <mask> _, err := to.Conn.Write(buf.Bytes()) <mask> return len(b), err <mask> } <mask> <mask> // NewTLSObfs return a SimpleObfs </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(grpcHeader) buf.Write(protobufHeader[:varuintSize+1]) buf.Write(b) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutSlice(grpcHeader) buf.PutSlice(protobufHeader[:varuintSize+1]) buf.PutSlice(b) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(socks5Addr) binary.Write(buf, binary.BigEndian, uint16(len(payload))) buf.Write(crlf) buf.Write(payload) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(socks5Addr) buf.PutUint16be(uint16(len(payload))) buf.PutSlice(crlf) buf.PutSlice(payload) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2) </s> remove buf.WriteByte(uint8(len(host))) buf.WriteString(host) binary.Write(buf, binary.BigEndian, uint16(port)) </s> add buf.PutUint8(uint8(len(host))) buf.PutString(host) buf.PutUint16be(uint16(port))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf := protobytes.BytesWriter{}
<mask> } <mask> } <mask> <mask> func makeClientHelloMsg(data []byte, server string) []byte { <mask> random := make([]byte, 28) <mask> sessionID := make([]byte, 32) <mask> rand.Read(random) <mask> rand.Read(sessionID) <mask> <mask> buf := &bytes.Buffer{} <mask> <mask> // handshake, TLS 1.0 version, length <mask> buf.WriteByte(22) <mask> buf.Write([]byte{0x03, 0x01}) <mask> length := uint16(212 + len(data) + len(server)) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(22) buf.Write([]byte{0x03, 0x01}) </s> add buf.PutUint8(22) buf.PutSlice([]byte{0x03, 0x01}) </s> remove buf.WriteByte(byte(length >> 8)) buf.WriteByte(byte(length & 0xff)) </s> add buf.PutUint16be(length) </s> remove buf := &bytes.Buffer{} binary.Write(buf, binary.BigEndian, time) random := make([]byte, 4) rand.Read(random) buf.Write(random) </s> add buf := protobytes.BytesWriter{} buf.PutUint64be(uint64(time)) buf.ReadFull(rand.Reader, 4) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(grpcHeader) buf.Write(protobufHeader[:varuintSize+1]) buf.Write(b) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutSlice(grpcHeader) buf.PutSlice(protobufHeader[:varuintSize+1]) buf.PutSlice(b) </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutUint8(22) buf.PutSlice([]byte{0x03, 0x01})
<mask> <mask> buf := &bytes.Buffer{} <mask> <mask> // handshake, TLS 1.0 version, length <mask> buf.WriteByte(22) <mask> buf.Write([]byte{0x03, 0x01}) <mask> length := uint16(212 + len(data) + len(server)) <mask> buf.WriteByte(byte(length >> 8)) <mask> buf.WriteByte(byte(length & 0xff)) <mask> <mask> // clientHello, length, TLS 1.2 version </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(byte(length >> 8)) buf.WriteByte(byte(length & 0xff)) </s> add buf.PutUint16be(length) </s> remove random := make([]byte, 28) sessionID := make([]byte, 32) rand.Read(random) rand.Read(sessionID) buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove buf.WriteByte(1) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(208+len(data)+len(server))) buf.Write([]byte{0x03, 0x03}) </s> add buf.PutUint8(1) buf.PutUint8(0) buf.PutUint16be(uint16(208 + len(data) + len(server))) buf.PutSlice([]byte{0x03, 0x03}) </s> remove binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) </s> add buf.PutUint16be(uint16(79 + len(data) + len(server))) </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutUint16be(length)
<mask> // handshake, TLS 1.0 version, length <mask> buf.WriteByte(22) <mask> buf.Write([]byte{0x03, 0x01}) <mask> length := uint16(212 + len(data) + len(server)) <mask> buf.WriteByte(byte(length >> 8)) <mask> buf.WriteByte(byte(length & 0xff)) <mask> <mask> // clientHello, length, TLS 1.2 version <mask> buf.WriteByte(1) <mask> buf.WriteByte(0) <mask> binary.Write(buf, binary.BigEndian, uint16(208+len(data)+len(server))) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(22) buf.Write([]byte{0x03, 0x01}) </s> add buf.PutUint8(22) buf.PutSlice([]byte{0x03, 0x01}) </s> remove buf.WriteByte(1) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(208+len(data)+len(server))) buf.Write([]byte{0x03, 0x03}) </s> add buf.PutUint8(1) buf.PutUint8(0) buf.PutUint16be(uint16(208 + len(data) + len(server))) buf.PutSlice([]byte{0x03, 0x03}) </s> remove random := make([]byte, 28) sessionID := make([]byte, 32) rand.Read(random) rand.Read(sessionID) buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) </s> add buf.PutUint16be(uint16(79 + len(data) + len(server))) </s> remove buf.WriteByte(0) </s> add buf.PutUint8(0)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutUint8(1) buf.PutUint8(0) buf.PutUint16be(uint16(208 + len(data) + len(server))) buf.PutSlice([]byte{0x03, 0x03})
<mask> buf.WriteByte(byte(length >> 8)) <mask> buf.WriteByte(byte(length & 0xff)) <mask> <mask> // clientHello, length, TLS 1.2 version <mask> buf.WriteByte(1) <mask> buf.WriteByte(0) <mask> binary.Write(buf, binary.BigEndian, uint16(208+len(data)+len(server))) <mask> buf.Write([]byte{0x03, 0x03}) <mask> <mask> // random with timestamp, sid len, sid <mask> binary.Write(buf, binary.BigEndian, uint32(time.Now().Unix())) <mask> buf.Write(random) <mask> buf.WriteByte(32) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(byte(length >> 8)) buf.WriteByte(byte(length & 0xff)) </s> add buf.PutUint16be(length) </s> remove binary.Write(buf, binary.BigEndian, uint32(time.Now().Unix())) buf.Write(random) buf.WriteByte(32) buf.Write(sessionID) </s> add buf.PutUint32be(uint32(time.Now().Unix())) buf.ReadFull(rand.Reader, 28) buf.PutUint8(32) buf.ReadFull(rand.Reader, 32) </s> remove buf.WriteByte(22) buf.Write([]byte{0x03, 0x01}) </s> add buf.PutUint8(22) buf.PutSlice([]byte{0x03, 0x01}) </s> remove buf.WriteByte(0) </s> add buf.PutUint8(0) </s> remove binary.Write(buf, binary.BigEndian, zero) </s> add buf.PutUint32be(zero)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutUint32be(uint32(time.Now().Unix())) buf.ReadFull(rand.Reader, 28) buf.PutUint8(32) buf.ReadFull(rand.Reader, 32)
<mask> binary.Write(buf, binary.BigEndian, uint16(208+len(data)+len(server))) <mask> buf.Write([]byte{0x03, 0x03}) <mask> <mask> // random with timestamp, sid len, sid <mask> binary.Write(buf, binary.BigEndian, uint32(time.Now().Unix())) <mask> buf.Write(random) <mask> buf.WriteByte(32) <mask> buf.Write(sessionID) <mask> <mask> // cipher suites <mask> buf.Write([]byte{0x00, 0x38}) <mask> buf.Write([]byte{ <mask> 0xc0, 0x2c, 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f, </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x38}) buf.Write([]byte{ </s> add buf.PutSlice([]byte{0x00, 0x38}) buf.PutSlice([]byte{ </s> remove buf.WriteByte(1) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(208+len(data)+len(server))) buf.Write([]byte{0x03, 0x03}) </s> add buf.PutUint8(1) buf.PutUint8(0) buf.PutUint16be(uint16(208 + len(data) + len(server))) buf.PutSlice([]byte{0x03, 0x03}) </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server)) </s> remove buf.Write([]byte{0x01, 0x00}) </s> add buf.PutSlice([]byte{0x01, 0x00}) </s> remove buf.Write([]byte{0x00, 0x23}) binary.Write(buf, binary.BigEndian, uint16(len(data))) buf.Write(data) </s> add buf.PutSlice([]byte{0x00, 0x23}) buf.PutUint16be(uint16(len(data))) buf.PutSlice(data)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x00, 0x38}) buf.PutSlice([]byte{
<mask> buf.WriteByte(32) <mask> buf.Write(sessionID) <mask> <mask> // cipher suites <mask> buf.Write([]byte{0x00, 0x38}) <mask> buf.Write([]byte{ <mask> 0xc0, 0x2c, 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f, <mask> 0x00, 0x9e, 0xc0, 0x24, 0xc0, 0x28, 0x00, 0x6b, 0xc0, 0x23, 0xc0, 0x27, 0x00, 0x67, 0xc0, 0x0a, <mask> 0xc0, 0x14, 0x00, 0x39, 0xc0, 0x09, 0xc0, 0x13, 0x00, 0x33, 0x00, 0x9d, 0x00, 0x9c, 0x00, 0x3d, <mask> 0x00, 0x3c, 0x00, 0x35, 0x00, 0x2f, 0x00, 0xff, <mask> }) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove binary.Write(buf, binary.BigEndian, uint32(time.Now().Unix())) buf.Write(random) buf.WriteByte(32) buf.Write(sessionID) </s> add buf.PutUint32be(uint32(time.Now().Unix())) buf.ReadFull(rand.Reader, 28) buf.PutUint8(32) buf.ReadFull(rand.Reader, 32) </s> remove buf.Write([]byte{0x01, 0x00}) </s> add buf.PutSlice([]byte{0x01, 0x00}) </s> remove buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> add buf.PutSlice([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> remove buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> add buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> remove buf.Write([]byte{ </s> add buf.PutSlice([]byte{
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x01, 0x00})
<mask> 0x00, 0x3c, 0x00, 0x35, 0x00, 0x2f, 0x00, 0xff, <mask> }) <mask> <mask> // compression <mask> buf.Write([]byte{0x01, 0x00}) <mask> <mask> // extension length <mask> binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) <mask> <mask> // session ticket </s> Chore: use protobytes replace most of bytes.Buffer </s> remove binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) </s> add buf.PutUint16be(uint16(79 + len(data) + len(server))) </s> remove buf.Write([]byte{0x00, 0x38}) buf.Write([]byte{ </s> add buf.PutSlice([]byte{0x00, 0x38}) buf.PutSlice([]byte{ </s> remove buf.Write([]byte{0x00, 0x23}) binary.Write(buf, binary.BigEndian, uint16(len(data))) buf.Write(data) </s> add buf.PutSlice([]byte{0x00, 0x23}) buf.PutUint16be(uint16(len(data))) buf.PutSlice(data) </s> remove buf.Write([]byte{0x00, 0x16, 0x00, 0x00}) </s> add buf.PutSlice([]byte{0x00, 0x16, 0x00, 0x00}) </s> remove buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> add buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02})
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutUint16be(uint16(79 + len(data) + len(server)))
<mask> // compression <mask> buf.Write([]byte{0x01, 0x00}) <mask> <mask> // extension length <mask> binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) <mask> <mask> // session ticket <mask> buf.Write([]byte{0x00, 0x23}) <mask> binary.Write(buf, binary.BigEndian, uint16(len(data))) <mask> buf.Write(data) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x23}) binary.Write(buf, binary.BigEndian, uint16(len(data))) buf.Write(data) </s> add buf.PutSlice([]byte{0x00, 0x23}) buf.PutUint16be(uint16(len(data))) buf.PutSlice(data) </s> remove buf.Write([]byte{0x01, 0x00}) </s> add buf.PutSlice([]byte{0x01, 0x00}) </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server)) </s> remove buf.WriteByte(0) </s> add buf.PutUint8(0) </s> remove binary.Write(buf, binary.BigEndian, uint32(time.Now().Unix())) buf.Write(random) buf.WriteByte(32) buf.Write(sessionID) </s> add buf.PutUint32be(uint32(time.Now().Unix())) buf.ReadFull(rand.Reader, 28) buf.PutUint8(32) buf.ReadFull(rand.Reader, 32)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x00, 0x23}) buf.PutUint16be(uint16(len(data))) buf.PutSlice(data)
<mask> // extension length <mask> binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) <mask> <mask> // session ticket <mask> buf.Write([]byte{0x00, 0x23}) <mask> binary.Write(buf, binary.BigEndian, uint16(len(data))) <mask> buf.Write(data) <mask> <mask> // server name <mask> buf.Write([]byte{0x00, 0x00}) <mask> binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) <mask> binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) </s> add buf.PutUint16be(uint16(79 + len(data) + len(server))) </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server)) </s> remove buf.Write([]byte{0x01, 0x00}) </s> add buf.PutSlice([]byte{0x01, 0x00}) </s> remove binary.Write(buf, binary.BigEndian, uint32(time.Now().Unix())) buf.Write(random) buf.WriteByte(32) buf.Write(sessionID) </s> add buf.PutUint32be(uint32(time.Now().Unix())) buf.ReadFull(rand.Reader, 28) buf.PutUint8(32) buf.ReadFull(rand.Reader, 32) </s> remove buf.WriteByte(0) </s> add buf.PutUint8(0)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server))
<mask> binary.Write(buf, binary.BigEndian, uint16(len(data))) <mask> buf.Write(data) <mask> <mask> // server name <mask> buf.Write([]byte{0x00, 0x00}) <mask> binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) <mask> binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) <mask> buf.WriteByte(0) <mask> binary.Write(buf, binary.BigEndian, uint16(len(server))) <mask> buf.Write([]byte(server)) <mask> <mask> // ec_point <mask> buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) <mask> <mask> // groups </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> add buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> remove buf.Write([]byte{0x00, 0x23}) binary.Write(buf, binary.BigEndian, uint16(len(data))) buf.Write(data) </s> add buf.PutSlice([]byte{0x00, 0x23}) buf.PutUint16be(uint16(len(data))) buf.PutSlice(data) </s> remove buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> add buf.PutSlice([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> remove binary.Write(buf, binary.BigEndian, uint16(79+len(data)+len(server))) </s> add buf.PutUint16be(uint16(79 + len(data) + len(server))) </s> remove buf.Write([]byte{ </s> add buf.PutSlice([]byte{
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02})
<mask> binary.Write(buf, binary.BigEndian, uint16(len(server))) <mask> buf.Write([]byte(server)) <mask> <mask> // ec_point <mask> buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) <mask> <mask> // groups <mask> buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) <mask> <mask> // signature </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> add buf.PutSlice([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> remove buf.Write([]byte{ </s> add buf.PutSlice([]byte{ </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server)) </s> remove buf.Write([]byte{0x00, 0x16, 0x00, 0x00}) </s> add buf.PutSlice([]byte{0x00, 0x16, 0x00, 0x00}) </s> remove buf.Write([]byte{0x00, 0x38}) buf.Write([]byte{ </s> add buf.PutSlice([]byte{0x00, 0x38}) buf.PutSlice([]byte{
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18})
<mask> // ec_point <mask> buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) <mask> <mask> // groups <mask> buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) <mask> <mask> // signature <mask> buf.Write([]byte{ <mask> 0x00, 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x01, 0x06, 0x02, 0x06, 0x03, 0x05, <mask> 0x01, 0x05, 0x02, 0x05, 0x03, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03, 0x03, 0x01, </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{ </s> add buf.PutSlice([]byte{ </s> remove buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> add buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> remove buf.Write([]byte{0x00, 0x16, 0x00, 0x00}) </s> add buf.PutSlice([]byte{0x00, 0x16, 0x00, 0x00}) </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server)) </s> remove buf.Write([]byte{0x00, 0x38}) buf.Write([]byte{ </s> add buf.PutSlice([]byte{0x00, 0x38}) buf.PutSlice([]byte{
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{
<mask> // groups <mask> buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) <mask> <mask> // signature <mask> buf.Write([]byte{ <mask> 0x00, 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x01, 0x06, 0x02, 0x06, 0x03, 0x05, <mask> 0x01, 0x05, 0x02, 0x05, 0x03, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03, 0x03, 0x01, <mask> 0x03, 0x02, 0x03, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03, <mask> }) <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> add buf.PutSlice([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> remove buf.Write([]byte{0x00, 0x16, 0x00, 0x00}) </s> add buf.PutSlice([]byte{0x00, 0x16, 0x00, 0x00}) </s> remove buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> add buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server)) </s> remove buf.Write([]byte{0x00, 0x38}) buf.Write([]byte{ </s> add buf.PutSlice([]byte{0x00, 0x38}) buf.PutSlice([]byte{
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x00, 0x16, 0x00, 0x00})
<mask> 0x03, 0x02, 0x03, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03, <mask> }) <mask> <mask> // encrypt then mac <mask> buf.Write([]byte{0x00, 0x16, 0x00, 0x00}) <mask> <mask> // extended master secret <mask> buf.Write([]byte{0x00, 0x17, 0x00, 0x00}) <mask> <mask> return buf.Bytes() </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{ </s> add buf.PutSlice([]byte{ </s> remove buf.Write([]byte{0x00, 0x17, 0x00, 0x00}) </s> add buf.PutSlice([]byte{0x00, 0x17, 0x00, 0x00}) </s> remove buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> add buf.PutSlice([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> remove buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> add buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server))
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
buf.PutSlice([]byte{0x00, 0x17, 0x00, 0x00})
<mask> // encrypt then mac <mask> buf.Write([]byte{0x00, 0x16, 0x00, 0x00}) <mask> <mask> // extended master secret <mask> buf.Write([]byte{0x00, 0x17, 0x00, 0x00}) <mask> <mask> return buf.Bytes() <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x16, 0x00, 0x00}) </s> add buf.PutSlice([]byte{0x00, 0x16, 0x00, 0x00}) </s> remove buf.Write([]byte{0x00, 0x00}) binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(len(server))) buf.Write([]byte(server)) </s> add buf.PutSlice([]byte{0x00, 0x00}) buf.PutUint16be(uint16(len(server) + 5)) buf.PutUint16be(uint16(len(server) + 3)) buf.PutUint8(0) buf.PutUint16be(uint16(len(server))) buf.PutSlice([]byte(server)) </s> remove buf.Write([]byte{0x01, 0x00}) </s> add buf.PutSlice([]byte{0x01, 0x00}) </s> remove buf.Write([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> add buf.PutSlice([]byte{0x00, 0x0b, 0x00, 0x04, 0x03, 0x01, 0x00, 0x02}) </s> remove buf.Write([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) </s> add buf.PutSlice([]byte{0x00, 0x0a, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18})
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/simple-obfs/tls.go
<mask> package snell <mask> <mask> import ( <mask> "encoding/binary" <mask> "errors" <mask> "fmt" <mask> "io" <mask> "net" <mask> "sync" </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "bytes" "encoding/binary" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutUint8(Version)
<mask> return 0, fmt.Errorf("server reported code: %d, message: %s", errcode, string(msg)) <mask> } <mask> <mask> func WriteHeader(conn net.Conn, host string, port uint, version int) error { <mask> buf := pool.GetBuffer() <mask> defer pool.PutBuffer(buf) <mask> buf.WriteByte(Version) <mask> if version == Version2 { <mask> buf.WriteByte(CommandConnectV2) <mask> } else { <mask> buf.WriteByte(CommandConnect) <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2) </s> remove buf.WriteByte(CommandConnect) </s> add buf.PutUint8(CommandConnect) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(t.hexPassword) buf.Write(crlf) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(t.hexPassword) buf.PutSlice(crlf) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(socks5Addr) binary.Write(buf, binary.BigEndian, uint16(len(payload))) buf.Write(crlf) buf.Write(payload) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(socks5Addr) buf.PutUint16be(uint16(len(payload))) buf.PutSlice(crlf) buf.PutSlice(payload) </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutUint8(CommandConnectV2)
<mask> buf := pool.GetBuffer() <mask> defer pool.PutBuffer(buf) <mask> buf.WriteByte(Version) <mask> if version == Version2 { <mask> buf.WriteByte(CommandConnectV2) <mask> } else { <mask> buf.WriteByte(CommandConnect) <mask> } <mask> <mask> // clientID length & id </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(CommandConnect) </s> add buf.PutUint8(CommandConnect) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.WriteByte(Version) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutUint8(Version) </s> remove buf.WriteByte(0) </s> add buf.PutUint8(0) </s> remove buf.WriteByte(uint8(len(host))) buf.WriteString(host) binary.Write(buf, binary.BigEndian, uint16(port)) </s> add buf.PutUint8(uint8(len(host))) buf.PutString(host) buf.PutUint16be(uint16(port)) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(t.hexPassword) buf.Write(crlf) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(t.hexPassword) buf.PutSlice(crlf)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutUint8(CommandConnect)
<mask> buf.WriteByte(Version) <mask> if version == Version2 { <mask> buf.WriteByte(CommandConnectV2) <mask> } else { <mask> buf.WriteByte(CommandConnect) <mask> } <mask> <mask> // clientID length & id <mask> buf.WriteByte(0) <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2) </s> remove buf.WriteByte(0) </s> add buf.PutUint8(0) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.WriteByte(Version) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) buf.PutUint8(Version) </s> remove buf.WriteByte(uint8(len(host))) buf.WriteString(host) binary.Write(buf, binary.BigEndian, uint16(port)) </s> add buf.PutUint8(uint8(len(host))) buf.PutString(host) buf.PutUint16be(uint16(port)) </s> remove buf.WriteByte(CommandTCP) </s> add buf.PutUint8(CommandTCP)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutUint8(0)
<mask> buf.WriteByte(CommandConnect) <mask> } <mask> <mask> // clientID length & id <mask> buf.WriteByte(0) <mask> <mask> // host & port <mask> buf.WriteByte(uint8(len(host))) <mask> buf.WriteString(host) <mask> binary.Write(buf, binary.BigEndian, uint16(port)) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(uint8(len(host))) buf.WriteString(host) binary.Write(buf, binary.BigEndian, uint16(port)) </s> add buf.PutUint8(uint8(len(host))) buf.PutString(host) buf.PutUint16be(uint16(port)) </s> remove buf.WriteByte(CommandConnect) </s> add buf.PutUint8(CommandConnect) </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2) </s> remove buf.WriteByte(byte(length >> 8)) buf.WriteByte(byte(length & 0xff)) </s> add buf.PutUint16be(length) </s> remove buf.WriteByte(1) buf.WriteByte(0) binary.Write(buf, binary.BigEndian, uint16(208+len(data)+len(server))) buf.Write([]byte{0x03, 0x03}) </s> add buf.PutUint8(1) buf.PutUint8(0) buf.PutUint16be(uint16(208 + len(data) + len(server))) buf.PutSlice([]byte{0x03, 0x03})
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutUint8(uint8(len(host))) buf.PutString(host) buf.PutUint16be(uint16(port))
<mask> // clientID length & id <mask> buf.WriteByte(0) <mask> <mask> // host & port <mask> buf.WriteByte(uint8(len(host))) <mask> buf.WriteString(host) <mask> binary.Write(buf, binary.BigEndian, uint16(port)) <mask> <mask> if _, err := conn.Write(buf.Bytes()); err != nil { <mask> return err <mask> } <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(0) </s> add buf.PutUint8(0) </s> remove buf.WriteByte(CommandConnect) </s> add buf.PutUint8(CommandConnect) </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2) </s> remove ip := net.ParseIP(option.Host) if ip == nil { buf.WriteByte(0x2) buf.WriteString(option.Host) } else if ipv4 := ip.To4(); ipv4 != nil { buf.WriteByte(0x1) buf.Write(ipv4) </s> add ip, err := netip.ParseAddr(option.Host) if err != nil { buf.PutUint8(0x2) buf.PutString(option.Host) } else if ip.Is4() { buf.PutUint8(0x1) buf.PutSlice(ip.AsSlice()) </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf)
<mask> } <mask> } <mask> <mask> func writePacket(w io.Writer, socks5Addr, payload []byte) (int, error) { <mask> buf := pool.GetBuffer() <mask> defer pool.PutBuffer(buf) <mask> <mask> // compose snell UDP address format (refer: icpz/snell-server-reversed) <mask> // a brand new wheel to replace socks5 address format, well done Yachen <mask> buf.WriteByte(CommondUDPForward) <mask> switch socks5Addr[0] { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.WriteByte(CommondUDPForward) </s> add buf.PutUint8(CommondUDPForward) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(socks5Addr) binary.Write(buf, binary.BigEndian, uint16(len(payload))) buf.Write(crlf) buf.Write(payload) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(socks5Addr) buf.PutUint16be(uint16(len(payload))) buf.PutSlice(crlf) buf.PutSlice(payload) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(t.hexPassword) buf.Write(crlf) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(t.hexPassword) buf.PutSlice(crlf) </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove buf.WriteByte(CommandConnectV2) </s> add buf.PutUint8(CommandConnectV2)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutUint8(CommondUDPForward)
<mask> defer pool.PutBuffer(buf) <mask> <mask> // compose snell UDP address format (refer: icpz/snell-server-reversed) <mask> // a brand new wheel to replace socks5 address format, well done Yachen <mask> buf.WriteByte(CommondUDPForward) <mask> switch socks5Addr[0] { <mask> case socks5.AtypDomainName: <mask> hostLen := socks5Addr[1] <mask> buf.Write(socks5Addr[1 : 1+1+hostLen+2]) <mask> case socks5.AtypIPv4: </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) </s> remove buf.Write(socks5Addr[1 : 1+1+hostLen+2]) </s> add buf.PutSlice(socks5Addr[1 : 1+1+hostLen+2]) </s> remove buf.Write([]byte{0x00, 0x04}) buf.Write(socks5Addr[1 : 1+net.IPv4len+2]) </s> add buf.PutSlice([]byte{0x00, 0x04}) buf.PutSlice(socks5Addr[1 : 1+net.IPv4len+2]) </s> remove buf.Write([]byte{0x00, 0x06}) buf.Write(socks5Addr[1 : 1+net.IPv6len+2]) </s> add buf.PutSlice([]byte{0x00, 0x06}) buf.PutSlice(socks5Addr[1 : 1+net.IPv6len+2]) </s> remove host := metadata.DstIP.To16() buf = [][]byte{{aType}, host, port} </s> add buf.PutSlice(metadata.DstIP.To16())
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutSlice(socks5Addr[1 : 1+1+hostLen+2])
<mask> buf.WriteByte(CommondUDPForward) <mask> switch socks5Addr[0] { <mask> case socks5.AtypDomainName: <mask> hostLen := socks5Addr[1] <mask> buf.Write(socks5Addr[1 : 1+1+hostLen+2]) <mask> case socks5.AtypIPv4: <mask> buf.Write([]byte{0x00, 0x04}) <mask> buf.Write(socks5Addr[1 : 1+net.IPv4len+2]) <mask> case socks5.AtypIPv6: <mask> buf.Write([]byte{0x00, 0x06}) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x04}) buf.Write(socks5Addr[1 : 1+net.IPv4len+2]) </s> add buf.PutSlice([]byte{0x00, 0x04}) buf.PutSlice(socks5Addr[1 : 1+net.IPv4len+2]) </s> remove buf.Write([]byte{0x00, 0x06}) buf.Write(socks5Addr[1 : 1+net.IPv6len+2]) </s> add buf.PutSlice([]byte{0x00, 0x06}) buf.PutSlice(socks5Addr[1 : 1+net.IPv6len+2]) </s> remove buf.WriteByte(CommondUDPForward) </s> add buf.PutUint8(CommondUDPForward) </s> remove buf.Write(payload) </s> add buf.PutSlice(payload) </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutSlice([]byte{0x00, 0x04}) buf.PutSlice(socks5Addr[1 : 1+net.IPv4len+2])
<mask> case socks5.AtypDomainName: <mask> hostLen := socks5Addr[1] <mask> buf.Write(socks5Addr[1 : 1+1+hostLen+2]) <mask> case socks5.AtypIPv4: <mask> buf.Write([]byte{0x00, 0x04}) <mask> buf.Write(socks5Addr[1 : 1+net.IPv4len+2]) <mask> case socks5.AtypIPv6: <mask> buf.Write([]byte{0x00, 0x06}) <mask> buf.Write(socks5Addr[1 : 1+net.IPv6len+2]) <mask> } <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write(socks5Addr[1 : 1+1+hostLen+2]) </s> add buf.PutSlice(socks5Addr[1 : 1+1+hostLen+2]) </s> remove buf.Write([]byte{0x00, 0x06}) buf.Write(socks5Addr[1 : 1+net.IPv6len+2]) </s> add buf.PutSlice([]byte{0x00, 0x06}) buf.PutSlice(socks5Addr[1 : 1+net.IPv6len+2]) </s> remove buf.WriteByte(CommondUDPForward) </s> add buf.PutUint8(CommondUDPForward) </s> remove buf.Write(payload) </s> add buf.PutSlice(payload) </s> remove len := uint8(len(metadata.Host)) host := []byte(metadata.Host) buf = [][]byte{{aType, len}, host, port} </s> add buf.PutUint8(uint8(len(metadata.Host))) buf.PutString(metadata.Host)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutSlice([]byte{0x00, 0x06}) buf.PutSlice(socks5Addr[1 : 1+net.IPv6len+2])
<mask> case socks5.AtypIPv4: <mask> buf.Write([]byte{0x00, 0x04}) <mask> buf.Write(socks5Addr[1 : 1+net.IPv4len+2]) <mask> case socks5.AtypIPv6: <mask> buf.Write([]byte{0x00, 0x06}) <mask> buf.Write(socks5Addr[1 : 1+net.IPv6len+2]) <mask> } <mask> <mask> buf.Write(payload) <mask> _, err := w.Write(buf.Bytes()) <mask> if err != nil { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x04}) buf.Write(socks5Addr[1 : 1+net.IPv4len+2]) </s> add buf.PutSlice([]byte{0x00, 0x04}) buf.PutSlice(socks5Addr[1 : 1+net.IPv4len+2]) </s> remove buf.Write(socks5Addr[1 : 1+1+hostLen+2]) </s> add buf.PutSlice(socks5Addr[1 : 1+1+hostLen+2]) </s> remove buf.Write(payload) </s> add buf.PutSlice(payload) </s> remove buf.WriteByte(CommondUDPForward) </s> add buf.PutUint8(CommondUDPForward) </s> remove return bytes.Join(buf, nil) </s> add buf.PutUint16be(uint16(p)) return buf.Bytes()
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
buf.PutSlice(payload)
<mask> buf.Write([]byte{0x00, 0x06}) <mask> buf.Write(socks5Addr[1 : 1+net.IPv6len+2]) <mask> } <mask> <mask> buf.Write(payload) <mask> _, err := w.Write(buf.Bytes()) <mask> if err != nil { <mask> return 0, err <mask> } <mask> return len(payload), nil </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf.Write([]byte{0x00, 0x06}) buf.Write(socks5Addr[1 : 1+net.IPv6len+2]) </s> add buf.PutSlice([]byte{0x00, 0x06}) buf.PutSlice(socks5Addr[1 : 1+net.IPv6len+2]) </s> remove buf.Write([]byte{0x00, 0x04}) buf.Write(socks5Addr[1 : 1+net.IPv4len+2]) </s> add buf.PutSlice([]byte{0x00, 0x04}) buf.PutSlice(socks5Addr[1 : 1+net.IPv4len+2]) </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove buf.Write(socks5Addr[1 : 1+1+hostLen+2]) </s> add buf.PutSlice(socks5Addr[1 : 1+1+hostLen+2]) </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/snell/snell.go
<mask> package socks4 <mask> <mask> import ( <mask> "bytes" <mask> "encoding/binary" <mask> "errors" <mask> "io" <mask> "net" <mask> "strconv" <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "bytes" </s> add </s> remove "encoding/binary" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add </s> remove "bytes" </s> add
[ "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
"net/netip"
<mask> "io" <mask> "net" <mask> "strconv" <mask> <mask> "github.com/Dreamacro/clash/component/auth" <mask> <mask> "github.com/Dreamacro/protobytes" </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "bytes" "encoding/binary" </s> add </s> remove "bytes" </s> add
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
"github.com/Dreamacro/protobytes"
<mask> <mask> "github.com/Dreamacro/clash/component/auth" <mask> ) <mask> <mask> const Version = 0x04 <mask> </s> Chore: use protobytes replace most of bytes.Buffer
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
r := protobytes.BytesReader(req[:]) if r.ReadUint8() != Version {
<mask> if _, err = io.ReadFull(rw, req[:]); err != nil { <mask> return <mask> } <mask> <mask> if req[0] != Version { <mask> err = errVersionMismatched <mask> return <mask> } <mask> <mask> if command = req[1]; command != CmdConnect { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if command = req[1]; command != CmdConnect { </s> add if command = r.ReadUint8(); command != CmdConnect { </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) { </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove buf.Write(payload) </s> add buf.PutSlice(payload) </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
if command = r.ReadUint8(); command != CmdConnect {
<mask> err = errVersionMismatched <mask> return <mask> } <mask> <mask> if command = req[1]; command != CmdConnect { <mask> err = errCommandNotSupported <mask> return <mask> } <mask> <mask> var ( </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if req[0] != Version { </s> add r := protobytes.BytesReader(req[:]) if r.ReadUint8() != Version { </s> remove var ( dstIP = req[4:8] // [4]byte dstPort = req[2:4] // [2]byte ) </s> add </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) { </s> remove if packet[2] != 0 /* fragments */ { </s> add if r.ReadUint8() != 0 /* fragments */ { </s> remove addr = make([]byte, 1+1+len(host)+2) addr[0] = AtypDomainName addr[1] = byte(len(host)) copy(addr[2:], host) </s> add buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
<mask> err = errCommandNotSupported <mask> return <mask> } <mask> <mask> var ( <mask> dstIP = req[4:8] // [4]byte <mask> dstPort = req[2:4] // [2]byte <mask> ) <mask> <mask> var ( <mask> host string <mask> port string <mask> code uint8 <mask> userID []byte </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if command = req[1]; command != CmdConnect { </s> add if command = r.ReadUint8(); command != CmdConnect { </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) { </s> remove var reply [8]byte reply[0] = 0x00 // reply code reply[1] = code // result code copy(reply[4:8], dstIP) copy(reply[2:4], dstPort) </s> add reply := protobytes.BytesWriter(make([]byte, 0, 8)) reply.PutUint8(0) // reply code reply.PutUint8(code) // result code reply.PutSlice(dstAddr.AsSlice()) reply.PutUint16be(dstPort) </s> remove var bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} </s> add var ( bufferPool = sync.Pool{New: func() any { return &bytes.Buffer{} }} bytesBufferPool = sync.Pool{New: func() any { return &protobytes.BytesWriter{} }} )
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) {
<mask> if userID, err = readUntilNull(rw); err != nil { <mask> return <mask> } <mask> <mask> if isReservedIP(dstIP) { <mask> var target []byte <mask> if target, err = readUntilNull(rw); err != nil { <mask> return <mask> } <mask> host = string(target) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if req[0] != Version { </s> add r := protobytes.BytesReader(req[:]) if r.ReadUint8() != Version { </s> remove if command = req[1]; command != CmdConnect { </s> add if command = r.ReadUint8(); command != CmdConnect { </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove addr = make([]byte, 1+1+len(host)+2) addr[0] = AtypDomainName addr[1] = byte(len(host)) copy(addr[2:], host) </s> add buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
port = strconv.Itoa(int(dstPort))
<mask> } <mask> host = string(target) <mask> } <mask> <mask> port = strconv.Itoa(int(binary.BigEndian.Uint16(dstPort))) <mask> if host != "" { <mask> addr = net.JoinHostPort(host, port) <mask> } else { <mask> addr = net.JoinHostPort(net.IP(dstIP).String(), port) <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove addr = net.JoinHostPort(net.IP(dstIP).String(), port) </s> add addr = net.JoinHostPort(dstAddr.String(), port) </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip) </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) { </s> remove addr = SplitAddr(packet[3:]) </s> add addr = SplitAddr(r)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
addr = net.JoinHostPort(dstAddr.String(), port)
<mask> port = strconv.Itoa(int(binary.BigEndian.Uint16(dstPort))) <mask> if host != "" { <mask> addr = net.JoinHostPort(host, port) <mask> } else { <mask> addr = net.JoinHostPort(net.IP(dstIP).String(), port) <mask> } <mask> <mask> // SOCKS4 only support USERID auth. <mask> if authenticator == nil || authenticator.Verify(string(userID), "") { <mask> code = RequestGranted </s> Chore: use protobytes replace most of bytes.Buffer </s> remove port = strconv.Itoa(int(binary.BigEndian.Uint16(dstPort))) </s> add port = strconv.Itoa(int(dstPort)) </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip) </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove addr = SplitAddr(packet[3:]) </s> add addr = SplitAddr(r)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
reply := protobytes.BytesWriter(make([]byte, 0, 8)) reply.PutUint8(0) // reply code reply.PutUint8(code) // result code reply.PutSlice(dstAddr.AsSlice()) reply.PutUint16be(dstPort)
<mask> code = RequestIdentdMismatched <mask> err = ErrRequestIdentdMismatched <mask> } <mask> <mask> var reply [8]byte <mask> reply[0] = 0x00 // reply code <mask> reply[1] = code // result code <mask> copy(reply[4:8], dstIP) <mask> copy(reply[2:4], dstPort) <mask> <mask> _, wErr := rw.Write(reply[:]) <mask> if err == nil { <mask> err = wErr <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove _, wErr := rw.Write(reply[:]) </s> add _, wErr := rw.Write(reply.Bytes()) </s> remove var ( dstIP = req[4:8] // [4]byte dstPort = req[2:4] // [2]byte ) </s> add </s> remove addr = net.JoinHostPort(net.IP(dstIP).String(), port) </s> add addr = net.JoinHostPort(dstAddr.String(), port) </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
_, wErr := rw.Write(reply.Bytes())
<mask> reply[1] = code // result code <mask> copy(reply[4:8], dstIP) <mask> copy(reply[2:4], dstPort) <mask> <mask> _, wErr := rw.Write(reply[:]) <mask> if err == nil { <mask> err = wErr <mask> } <mask> return <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove var reply [8]byte reply[0] = 0x00 // reply code reply[1] = code // result code copy(reply[4:8], dstIP) copy(reply[2:4], dstPort) </s> add reply := protobytes.BytesWriter(make([]byte, 0, 8)) reply.PutUint8(0) // reply code reply.PutUint8(code) // result code reply.PutSlice(dstAddr.AsSlice()) reply.PutUint16be(dstPort) </s> remove addr = net.JoinHostPort(net.IP(dstIP).String(), port) </s> add addr = net.JoinHostPort(dstAddr.String(), port) </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove var ( dstIP = req[4:8] // [4]byte dstPort = req[2:4] // [2]byte ) </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6
<mask> if err != nil { <mask> return err <mask> } <mask> <mask> ip := net.ParseIP(host) <mask> if ip == nil /* HOST */ { <mask> ip = net.IPv4(0, 0, 0, 1).To4() <mask> } else if ip.To4() == nil /* IPv6 */ { <mask> return errIPv6NotSupported <mask> } <mask> <mask> dstIP := ip.To4() <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove dstIP := ip.To4() </s> add req := protobytes.BytesWriter{} req.PutUint8(Version) req.PutUint8(command) req.PutUint16be(uint16(port)) req.Write(ip.AsSlice()) req.PutString(userID) req.PutUint8(0) /* NULL */ </s> remove req := &bytes.Buffer{} req.WriteByte(Version) req.WriteByte(command) binary.Write(req, binary.BigEndian, uint16(port)) req.Write(dstIP) req.WriteString(userID) req.WriteByte(0) /* NULL */ if isReservedIP(dstIP) /* SOCKS4A */ { req.WriteString(host) req.WriteByte(0) /* NULL */ </s> add if isReservedIP(ip) /* SOCKS4A */ { req.PutString(host) req.PutUint8(0) /* NULL */ </s> remove ip := net.ParseIP(option.Host) if ip == nil { buf.WriteByte(0x2) buf.WriteString(option.Host) } else if ipv4 := ip.To4(); ipv4 != nil { buf.WriteByte(0x1) buf.Write(ipv4) </s> add ip, err := netip.ParseAddr(option.Host) if err != nil { buf.PutUint8(0x2) buf.PutString(option.Host) } else if ip.Is4() { buf.PutUint8(0x1) buf.PutSlice(ip.AsSlice()) </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove binary.Write(buf, binary.BigEndian, option.Port) </s> add buf.PutUint16be(option.Port)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
req := protobytes.BytesWriter{} req.PutUint8(Version) req.PutUint8(command) req.PutUint16be(uint16(port)) req.Write(ip.AsSlice()) req.PutString(userID) req.PutUint8(0) /* NULL */
<mask> } else if ip.To4() == nil /* IPv6 */ { <mask> return errIPv6NotSupported <mask> } <mask> <mask> dstIP := ip.To4() <mask> <mask> req := &bytes.Buffer{} <mask> req.WriteByte(Version) <mask> req.WriteByte(command) <mask> binary.Write(req, binary.BigEndian, uint16(port)) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove req := &bytes.Buffer{} req.WriteByte(Version) req.WriteByte(command) binary.Write(req, binary.BigEndian, uint16(port)) req.Write(dstIP) req.WriteString(userID) req.WriteByte(0) /* NULL */ if isReservedIP(dstIP) /* SOCKS4A */ { req.WriteString(host) req.WriteByte(0) /* NULL */ </s> add if isReservedIP(ip) /* SOCKS4A */ { req.PutString(host) req.PutUint8(0) /* NULL */ </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove ip := net.ParseIP(option.Host) if ip == nil { buf.WriteByte(0x2) buf.WriteString(option.Host) } else if ipv4 := ip.To4(); ipv4 != nil { buf.WriteByte(0x1) buf.Write(ipv4) </s> add ip, err := netip.ParseAddr(option.Host) if err != nil { buf.PutUint8(0x2) buf.PutString(option.Host) } else if ip.Is4() { buf.PutUint8(0x1) buf.PutSlice(ip.AsSlice()) </s> remove if packet[2] != 0 /* fragments */ { </s> add if r.ReadUint8() != 0 /* fragments */ { </s> remove if !bytes.Equal(packet[:2], []byte{0, 0}) { </s> add reserved, r := r.SplitAt(2) if !bytes.Equal(reserved, []byte{0, 0}) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
if isReservedIP(ip) /* SOCKS4A */ { req.PutString(host) req.PutUint8(0) /* NULL */
<mask> } <mask> <mask> dstIP := ip.To4() <mask> <mask> req := &bytes.Buffer{} <mask> req.WriteByte(Version) <mask> req.WriteByte(command) <mask> binary.Write(req, binary.BigEndian, uint16(port)) <mask> req.Write(dstIP) <mask> req.WriteString(userID) <mask> req.WriteByte(0) /* NULL */ <mask> <mask> if isReservedIP(dstIP) /* SOCKS4A */ { <mask> req.WriteString(host) <mask> req.WriteByte(0) /* NULL */ <mask> } <mask> <mask> if _, err = rw.Write(req.Bytes()); err != nil { <mask> return err <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove dstIP := ip.To4() </s> add req := protobytes.BytesWriter{} req.PutUint8(Version) req.PutUint8(command) req.PutUint16be(uint16(port)) req.Write(ip.AsSlice()) req.PutString(userID) req.PutUint8(0) /* NULL */ </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove if packet[2] != 0 /* fragments */ { </s> add if r.ReadUint8() != 0 /* fragments */ { </s> remove if !bytes.Equal(packet[:2], []byte{0, 0}) { </s> add reserved, r := r.SplitAt(2) if !bytes.Equal(reserved, []byte{0, 0}) { </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
func isReservedIP(ip netip.Addr) bool { subnet := netip.PrefixFrom( netip.AddrFrom4([4]byte{0, 0, 0, 0}), 24, )
<mask> // to IP address 0.0.0.x, with x nonzero. As decreed by IANA -- The <mask> // Internet Assigned Numbers Authority -- such an address is inadmissible <mask> // as a destination IP address and thus should never occur if the client <mask> // can resolve the domain name.) <mask> func isReservedIP(ip net.IP) bool { <mask> subnet := net.IPNet{ <mask> IP: net.IPv4zero, <mask> Mask: net.IPv4Mask(0xff, 0xff, 0xff, 0x00), <mask> } <mask> <mask> return !ip.IsUnspecified() && subnet.Contains(ip) <mask> } <mask> <mask> func readUntilNull(r io.Reader) ([]byte, error) { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) </s> remove var addr Addr </s> add buf := protobytes.BytesWriter{} </s> remove if len(packet) < 5 { </s> add r := protobytes.BytesReader(packet) if r.Len() < 5 { </s> remove return bytes.Join(buf, nil) </s> add buf.PutUint16be(uint16(p)) return buf.Bytes()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
buf := protobytes.BytesWriter{}
<mask> return !ip.IsUnspecified() && subnet.Contains(ip) <mask> } <mask> <mask> func readUntilNull(r io.Reader) ([]byte, error) { <mask> buf := &bytes.Buffer{} <mask> var data [1]byte <mask> <mask> for { <mask> if _, err := r.Read(data[:]); err != nil { <mask> return nil, err </s> Chore: use protobytes replace most of bytes.Buffer </s> remove authMsg := &bytes.Buffer{} authMsg.WriteByte(1) authMsg.WriteByte(uint8(len(user.Username))) authMsg.WriteString(user.Username) authMsg.WriteByte(uint8(len(user.Password))) authMsg.WriteString(user.Password) </s> add authMsg := protobytes.BytesWriter{} authMsg.PutUint8(1) authMsg.PutUint8(uint8(len(user.Username))) authMsg.PutString(user.Username) authMsg.PutUint8(uint8(len(user.Password))) authMsg.PutString(user.Password) </s> remove func isReservedIP(ip net.IP) bool { subnet := net.IPNet{ IP: net.IPv4zero, Mask: net.IPv4Mask(0xff, 0xff, 0xff, 0x00), } </s> add func isReservedIP(ip netip.Addr) bool { subnet := netip.PrefixFrom( netip.AddrFrom4([4]byte{0, 0, 0, 0}), 24, ) </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove if err := json.NewEncoder(buf).Encode(Traffic{ </s> add if err := json.NewEncoder(&buf).Encode(Traffic{ </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
buf.PutUint8(data[0])
<mask> } <mask> if data[0] == 0 { <mask> return buf.Bytes(), nil <mask> } <mask> buf.WriteByte(data[0]) <mask> } <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if packet[2] != 0 /* fragments */ { </s> add if r.ReadUint8() != 0 /* fragments */ { </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove ip := net.ParseIP(option.Host) if ip == nil { buf.WriteByte(0x2) buf.WriteString(option.Host) } else if ipv4 := ip.To4(); ipv4 != nil { buf.WriteByte(0x1) buf.Write(ipv4) </s> add ip, err := netip.ParseAddr(option.Host) if err != nil { buf.PutUint8(0x2) buf.PutString(option.Host) } else if ip.Is4() { buf.PutUint8(0x1) buf.PutSlice(ip.AsSlice()) </s> remove buf.WriteByte(CommandConnect) </s> add buf.PutUint8(CommandConnect)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks4/socks4.go
"github.com/Dreamacro/protobytes"
<mask> "strconv" <mask> <mask> "github.com/Dreamacro/clash/component/auth" <mask> ) <mask> <mask> // Error represents a SOCKS error <mask> type Error byte <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf bytes.Buffer </s> add buf protobytes.BytesWriter
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
authMsg := protobytes.BytesWriter{} authMsg.PutUint8(1) authMsg.PutUint8(uint8(len(user.Username))) authMsg.PutString(user.Username) authMsg.PutUint8(uint8(len(user.Password))) authMsg.PutString(user.Password)
<mask> return nil, ErrAuth <mask> } <mask> <mask> // password protocol version <mask> authMsg := &bytes.Buffer{} <mask> authMsg.WriteByte(1) <mask> authMsg.WriteByte(uint8(len(user.Username))) <mask> authMsg.WriteString(user.Username) <mask> authMsg.WriteByte(uint8(len(user.Password))) <mask> authMsg.WriteString(user.Password) <mask> <mask> if _, err := rw.Write(authMsg.Bytes()); err != nil { <mask> return nil, err <mask> } <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if err := json.NewEncoder(buf).Encode(snapshot); err != nil { </s> add if err := json.NewEncoder(&buf).Encode(snapshot); err != nil { </s> remove buf.Write(payload) </s> add buf.PutSlice(payload) </s> remove buf := &bytes.Buffer{} </s> add buf := protobytes.BytesWriter{} </s> remove if req[0] != Version { </s> add r := protobytes.BytesReader(req[:]) if r.ReadUint8() != Version {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
buf := protobytes.BytesWriter{}
<mask> } <mask> <mask> // ParseAddr parses the address in string s. Returns nil if failed. <mask> func ParseAddr(s string) Addr { <mask> var addr Addr <mask> host, port, err := net.SplitHostPort(s) <mask> if err != nil { <mask> return nil <mask> } <mask> if ip := net.ParseIP(host); ip != nil { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove return bytes.Join(buf, nil) </s> add buf.PutUint16be(uint16(p)) return buf.Bytes() </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove ip := net.ParseIP(option.Host) if ip == nil { buf.WriteByte(0x2) buf.WriteString(option.Host) } else if ipv4 := ip.To4(); ipv4 != nil { buf.WriteByte(0x1) buf.Write(ipv4) </s> add ip, err := netip.ParseAddr(option.Host) if err != nil { buf.PutUint8(0x2) buf.PutString(option.Host) } else if ip.Is4() { buf.PutUint8(0x1) buf.PutSlice(ip.AsSlice()) </s> remove binary.Write(buf, binary.BigEndian, option.Port) </s> add buf.PutUint16be(option.Port)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
buf.PutUint8(AtypIPv4) buf.PutSlice(ip4)
<mask> return nil <mask> } <mask> if ip := net.ParseIP(host); ip != nil { <mask> if ip4 := ip.To4(); ip4 != nil { <mask> addr = make([]byte, 1+net.IPv4len+2) <mask> addr[0] = AtypIPv4 <mask> copy(addr[1:], ip4) <mask> } else { <mask> addr = make([]byte, 1+net.IPv6len+2) <mask> addr[0] = AtypIPv6 <mask> copy(addr[1:], ip) <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip) </s> remove parsed = make([]byte, 1+net.IPv4len+2) parsed[0] = AtypIPv4 copy(parsed[1:], ip4) binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv4len+2) parsed.PutUint8(AtypIPv4) parsed.PutSlice(ip4) parsed.PutUint16be(uint16(port)) </s> remove var parsed Addr </s> add var parsed protobytes.BytesWriter </s> remove addr = make([]byte, 1+1+len(host)+2) addr[0] = AtypDomainName addr[1] = byte(len(host)) copy(addr[2:], host) </s> add buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host) </s> remove var addr Addr </s> add buf := protobytes.BytesWriter{}
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
buf.PutUint8(AtypIPv6) buf.PutSlice(ip)
<mask> addr = make([]byte, 1+net.IPv4len+2) <mask> addr[0] = AtypIPv4 <mask> copy(addr[1:], ip4) <mask> } else { <mask> addr = make([]byte, 1+net.IPv6len+2) <mask> addr[0] = AtypIPv6 <mask> copy(addr[1:], ip) <mask> } <mask> } else { <mask> if len(host) > 255 { <mask> return nil <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove addr = make([]byte, 1+1+len(host)+2) addr[0] = AtypDomainName addr[1] = byte(len(host)) copy(addr[2:], host) </s> add buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host) </s> remove parsed = make([]byte, 1+net.IPv4len+2) parsed[0] = AtypIPv4 copy(parsed[1:], ip4) binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv4len+2) parsed.PutUint8(AtypIPv4) parsed.PutSlice(ip4) parsed.PutUint16be(uint16(port)) </s> remove parsed = make([]byte, 1+net.IPv6len+2) parsed[0] = AtypIPv6 copy(parsed[1:], hostip) binary.BigEndian.PutUint16(parsed[1+net.IPv6len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv6len+2) parsed.PutUint8(AtypIPv6) parsed.PutSlice(hostip) parsed.PutUint16be(uint16(port)) </s> remove var parsed Addr </s> add var parsed protobytes.BytesWriter
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host)
<mask> } else { <mask> if len(host) > 255 { <mask> return nil <mask> } <mask> addr = make([]byte, 1+1+len(host)+2) <mask> addr[0] = AtypDomainName <mask> addr[1] = byte(len(host)) <mask> copy(addr[2:], host) <mask> } <mask> <mask> portnum, err := strconv.ParseUint(port, 10, 16) <mask> if err != nil { <mask> return nil </s> Chore: use protobytes replace most of bytes.Buffer </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip) </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove if isReservedIP(dstIP) { </s> add dstAddr := r.ReadIPv4() dstPort := r.ReadUint16be() if isReservedIP(dstAddr) { </s> remove if req[0] != Version { </s> add r := protobytes.BytesReader(req[:]) if r.ReadUint8() != Version {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
buf.PutUint16be(uint16(portnum)) return Addr(buf.Bytes())
<mask> if err != nil { <mask> return nil <mask> } <mask> <mask> addr[len(addr)-2], addr[len(addr)-1] = byte(portnum>>8), byte(portnum) <mask> <mask> return addr <mask> } <mask> <mask> // ParseAddrToSocksAddr parse a socks addr from net.addr <mask> // This is a fast path of ParseAddr(addr.String()) <mask> func ParseAddrToSocksAddr(addr net.Addr) Addr { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove var addr Addr </s> add buf := protobytes.BytesWriter{} </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove if len(packet) < 5 { </s> add r := protobytes.BytesReader(packet) if r.Len() < 5 { </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove addr = SplitAddr(packet[3:]) </s> add addr = SplitAddr(r)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
var parsed protobytes.BytesWriter
<mask> if hostip == nil { <mask> return ParseAddr(addr.String()) <mask> } <mask> <mask> var parsed Addr <mask> if ip4 := hostip.To4(); ip4.DefaultMask() != nil { <mask> parsed = make([]byte, 1+net.IPv4len+2) <mask> parsed[0] = AtypIPv4 <mask> copy(parsed[1:], ip4) <mask> binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove parsed = make([]byte, 1+net.IPv4len+2) parsed[0] = AtypIPv4 copy(parsed[1:], ip4) binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv4len+2) parsed.PutUint8(AtypIPv4) parsed.PutSlice(ip4) parsed.PutUint16be(uint16(port)) </s> remove parsed = make([]byte, 1+net.IPv6len+2) parsed[0] = AtypIPv6 copy(parsed[1:], hostip) binary.BigEndian.PutUint16(parsed[1+net.IPv6len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv6len+2) parsed.PutUint8(AtypIPv6) parsed.PutSlice(hostip) parsed.PutUint16be(uint16(port)) </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove return parsed </s> add return Addr(parsed) </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
parsed = make([]byte, 0, 1+net.IPv4len+2) parsed.PutUint8(AtypIPv4) parsed.PutSlice(ip4) parsed.PutUint16be(uint16(port))
<mask> } <mask> <mask> var parsed Addr <mask> if ip4 := hostip.To4(); ip4.DefaultMask() != nil { <mask> parsed = make([]byte, 1+net.IPv4len+2) <mask> parsed[0] = AtypIPv4 <mask> copy(parsed[1:], ip4) <mask> binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) <mask> <mask> } else { <mask> parsed = make([]byte, 1+net.IPv6len+2) <mask> parsed[0] = AtypIPv6 <mask> copy(parsed[1:], hostip) <mask> binary.BigEndian.PutUint16(parsed[1+net.IPv6len:], uint16(port)) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove var parsed Addr </s> add var parsed protobytes.BytesWriter </s> remove parsed = make([]byte, 1+net.IPv6len+2) parsed[0] = AtypIPv6 copy(parsed[1:], hostip) binary.BigEndian.PutUint16(parsed[1+net.IPv6len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv6len+2) parsed.PutUint8(AtypIPv6) parsed.PutSlice(hostip) parsed.PutUint16be(uint16(port)) </s> remove return parsed </s> add return Addr(parsed) </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
parsed = make([]byte, 0, 1+net.IPv6len+2) parsed.PutUint8(AtypIPv6) parsed.PutSlice(hostip) parsed.PutUint16be(uint16(port))
<mask> copy(parsed[1:], ip4) <mask> binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) <mask> <mask> } else { <mask> parsed = make([]byte, 1+net.IPv6len+2) <mask> parsed[0] = AtypIPv6 <mask> copy(parsed[1:], hostip) <mask> binary.BigEndian.PutUint16(parsed[1+net.IPv6len:], uint16(port)) <mask> } <mask> return parsed <mask> } <mask> <mask> func AddrFromStdAddrPort(addrPort netip.AddrPort) Addr { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove parsed = make([]byte, 1+net.IPv4len+2) parsed[0] = AtypIPv4 copy(parsed[1:], ip4) binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv4len+2) parsed.PutUint8(AtypIPv4) parsed.PutSlice(ip4) parsed.PutUint16be(uint16(port)) </s> remove return parsed </s> add return Addr(parsed) </s> remove var parsed Addr </s> add var parsed protobytes.BytesWriter </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip) </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
return Addr(parsed)
<mask> parsed[0] = AtypIPv6 <mask> copy(parsed[1:], hostip) <mask> binary.BigEndian.PutUint16(parsed[1+net.IPv6len:], uint16(port)) <mask> } <mask> return parsed <mask> } <mask> <mask> func AddrFromStdAddrPort(addrPort netip.AddrPort) Addr { <mask> addr := addrPort.Addr() <mask> if addr.Is4() { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove parsed = make([]byte, 1+net.IPv6len+2) parsed[0] = AtypIPv6 copy(parsed[1:], hostip) binary.BigEndian.PutUint16(parsed[1+net.IPv6len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv6len+2) parsed.PutUint8(AtypIPv6) parsed.PutSlice(hostip) parsed.PutUint16be(uint16(port)) </s> remove parsed = make([]byte, 1+net.IPv4len+2) parsed[0] = AtypIPv4 copy(parsed[1:], ip4) binary.BigEndian.PutUint16(parsed[1+net.IPv4len:], uint16(port)) </s> add parsed = make([]byte, 0, 1+net.IPv4len+2) parsed.PutUint8(AtypIPv4) parsed.PutSlice(ip4) parsed.PutUint16be(uint16(port)) </s> remove var parsed Addr </s> add var parsed protobytes.BytesWriter </s> remove addr = make([]byte, 1+net.IPv4len+2) addr[0] = AtypIPv4 copy(addr[1:], ip4) </s> add buf.PutUint8(AtypIPv4) buf.PutSlice(ip4) </s> remove addr = make([]byte, 1+net.IPv6len+2) addr[0] = AtypIPv6 copy(addr[1:], ip) </s> add buf.PutUint8(AtypIPv6) buf.PutSlice(ip)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
r := protobytes.BytesReader(packet) if r.Len() < 5 {
<mask> } <mask> <mask> // DecodeUDPPacket split `packet` to addr payload, and this function is mutable with `packet` <mask> func DecodeUDPPacket(packet []byte) (addr Addr, payload []byte, err error) { <mask> if len(packet) < 5 { <mask> err = errors.New("insufficient length of packet") <mask> return <mask> } <mask> <mask> // packet[0] and packet[1] are reserved </s> Chore: use protobytes replace most of bytes.Buffer </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove if !bytes.Equal(packet[:2], []byte{0, 0}) { </s> add reserved, r := r.SplitAt(2) if !bytes.Equal(reserved, []byte{0, 0}) { </s> remove addr = SplitAddr(packet[3:]) </s> add addr = SplitAddr(r) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(socks5Addr) binary.Write(buf, binary.BigEndian, uint16(len(payload))) buf.Write(crlf) buf.Write(payload) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(socks5Addr) buf.PutUint16be(uint16(len(payload))) buf.PutSlice(crlf) buf.PutSlice(payload) </s> remove addr[len(addr)-2], addr[len(addr)-1] = byte(portnum>>8), byte(portnum) return addr </s> add buf.PutUint16be(uint16(portnum)) return Addr(buf.Bytes())
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
reserved, r := r.SplitAt(2) if !bytes.Equal(reserved, []byte{0, 0}) {
<mask> return <mask> } <mask> <mask> // packet[0] and packet[1] are reserved <mask> if !bytes.Equal(packet[:2], []byte{0, 0}) { <mask> err = errors.New("reserved fields should be zero") <mask> return <mask> } <mask> <mask> if packet[2] != 0 /* fragments */ { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if packet[2] != 0 /* fragments */ { </s> add if r.ReadUint8() != 0 /* fragments */ { </s> remove if len(packet) < 5 { </s> add r := protobytes.BytesReader(packet) if r.Len() < 5 { </s> remove req := &bytes.Buffer{} req.WriteByte(Version) req.WriteByte(command) binary.Write(req, binary.BigEndian, uint16(port)) req.Write(dstIP) req.WriteString(userID) req.WriteByte(0) /* NULL */ if isReservedIP(dstIP) /* SOCKS4A */ { req.WriteString(host) req.WriteByte(0) /* NULL */ </s> add if isReservedIP(ip) /* SOCKS4A */ { req.PutString(host) req.PutUint8(0) /* NULL */ </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove dstIP := ip.To4() </s> add req := protobytes.BytesWriter{} req.PutUint8(Version) req.PutUint8(command) req.PutUint16be(uint16(port)) req.Write(ip.AsSlice()) req.PutString(userID) req.PutUint8(0) /* NULL */
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
if r.ReadUint8() != 0 /* fragments */ {
<mask> err = errors.New("reserved fields should be zero") <mask> return <mask> } <mask> <mask> if packet[2] != 0 /* fragments */ { <mask> err = errors.New("discarding fragmented payload") <mask> return <mask> } <mask> <mask> addr = SplitAddr(packet[3:]) </s> Chore: use protobytes replace most of bytes.Buffer </s> remove if !bytes.Equal(packet[:2], []byte{0, 0}) { </s> add reserved, r := r.SplitAt(2) if !bytes.Equal(reserved, []byte{0, 0}) { </s> remove addr = SplitAddr(packet[3:]) </s> add addr = SplitAddr(r) </s> remove req := &bytes.Buffer{} req.WriteByte(Version) req.WriteByte(command) binary.Write(req, binary.BigEndian, uint16(port)) req.Write(dstIP) req.WriteString(userID) req.WriteByte(0) /* NULL */ if isReservedIP(dstIP) /* SOCKS4A */ { req.WriteString(host) req.WriteByte(0) /* NULL */ </s> add if isReservedIP(ip) /* SOCKS4A */ { req.PutString(host) req.PutUint8(0) /* NULL */ </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove addr = make([]byte, 1+1+len(host)+2) addr[0] = AtypDomainName addr[1] = byte(len(host)) copy(addr[2:], host) </s> add buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
addr = SplitAddr(r)
<mask> err = errors.New("discarding fragmented payload") <mask> return <mask> } <mask> <mask> addr = SplitAddr(packet[3:]) <mask> if addr == nil { <mask> err = errors.New("failed to read UDP header") <mask> } <mask> <mask> payload = packet[3+len(addr):] </s> Chore: use protobytes replace most of bytes.Buffer </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove if packet[2] != 0 /* fragments */ { </s> add if r.ReadUint8() != 0 /* fragments */ { </s> remove addr = net.JoinHostPort(net.IP(dstIP).String(), port) </s> add addr = net.JoinHostPort(dstAddr.String(), port) </s> remove packet = bytes.Join([][]byte{{0, 0, 0}, addr, payload}, []byte{}) </s> add w := protobytes.BytesWriter{} w.PutSlice([]byte{0, 0, 0}) w.PutSlice(addr) w.PutSlice(payload) packet = w.Bytes() </s> remove addr = make([]byte, 1+1+len(host)+2) addr[0] = AtypDomainName addr[1] = byte(len(host)) copy(addr[2:], host) </s> add buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
_, payload = r.SplitAt(len(addr))
<mask> if addr == nil { <mask> err = errors.New("failed to read UDP header") <mask> } <mask> <mask> payload = packet[3+len(addr):] <mask> return <mask> } <mask> <mask> func EncodeUDPPacket(addr Addr, payload []byte) (packet []byte, err error) { <mask> if addr == nil { </s> Chore: use protobytes replace most of bytes.Buffer </s> remove addr = SplitAddr(packet[3:]) </s> add addr = SplitAddr(r) </s> remove if len(packet) < 5 { </s> add r := protobytes.BytesReader(packet) if r.Len() < 5 { </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) buf.Write(socks5Addr) binary.Write(buf, binary.BigEndian, uint16(len(payload))) buf.Write(crlf) buf.Write(payload) </s> add buf := protobytes.BytesWriter{} buf.PutSlice(socks5Addr) buf.PutUint16be(uint16(len(payload))) buf.PutSlice(crlf) buf.PutSlice(payload) </s> remove buf := pool.GetBuffer() defer pool.PutBuffer(buf) </s> add buf := pool.GetBytesBuffer() defer pool.PutBytesBuffer(buf) </s> remove addr = net.JoinHostPort(net.IP(dstIP).String(), port) </s> add addr = net.JoinHostPort(dstAddr.String(), port)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
w := protobytes.BytesWriter{} w.PutSlice([]byte{0, 0, 0}) w.PutSlice(addr) w.PutSlice(payload) packet = w.Bytes()
<mask> if addr == nil { <mask> err = errors.New("address is invalid") <mask> return <mask> } <mask> packet = bytes.Join([][]byte{{0, 0, 0}, addr, payload}, []byte{}) <mask> return <mask> } </s> Chore: use protobytes replace most of bytes.Buffer </s> remove ip := net.ParseIP(host) if ip == nil /* HOST */ { ip = net.IPv4(0, 0, 0, 1).To4() } else if ip.To4() == nil /* IPv6 */ { </s> add ip, err := netip.ParseAddr(host) if err != nil { // Host ip = netip.AddrFrom4([4]byte{0, 0, 0, 1}) } else if ip.Is6() { // IPv6 </s> remove addr = SplitAddr(packet[3:]) </s> add addr = SplitAddr(r) </s> remove payload = packet[3+len(addr):] </s> add _, payload = r.SplitAt(len(addr)) </s> remove addr[len(addr)-2], addr[len(addr)-1] = byte(portnum>>8), byte(portnum) return addr </s> add buf.PutUint16be(uint16(portnum)) return Addr(buf.Bytes()) </s> remove addr = make([]byte, 1+1+len(host)+2) addr[0] = AtypDomainName addr[1] = byte(len(host)) copy(addr[2:], host) </s> add buf.PutUint8(AtypDomainName) buf.PutUint8(byte(len(host))) buf.PutString(host)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/socks5/socks5.go
<mask> "net" <mask> "net/http" <mask> "sync" <mask> <mask> "github.com/Dreamacro/clash/common/pool" <mask> C "github.com/Dreamacro/clash/constant" <mask> "github.com/Dreamacro/clash/transport/socks5" <mask> "github.com/Dreamacro/clash/transport/vmess" <mask> ) <mask> </s> Chore: use protobytes replace most of bytes.Buffer </s> remove "encoding/binary" </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/Dreamacro/clash/commit/b7aade5e1139dc0c4eaf8561b3c4271a8984fa1a
transport/trojan/trojan.go