mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Style: format code by gofumpt (#761)
This commit is contained in:
parent
d77be80b40
commit
e286cdcaa8
111 changed files with 293 additions and 291 deletions
|
@ -78,6 +78,7 @@ func TestBufferByte(t *testing.T) {
|
|||
buffer.Release()
|
||||
}
|
||||
}
|
||||
|
||||
func TestBufferResize(t *testing.T) {
|
||||
buffer := New()
|
||||
defer buffer.Release()
|
||||
|
|
|
@ -121,7 +121,7 @@ func NewWriter(writer io.Writer) Writer {
|
|||
return mw
|
||||
}
|
||||
|
||||
var iConn = writer
|
||||
iConn := writer
|
||||
if statConn, ok := writer.(*stat.CounterConnection); ok {
|
||||
iConn = statConn.Connection
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@ import (
|
|||
|
||||
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
||||
|
||||
var (
|
||||
// ErrNoClue is for the situation that existing information is not enough to make a decision. For example, Router may return this error when there is no suitable route.
|
||||
ErrNoClue = errors.New("not enough information for making a decision")
|
||||
)
|
||||
// ErrNoClue is for the situation that existing information is not enough to make a decision. For example, Router may return this error when there is no suitable route.
|
||||
var ErrNoClue = errors.New("not enough information for making a decision")
|
||||
|
||||
// Must panics if err is not nil.
|
||||
func Must(err error) {
|
||||
|
|
|
@ -290,7 +290,6 @@ func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error {
|
|||
mb = nb
|
||||
|
||||
eb, err := w.seal(rawBytes[:nBytes])
|
||||
|
||||
if err != nil {
|
||||
buf.ReleaseMulti(mb2Write)
|
||||
return err
|
||||
|
|
|
@ -18,7 +18,7 @@ func mustDecodeHex(s string) []byte {
|
|||
}
|
||||
|
||||
func TestChaCha20Stream(t *testing.T) {
|
||||
var cases = []struct {
|
||||
cases := []struct {
|
||||
key []byte
|
||||
iv []byte
|
||||
output []byte
|
||||
|
|
|
@ -3,7 +3,7 @@ package internal
|
|||
import "encoding/binary"
|
||||
|
||||
func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
|
||||
var x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 = s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]
|
||||
x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 := s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]
|
||||
for i := 0; i < rounds; i += 2 {
|
||||
var x uint32
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
file, err := os.OpenFile("chacha_core.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||
file, err := os.OpenFile("chacha_core.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to generate chacha_core.go: %v", err)
|
||||
}
|
||||
|
|
|
@ -27,9 +27,7 @@ func (r *CryptionReader) Read(data []byte) (int, error) {
|
|||
return nBytes, err
|
||||
}
|
||||
|
||||
var (
|
||||
_ buf.Writer = (*CryptionWriter)(nil)
|
||||
)
|
||||
var _ buf.Writer = (*CryptionWriter)(nil)
|
||||
|
||||
type CryptionWriter struct {
|
||||
stream cipher.Stream
|
||||
|
|
|
@ -17,7 +17,7 @@ func main() {
|
|||
pkg = "core"
|
||||
}
|
||||
|
||||
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to generate errors.generated.go: %v", err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -32,9 +32,7 @@ func Record(msg Message) {
|
|||
logHandler.Handle(msg)
|
||||
}
|
||||
|
||||
var (
|
||||
logHandler syncHandler
|
||||
)
|
||||
var logHandler syncHandler
|
||||
|
||||
// RegisterHandler register a new handler as current log handler. Previous registered handler will be discarded.
|
||||
func RegisterHandler(handler Handler) {
|
||||
|
|
|
@ -130,13 +130,13 @@ func CreateStderrLogWriter() WriterCreator {
|
|||
|
||||
// CreateFileLogWriter returns a LogWriterCreator that creates LogWriter for the given file.
|
||||
func CreateFileLogWriter(path string) (WriterCreator, error) {
|
||||
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
file.Close()
|
||||
return func() Writer {
|
||||
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -142,7 +142,6 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
|
|||
Reader: downlinkReader,
|
||||
Writer: upLinkWriter,
|
||||
}, f.Strategy)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -175,8 +174,10 @@ type ClientWorker struct {
|
|||
strategy ClientStrategy
|
||||
}
|
||||
|
||||
var muxCoolAddress = net.DomainAddress("v1.mux.cool")
|
||||
var muxCoolPort = net.Port(9527)
|
||||
var (
|
||||
muxCoolAddress = net.DomainAddress("v1.mux.cool")
|
||||
muxCoolPort = net.Port(9527)
|
||||
)
|
||||
|
||||
// NewClientWorker creates a new mux.Client.
|
||||
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
|
||||
|
|
|
@ -3,17 +3,21 @@ package net
|
|||
import "net"
|
||||
|
||||
// DialTCP is an alias of net.DialTCP.
|
||||
var DialTCP = net.DialTCP
|
||||
var DialUDP = net.DialUDP
|
||||
var DialUnix = net.DialUnix
|
||||
var Dial = net.Dial
|
||||
var (
|
||||
DialTCP = net.DialTCP
|
||||
DialUDP = net.DialUDP
|
||||
DialUnix = net.DialUnix
|
||||
Dial = net.Dial
|
||||
)
|
||||
|
||||
type ListenConfig = net.ListenConfig
|
||||
|
||||
var Listen = net.Listen
|
||||
var ListenTCP = net.ListenTCP
|
||||
var ListenUDP = net.ListenUDP
|
||||
var ListenUnix = net.ListenUnix
|
||||
var (
|
||||
Listen = net.Listen
|
||||
ListenTCP = net.ListenTCP
|
||||
ListenUDP = net.ListenUDP
|
||||
ListenUnix = net.ListenUnix
|
||||
)
|
||||
|
||||
var LookupIP = net.LookupIP
|
||||
|
||||
|
@ -26,36 +30,54 @@ var SplitHostPort = net.SplitHostPort
|
|||
|
||||
var CIDRMask = net.CIDRMask
|
||||
|
||||
type Addr = net.Addr
|
||||
type Conn = net.Conn
|
||||
type PacketConn = net.PacketConn
|
||||
type (
|
||||
Addr = net.Addr
|
||||
Conn = net.Conn
|
||||
PacketConn = net.PacketConn
|
||||
)
|
||||
|
||||
type TCPAddr = net.TCPAddr
|
||||
type TCPConn = net.TCPConn
|
||||
type (
|
||||
TCPAddr = net.TCPAddr
|
||||
TCPConn = net.TCPConn
|
||||
)
|
||||
|
||||
type UDPAddr = net.UDPAddr
|
||||
type UDPConn = net.UDPConn
|
||||
type (
|
||||
UDPAddr = net.UDPAddr
|
||||
UDPConn = net.UDPConn
|
||||
)
|
||||
|
||||
type UnixAddr = net.UnixAddr
|
||||
type UnixConn = net.UnixConn
|
||||
type (
|
||||
UnixAddr = net.UnixAddr
|
||||
UnixConn = net.UnixConn
|
||||
)
|
||||
|
||||
// IP is an alias for net.IP.
|
||||
type IP = net.IP
|
||||
type IPMask = net.IPMask
|
||||
type IPNet = net.IPNet
|
||||
type (
|
||||
IP = net.IP
|
||||
IPMask = net.IPMask
|
||||
IPNet = net.IPNet
|
||||
)
|
||||
|
||||
const IPv4len = net.IPv4len
|
||||
const IPv6len = net.IPv6len
|
||||
const (
|
||||
IPv4len = net.IPv4len
|
||||
IPv6len = net.IPv6len
|
||||
)
|
||||
|
||||
type Error = net.Error
|
||||
type AddrError = net.AddrError
|
||||
type (
|
||||
Error = net.Error
|
||||
AddrError = net.AddrError
|
||||
)
|
||||
|
||||
type Dialer = net.Dialer
|
||||
type Listener = net.Listener
|
||||
type TCPListener = net.TCPListener
|
||||
type UnixListener = net.UnixListener
|
||||
type (
|
||||
Dialer = net.Dialer
|
||||
Listener = net.Listener
|
||||
TCPListener = net.TCPListener
|
||||
UnixListener = net.UnixListener
|
||||
)
|
||||
|
||||
var ResolveUnixAddr = net.ResolveUnixAddr
|
||||
var ResolveUDPAddr = net.ResolveUDPAddr
|
||||
var (
|
||||
ResolveUnixAddr = net.ResolveUnixAddr
|
||||
ResolveUDPAddr = net.ResolveUDPAddr
|
||||
)
|
||||
|
||||
type Resolver = net.Resolver
|
||||
|
|
|
@ -56,7 +56,6 @@ func GetOCSPForCert(cert [][]byte) ([]byte, error) {
|
|||
pemBundle := bundle.Bytes()
|
||||
|
||||
certificates, err := parsePEMBundle(pemBundle)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -99,12 +98,10 @@ func GetOCSPForCert(cert [][]byte) ([]byte, error) {
|
|||
}
|
||||
defer req.Body.Close()
|
||||
ocspResBytes, err := io.ReadAll(req.Body)
|
||||
|
||||
if err != nil {
|
||||
return nil, newError(err)
|
||||
}
|
||||
return ocspResBytes, nil
|
||||
|
||||
}
|
||||
|
||||
// parsePEMBundle parses a certificate bundle from top to bottom and returns
|
||||
|
|
|
@ -33,7 +33,7 @@ func CopyFile(dst string, src string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, 0644)
|
||||
f, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ import (
|
|||
"github.com/xtls/xray-core/common"
|
||||
)
|
||||
|
||||
type SniffHeader struct {
|
||||
}
|
||||
type SniffHeader struct{}
|
||||
|
||||
func (h *SniffHeader) Protocol() string {
|
||||
return "bittorrent"
|
||||
|
|
|
@ -73,6 +73,7 @@ func printJSON(certificate *Certificate) {
|
|||
os.Stdout.Write(content)
|
||||
os.Stdout.WriteString("\n")
|
||||
}
|
||||
|
||||
func printFile(certificate *Certificate, name string) error {
|
||||
certPEM, keyPEM := certificate.ToPEM()
|
||||
return task.Run(context.Background(), func() error {
|
||||
|
@ -81,6 +82,7 @@ func printFile(certificate *Certificate, name string) error {
|
|||
return writeFile(keyPEM, name+"_key.pem")
|
||||
})
|
||||
}
|
||||
|
||||
func writeFile(content []byte, name string) error {
|
||||
f, err := os.Create(name)
|
||||
if err != nil {
|
||||
|
|
|
@ -20,8 +20,10 @@ func (h *SniffHeader) Domain() string {
|
|||
return h.domain
|
||||
}
|
||||
|
||||
var errNotTLS = errors.New("not TLS header")
|
||||
var errNotClientHello = errors.New("not client hello")
|
||||
var (
|
||||
errNotTLS = errors.New("not TLS header")
|
||||
errNotClientHello = errors.New("not client hello")
|
||||
)
|
||||
|
||||
func IsValidTLSVersion(major, minor byte) bool {
|
||||
return major == 3
|
||||
|
|
|
@ -6,9 +6,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrRetryFailed = newError("all retry attempts failed")
|
||||
)
|
||||
var ErrRetryFailed = newError("all retry attempts failed")
|
||||
|
||||
// Strategy is a way to retry on a specific function.
|
||||
type Strategy interface {
|
||||
|
|
|
@ -9,9 +9,7 @@ import (
|
|||
. "github.com/xtls/xray-core/common/retry"
|
||||
)
|
||||
|
||||
var (
|
||||
errorTestOnly = errors.New("this is a fake error")
|
||||
)
|
||||
var errorTestOnly = errors.New("this is a fake error")
|
||||
|
||||
func TestNoRetry(t *testing.T) {
|
||||
startTime := time.Now().Unix()
|
||||
|
|
|
@ -122,7 +122,7 @@ var char2Index = []int{
|
|||
}
|
||||
|
||||
func NewACAutomaton() *ACAutomaton {
|
||||
var ac = new(ACAutomaton)
|
||||
ac := new(ACAutomaton)
|
||||
ac.trie = append(ac.trie, newNode())
|
||||
ac.fail = append(ac.fail, 0)
|
||||
ac.exists = append(ac.exists, MatchType{
|
||||
|
@ -133,9 +133,9 @@ func NewACAutomaton() *ACAutomaton {
|
|||
}
|
||||
|
||||
func (ac *ACAutomaton) Add(domain string, t Type) {
|
||||
var node = 0
|
||||
node := 0
|
||||
for i := len(domain) - 1; i >= 0; i-- {
|
||||
var idx = char2Index[domain[i]]
|
||||
idx := char2Index[domain[i]]
|
||||
if ac.trie[node][idx].nextNode == 0 {
|
||||
ac.count++
|
||||
if len(ac.trie) < ac.count+1 {
|
||||
|
@ -163,7 +163,7 @@ func (ac *ACAutomaton) Add(domain string, t Type) {
|
|||
matchType: Full,
|
||||
exist: true,
|
||||
}
|
||||
var idx = char2Index['.']
|
||||
idx := char2Index['.']
|
||||
if ac.trie[node][idx].nextNode == 0 {
|
||||
ac.count++
|
||||
if len(ac.trie) < ac.count+1 {
|
||||
|
@ -190,18 +190,18 @@ func (ac *ACAutomaton) Add(domain string, t Type) {
|
|||
}
|
||||
|
||||
func (ac *ACAutomaton) Build() {
|
||||
var queue = list.New()
|
||||
queue := list.New()
|
||||
for i := 0; i < validCharCount; i++ {
|
||||
if ac.trie[0][i].nextNode != 0 {
|
||||
queue.PushBack(ac.trie[0][i])
|
||||
}
|
||||
}
|
||||
for {
|
||||
var front = queue.Front()
|
||||
front := queue.Front()
|
||||
if front == nil {
|
||||
break
|
||||
} else {
|
||||
var node = front.Value.(Edge).nextNode
|
||||
node := front.Value.(Edge).nextNode
|
||||
queue.Remove(front)
|
||||
for i := 0; i < validCharCount; i++ {
|
||||
if ac.trie[node][i].nextNode != 0 {
|
||||
|
@ -219,13 +219,13 @@ func (ac *ACAutomaton) Build() {
|
|||
}
|
||||
|
||||
func (ac *ACAutomaton) Match(s string) bool {
|
||||
var node = 0
|
||||
var fullMatch = true
|
||||
node := 0
|
||||
fullMatch := true
|
||||
// 1. the match string is all through trie edge. FULL MATCH or DOMAIN
|
||||
// 2. the match string is through a fail edge. NOT FULL MATCH
|
||||
// 2.1 Through a fail edge, but there exists a valid node. SUBSTR
|
||||
for i := len(s) - 1; i >= 0; i-- {
|
||||
var idx = char2Index[s[i]]
|
||||
idx := char2Index[s[i]]
|
||||
fullMatch = fullMatch && ac.trie[node][idx].edgeType
|
||||
node = ac.trie[node][idx].nextNode
|
||||
switch ac.exists[node].matchType {
|
||||
|
|
|
@ -102,7 +102,7 @@ func (g *MphMatcherGroup) Build() {
|
|||
g.level0Mask = len(g.level0) - 1
|
||||
g.level1 = make([]uint32, nextPow2(keyLen))
|
||||
g.level1Mask = len(g.level1) - 1
|
||||
var sparseBuckets = make([][]int, len(g.level0))
|
||||
sparseBuckets := make([][]int, len(g.level0))
|
||||
var ruleIdx int
|
||||
for rule, hash := range *g.ruleMap {
|
||||
n := int(hash) & g.level0Mask
|
||||
|
@ -122,7 +122,7 @@ func (g *MphMatcherGroup) Build() {
|
|||
occ := make([]bool, len(g.level1))
|
||||
var tmpOcc []int
|
||||
for _, bucket := range buckets {
|
||||
var seed = uint32(0)
|
||||
seed := uint32(0)
|
||||
for {
|
||||
findSeed := true
|
||||
tmpOcc = tmpOcc[:0]
|
||||
|
@ -284,9 +284,11 @@ tail:
|
|||
h ^= h >> 32
|
||||
return uintptr(h)
|
||||
}
|
||||
|
||||
func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr(p) + x)
|
||||
}
|
||||
|
||||
func readUnaligned32(p unsafe.Pointer) uint32 {
|
||||
q := (*[4]byte)(p)
|
||||
return uint32(q[0]) | uint32(q[1])<<8 | uint32(q[2])<<16 | uint32(q[3])<<24
|
||||
|
@ -295,6 +297,7 @@ func readUnaligned32(p unsafe.Pointer) uint32 {
|
|||
func rotl31(x uint64) uint64 {
|
||||
return (x << 31) | (x >> (64 - 31))
|
||||
}
|
||||
|
||||
func readUnaligned64(p unsafe.Pointer) uint64 {
|
||||
q := (*[8]byte)(p)
|
||||
return uint64(q[0]) | uint64(q[1])<<8 | uint64(q[2])<<16 | uint64(q[3])<<24 | uint64(q[4])<<32 | uint64(q[5])<<40 | uint64(q[6])<<48 | uint64(q[7])<<56
|
||||
|
|
|
@ -143,7 +143,7 @@ func TestACAutomaton(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, test := range cases1 {
|
||||
var ac = NewACAutomaton()
|
||||
ac := NewACAutomaton()
|
||||
ac.Add(test.pattern, test.mType)
|
||||
ac.Build()
|
||||
if m := ac.Match(test.input); m != test.output {
|
||||
|
@ -176,7 +176,7 @@ func TestACAutomaton(t *testing.T) {
|
|||
mType: Substr,
|
||||
},
|
||||
}
|
||||
var ac = NewACAutomaton()
|
||||
ac := NewACAutomaton()
|
||||
for _, test := range cases2Input {
|
||||
ac.Add(test.pattern, test.mType)
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ func TestACAutomaton(t *testing.T) {
|
|||
mType: Domain,
|
||||
},
|
||||
}
|
||||
var ac = NewACAutomaton()
|
||||
ac := NewACAutomaton()
|
||||
for _, test := range cases3Input {
|
||||
ac.Add(test.pattern, test.mType)
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ import (
|
|||
// ConfigCreator is a function to create an object by a config.
|
||||
type ConfigCreator func(ctx context.Context, config interface{}) (interface{}, error)
|
||||
|
||||
var (
|
||||
typeCreatorRegistry = make(map[reflect.Type]ConfigCreator)
|
||||
)
|
||||
var typeCreatorRegistry = make(map[reflect.Type]ConfigCreator)
|
||||
|
||||
// RegisterConfig registers a global config creator. The config can be nil but must have a type.
|
||||
func RegisterConfig(config interface{}, configCreator ConfigCreator) error {
|
||||
|
|
|
@ -16,7 +16,7 @@ type YConfig struct {
|
|||
}
|
||||
|
||||
func TestObjectCreation(t *testing.T) {
|
||||
var f = func(ctx context.Context, t interface{}) (interface{}, error) {
|
||||
f := func(ctx context.Context, t interface{}) (interface{}, error) {
|
||||
return func() int {
|
||||
return t.(*TConfig).value
|
||||
}, nil
|
||||
|
|
|
@ -10,9 +10,7 @@ import (
|
|||
"github.com/xtls/xray-core/common/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
byteGroups = []int{8, 4, 4, 4, 12}
|
||||
)
|
||||
var byteGroups = []int{8, 4, 4, 4, 12}
|
||||
|
||||
type UUID [16]byte
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue