diff --git a/cmd/acme.go b/cmd/acme.go index c4cf196..991de94 100644 --- a/cmd/acme.go +++ b/cmd/acme.go @@ -3,11 +3,13 @@ package main import ( "context" "crypto/tls" + "github.com/caddyserver/certmagic" ) func acmeTLSConfig(domains []string, email string, disableHTTP bool, disableTLSALPN bool, - altHTTPPort int, altTLSALPNPort int) (*tls.Config, error) { + altHTTPPort int, altTLSALPNPort int, +) (*tls.Config, error) { certmagic.DefaultACME.Agreed = true certmagic.DefaultACME.Email = email certmagic.DefaultACME.DisableHTTPChallenge = disableHTTP diff --git a/cmd/auth/cmd.go b/cmd/auth/cmd.go index 2f4276d..d99e92e 100644 --- a/cmd/auth/cmd.go +++ b/cmd/auth/cmd.go @@ -1,11 +1,12 @@ package auth import ( - "github.com/sirupsen/logrus" "net" "os/exec" "strconv" "strings" + + "github.com/sirupsen/logrus" ) type CmdAuthProvider struct { diff --git a/cmd/auth/http.go b/cmd/auth/http.go index da4970f..4b9162d 100644 --- a/cmd/auth/http.go +++ b/cmd/auth/http.go @@ -3,10 +3,11 @@ package auth import ( "bytes" "encoding/json" - "github.com/sirupsen/logrus" "io/ioutil" "net" "net/http" + + "github.com/sirupsen/logrus" ) type HTTPAuthProvider struct { diff --git a/cmd/client.go b/cmd/client.go index a835058..903a324 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -4,10 +4,6 @@ import ( "crypto/tls" "crypto/x509" "errors" - "github.com/oschwald/geoip2-golang" - "github.com/tobyxdd/hysteria/pkg/pmtud_fix" - "github.com/tobyxdd/hysteria/pkg/redirect" - "github.com/yosuke-furukawa/json5/encoding/json5" "io" "io/ioutil" "net" @@ -15,6 +11,11 @@ import ( "os" "time" + "github.com/oschwald/geoip2-golang" + "github.com/tobyxdd/hysteria/pkg/pmtud_fix" + "github.com/tobyxdd/hysteria/pkg/redirect" + "github.com/yosuke-furukawa/json5/encoding/json5" + "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/congestion" "github.com/sirupsen/logrus" diff --git a/cmd/client_gpl.go b/cmd/client_gpl.go index 2b4b182..dd6a015 100644 --- a/cmd/client_gpl.go +++ b/cmd/client_gpl.go @@ -4,13 +4,14 @@ package main import ( - "github.com/sirupsen/logrus" - "github.com/tobyxdd/hysteria/pkg/core" - "github.com/tobyxdd/hysteria/pkg/tun" "io" "net" "strings" "time" + + "github.com/sirupsen/logrus" + "github.com/tobyxdd/hysteria/pkg/core" + "github.com/tobyxdd/hysteria/pkg/tun" ) const license = `Hysteria is a feature-packed proxy & relay utility optimized for lossy, unstable connections. diff --git a/cmd/config.go b/cmd/config.go index d7b1881..b808467 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -3,11 +3,12 @@ package main import ( "errors" "fmt" - "github.com/sirupsen/logrus" - "github.com/yosuke-furukawa/json5/encoding/json5" "regexp" "strconv" "time" + + "github.com/sirupsen/logrus" + "github.com/yosuke-furukawa/json5/encoding/json5" ) const ( diff --git a/cmd/kploader.go b/cmd/kploader.go index b71b3d0..5d6f60e 100644 --- a/cmd/kploader.go +++ b/cmd/kploader.go @@ -2,9 +2,10 @@ package main import ( "crypto/tls" + "sync" + "github.com/fsnotify/fsnotify" "github.com/sirupsen/logrus" - "sync" ) type keypairLoader struct { diff --git a/cmd/mmdb.go b/cmd/mmdb.go index 1370959..f35185d 100644 --- a/cmd/mmdb.go +++ b/cmd/mmdb.go @@ -1,12 +1,13 @@ package main import ( - "github.com/oschwald/geoip2-golang" - "github.com/sirupsen/logrus" - "github.com/spf13/viper" "io" "net/http" "os" + + "github.com/oschwald/geoip2-golang" + "github.com/sirupsen/logrus" + "github.com/spf13/viper" ) func downloadMMDB(filename string) error { diff --git a/cmd/resolver.go b/cmd/resolver.go index aefe81f..a0a8eca 100644 --- a/cmd/resolver.go +++ b/cmd/resolver.go @@ -2,10 +2,11 @@ package main import ( "errors" - rdns "github.com/folbricht/routedns" - "github.com/tobyxdd/hysteria/pkg/utils" "net" "strings" + + rdns "github.com/folbricht/routedns" + "github.com/tobyxdd/hysteria/pkg/utils" ) var errInvalidSyntax = errors.New("invalid syntax") diff --git a/cmd/server.go b/cmd/server.go index 7e79115..7d09755 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -3,6 +3,11 @@ package main import ( "crypto/tls" "errors" + "io" + "net" + "net/http" + "time" + "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/congestion" "github.com/oschwald/geoip2-golang" @@ -18,10 +23,6 @@ import ( "github.com/tobyxdd/hysteria/pkg/sockopt" "github.com/tobyxdd/hysteria/pkg/transport" "github.com/yosuke-furukawa/json5/encoding/json5" - "io" - "net" - "net/http" - "time" ) func server(config *serverConfig) { diff --git a/pkg/acl/engine.go b/pkg/acl/engine.go index 4b758a6..2d591f1 100644 --- a/pkg/acl/engine.go +++ b/pkg/acl/engine.go @@ -2,12 +2,13 @@ package acl import ( "bufio" - lru "github.com/hashicorp/golang-lru" - "github.com/oschwald/geoip2-golang" - "github.com/tobyxdd/hysteria/pkg/utils" "net" "os" "strings" + + lru "github.com/hashicorp/golang-lru" + "github.com/oschwald/geoip2-golang" + "github.com/tobyxdd/hysteria/pkg/utils" ) const entryCacheSize = 1024 diff --git a/pkg/acl/engine_test.go b/pkg/acl/engine_test.go index 4c30884..2a0694c 100644 --- a/pkg/acl/engine_test.go +++ b/pkg/acl/engine_test.go @@ -2,10 +2,11 @@ package acl import ( "errors" - lru "github.com/hashicorp/golang-lru" "net" "strings" "testing" + + lru "github.com/hashicorp/golang-lru" ) func TestEngine_ResolveAndMatch(t *testing.T) { diff --git a/pkg/acl/entry.go b/pkg/acl/entry.go index bc345aa..5cec192 100644 --- a/pkg/acl/entry.go +++ b/pkg/acl/entry.go @@ -3,14 +3,17 @@ package acl import ( "errors" "fmt" - "github.com/oschwald/geoip2-golang" "net" "strconv" "strings" + + "github.com/oschwald/geoip2-golang" ) -type Action byte -type Protocol byte +type ( + Action byte + Protocol byte +) const ( ActionDirect = Action(iota) diff --git a/pkg/acl/entry_test.go b/pkg/acl/entry_test.go index 37b8807..d620197 100644 --- a/pkg/acl/entry_test.go +++ b/pkg/acl/entry_test.go @@ -19,46 +19,64 @@ func TestParseEntry(t *testing.T) { wantErr bool }{ {name: "empty", args: args{""}, want: Entry{}, wantErr: true}, - {name: "ok 1", args: args{"direct domain-suffix google.com"}, + { + name: "ok 1", args: args{"direct domain-suffix google.com"}, want: Entry{ActionDirect, "", &domainMatcher{ matcherBase: matcherBase{}, Domain: "google.com", Suffix: true, }}, - wantErr: false}, - {name: "ok 2", args: args{"proxy domain shithole"}, + wantErr: false, + }, + { + name: "ok 2", args: args{"proxy domain shithole"}, want: Entry{ActionProxy, "", &domainMatcher{ matcherBase: matcherBase{}, Domain: "shithole", Suffix: false, }}, - wantErr: false}, - {name: "ok 3", args: args{"block cidr 8.8.8.0/24 */53"}, + wantErr: false, + }, + { + name: "ok 3", args: args{"block cidr 8.8.8.0/24 */53"}, want: Entry{ActionBlock, "", &netMatcher{ matcherBase: matcherBase{ProtocolAll, 53}, Net: ok3net, }}, - wantErr: false}, - {name: "ok 4", args: args{"hijack all udp/* udpblackhole.net"}, + wantErr: false, + }, + { + name: "ok 4", args: args{"hijack all udp/* udpblackhole.net"}, want: Entry{ActionHijack, "udpblackhole.net", &allMatcher{ matcherBase: matcherBase{ProtocolUDP, 0}, }}, - wantErr: false}, - {name: "err 1", args: args{"what the heck"}, + wantErr: false, + }, + { + name: "err 1", args: args{"what the heck"}, want: Entry{}, - wantErr: true}, - {name: "err 2", args: args{"proxy sucks ass"}, + wantErr: true, + }, + { + name: "err 2", args: args{"proxy sucks ass"}, want: Entry{}, - wantErr: true}, - {name: "err 3", args: args{"block ip 999.999.999.999"}, + wantErr: true, + }, + { + name: "err 3", args: args{"block ip 999.999.999.999"}, want: Entry{}, - wantErr: true}, - {name: "err 4", args: args{"hijack domain google.com"}, + wantErr: true, + }, + { + name: "err 4", args: args{"hijack domain google.com"}, want: Entry{}, - wantErr: true}, - {name: "err 5", args: args{"hijack domain google.com bing.com 123"}, + wantErr: true, + }, + { + name: "err 5", args: args{"hijack domain google.com bing.com 123"}, want: Entry{}, - wantErr: true}, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/congestion/brutal.go b/pkg/congestion/brutal.go index d08ac34..02f12d4 100644 --- a/pkg/congestion/brutal.go +++ b/pkg/congestion/brutal.go @@ -1,8 +1,9 @@ package congestion import ( - "github.com/lucas-clemente/quic-go/congestion" "time" + + "github.com/lucas-clemente/quic-go/congestion" ) const ( @@ -66,12 +67,14 @@ func (b *BrutalSender) GetCongestionWindow() congestion.ByteCount { } func (b *BrutalSender) OnPacketSent(sentTime time.Time, bytesInFlight congestion.ByteCount, - packetNumber congestion.PacketNumber, bytes congestion.ByteCount, isRetransmittable bool) { + packetNumber congestion.PacketNumber, bytes congestion.ByteCount, isRetransmittable bool, +) { b.pacer.SentPacket(sentTime, bytes) } func (b *BrutalSender) OnPacketAcked(number congestion.PacketNumber, ackedBytes congestion.ByteCount, - priorInFlight congestion.ByteCount, eventTime time.Time) { + priorInFlight congestion.ByteCount, eventTime time.Time, +) { currentTimestamp := eventTime.Unix() slot := currentTimestamp % pktInfoSlotCount if b.pktInfoSlots[slot].Timestamp == currentTimestamp { @@ -86,7 +89,8 @@ func (b *BrutalSender) OnPacketAcked(number congestion.PacketNumber, ackedBytes } func (b *BrutalSender) OnPacketLost(number congestion.PacketNumber, lostBytes congestion.ByteCount, - priorInFlight congestion.ByteCount) { + priorInFlight congestion.ByteCount, +) { currentTimestamp := time.Now().Unix() slot := currentTimestamp % pktInfoSlotCount if b.pktInfoSlots[slot].Timestamp == currentTimestamp { diff --git a/pkg/congestion/pacer.go b/pkg/congestion/pacer.go index 4370710..907cddc 100644 --- a/pkg/congestion/pacer.go +++ b/pkg/congestion/pacer.go @@ -1,9 +1,10 @@ package congestion import ( - "github.com/lucas-clemente/quic-go/congestion" "math" "time" + + "github.com/lucas-clemente/quic-go/congestion" ) const ( diff --git a/pkg/conns/faketcp/obfs.go b/pkg/conns/faketcp/obfs.go index 7f0f70c..5a774a0 100644 --- a/pkg/conns/faketcp/obfs.go +++ b/pkg/conns/faketcp/obfs.go @@ -1,11 +1,12 @@ package faketcp import ( - "github.com/tobyxdd/hysteria/pkg/obfs" "net" "sync" "syscall" "time" + + "github.com/tobyxdd/hysteria/pkg/obfs" ) const udpBufferSize = 65535 diff --git a/pkg/conns/faketcp/tcp_test.go b/pkg/conns/faketcp/tcp_test.go index ea26c68..fa850b8 100644 --- a/pkg/conns/faketcp/tcp_test.go +++ b/pkg/conns/faketcp/tcp_test.go @@ -11,12 +11,14 @@ import ( "testing" ) -//const testPortStream = "127.0.0.1:3456" -//const testPortPacket = "127.0.0.1:3457" +// const testPortStream = "127.0.0.1:3456" +// const testPortPacket = "127.0.0.1:3457" -const testPortStream = "127.0.0.1:3456" -const portServerPacket = "[::]:3457" -const portRemotePacket = "127.0.0.1:3457" +const ( + testPortStream = "127.0.0.1:3456" + portServerPacket = "[::]:3457" + portRemotePacket = "127.0.0.1:3457" +) func init() { startTCPServer() @@ -70,7 +72,7 @@ func startTCPRawServer() *TCPConn { log.Println("server readfrom:", err) return } - //echo + // echo n, err = conn.WriteTo(buf[:n], addr) if err != nil { log.Println("server writeTo:", err) diff --git a/pkg/conns/udp/obfs.go b/pkg/conns/udp/obfs.go index bfe4fd6..ecd509e 100644 --- a/pkg/conns/udp/obfs.go +++ b/pkg/conns/udp/obfs.go @@ -1,12 +1,13 @@ package udp import ( - "github.com/tobyxdd/hysteria/pkg/obfs" "net" "os" "sync" "syscall" "time" + + "github.com/tobyxdd/hysteria/pkg/obfs" ) const udpBufferSize = 65535 diff --git a/pkg/conns/wechat/obfs.go b/pkg/conns/wechat/obfs.go index 4475e2f..78925ea 100644 --- a/pkg/conns/wechat/obfs.go +++ b/pkg/conns/wechat/obfs.go @@ -2,13 +2,14 @@ package wechat import ( "encoding/binary" - "github.com/tobyxdd/hysteria/pkg/obfs" "math/rand" "net" "os" "sync" "syscall" "time" + + "github.com/tobyxdd/hysteria/pkg/obfs" ) const udpBufferSize = 65535 diff --git a/pkg/core/client.go b/pkg/core/client.go index f4c2ab6..2477f3d 100644 --- a/pkg/core/client.go +++ b/pkg/core/client.go @@ -6,6 +6,12 @@ import ( "crypto/tls" "errors" "fmt" + "math/rand" + "net" + "strconv" + "sync" + "time" + "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/congestion" "github.com/lunixbochs/struc" @@ -13,16 +19,9 @@ import ( "github.com/tobyxdd/hysteria/pkg/pmtud_fix" "github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/utils" - "math/rand" - "net" - "strconv" - "sync" - "time" ) -var ( - ErrClosed = errors.New("closed") -) +var ErrClosed = errors.New("closed") type CongestionFactory func(refBPS uint64) congestion.CongestionControl @@ -49,7 +48,8 @@ type Client struct { func NewClient(serverAddr string, protocol string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config, transport *transport.ClientTransport, sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory, - obfuscator obfs.Obfuscator) (*Client, error) { + obfuscator obfs.Obfuscator, +) (*Client, error) { quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud_fix.DisablePathMTUDiscovery c := &Client{ transport: transport, diff --git a/pkg/core/frag_test.go b/pkg/core/frag_test.go index f2f2462..aa1c616 100644 --- a/pkg/core/frag_test.go +++ b/pkg/core/frag_test.go @@ -32,7 +32,7 @@ func Test_fragUDPMessage(t *testing.T) { 100, }, []udpMessage{ - udpMessage{ + { SessionID: 123, HostLen: 4, Host: "test", @@ -62,7 +62,7 @@ func Test_fragUDPMessage(t *testing.T) { 22, }, []udpMessage{ - udpMessage{ + { SessionID: 123, HostLen: 4, Host: "test", @@ -73,7 +73,7 @@ func Test_fragUDPMessage(t *testing.T) { DataLen: 4, Data: []byte("hell"), }, - udpMessage{ + { SessionID: 123, HostLen: 4, Host: "test", @@ -103,7 +103,7 @@ func Test_fragUDPMessage(t *testing.T) { 23, }, []udpMessage{ - udpMessage{ + { SessionID: 123, HostLen: 4, Host: "test", @@ -114,7 +114,7 @@ func Test_fragUDPMessage(t *testing.T) { DataLen: 5, Data: []byte("wow w"), }, - udpMessage{ + { SessionID: 123, HostLen: 4, Host: "test", @@ -125,7 +125,7 @@ func Test_fragUDPMessage(t *testing.T) { DataLen: 5, Data: []byte("ow wo"), }, - udpMessage{ + { SessionID: 123, HostLen: 4, Host: "test", @@ -136,7 +136,7 @@ func Test_fragUDPMessage(t *testing.T) { DataLen: 5, Data: []byte("w lol"), }, - udpMessage{ + { SessionID: 123, HostLen: 4, Host: "test", diff --git a/pkg/core/server.go b/pkg/core/server.go index 04d8871..dd3a908 100644 --- a/pkg/core/server.go +++ b/pkg/core/server.go @@ -5,6 +5,8 @@ import ( "crypto/tls" "errors" "fmt" + "net" + "github.com/lucas-clemente/quic-go" "github.com/lunixbochs/struc" "github.com/prometheus/client_golang/prometheus" @@ -12,15 +14,16 @@ import ( "github.com/tobyxdd/hysteria/pkg/obfs" "github.com/tobyxdd/hysteria/pkg/pmtud_fix" "github.com/tobyxdd/hysteria/pkg/transport" - "net" ) -type ConnectFunc func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) -type DisconnectFunc func(addr net.Addr, auth []byte, err error) -type TCPRequestFunc func(addr net.Addr, auth []byte, reqAddr string, action acl.Action, arg string) -type TCPErrorFunc func(addr net.Addr, auth []byte, reqAddr string, err error) -type UDPRequestFunc func(addr net.Addr, auth []byte, sessionID uint32) -type UDPErrorFunc func(addr net.Addr, auth []byte, sessionID uint32, err error) +type ( + ConnectFunc func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) + DisconnectFunc func(addr net.Addr, auth []byte, err error) + TCPRequestFunc func(addr net.Addr, auth []byte, reqAddr string, action acl.Action, arg string) + TCPErrorFunc func(addr net.Addr, auth []byte, reqAddr string, err error) + UDPRequestFunc func(addr net.Addr, auth []byte, sessionID uint32) + UDPErrorFunc func(addr net.Addr, auth []byte, sessionID uint32, err error) +) type Server struct { transport *transport.ServerTransport @@ -46,7 +49,8 @@ func NewServer(addr string, protocol string, tlsConfig *tls.Config, quicConfig * sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory, disableUDP bool, aclEngine *acl.Engine, obfuscator obfs.Obfuscator, connectFunc ConnectFunc, disconnectFunc DisconnectFunc, tcpRequestFunc TCPRequestFunc, tcpErrorFunc TCPErrorFunc, - udpRequestFunc UDPRequestFunc, udpErrorFunc UDPErrorFunc, promRegistry *prometheus.Registry) (*Server, error) { + udpRequestFunc UDPRequestFunc, udpErrorFunc UDPErrorFunc, promRegistry *prometheus.Registry, +) (*Server, error) { quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud_fix.DisablePathMTUDiscovery listener, err := transport.QUICListen(protocol, addr, tlsConfig, quicConfig, obfuscator) if err != nil { diff --git a/pkg/core/server_client.go b/pkg/core/server_client.go index 6f1a19e..05b5d15 100644 --- a/pkg/core/server_client.go +++ b/pkg/core/server_client.go @@ -4,16 +4,17 @@ import ( "bytes" "context" "encoding/base64" + "math/rand" + "net" + "strconv" + "sync" + "github.com/lucas-clemente/quic-go" "github.com/lunixbochs/struc" "github.com/prometheus/client_golang/prometheus" "github.com/tobyxdd/hysteria/pkg/acl" "github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/utils" - "math/rand" - "net" - "strconv" - "sync" ) const udpBufferSize = 65535 @@ -44,7 +45,8 @@ func newServerClient(v2 bool, cs quic.Connection, tr *transport.ServerTransport, CTCPRequestFunc TCPRequestFunc, CTCPErrorFunc TCPErrorFunc, CUDPRequestFunc UDPRequestFunc, CUDPErrorFunc UDPErrorFunc, UpCounterVec, DownCounterVec *prometheus.CounterVec, - ConnGaugeVec *prometheus.GaugeVec) *serverClient { + ConnGaugeVec *prometheus.GaugeVec, +) *serverClient { sc := &serverClient{ V2: v2, CS: cs, diff --git a/pkg/core/stream.go b/pkg/core/stream.go index 8ace4a1..7771036 100644 --- a/pkg/core/stream.go +++ b/pkg/core/stream.go @@ -2,8 +2,9 @@ package core import ( "context" - "github.com/lucas-clemente/quic-go" "time" + + "github.com/lucas-clemente/quic-go" ) // Handle stream close properly diff --git a/pkg/http/server.go b/pkg/http/server.go index 5afef7a..ddd1086 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -3,12 +3,13 @@ package http import ( "errors" "fmt" - "github.com/tobyxdd/hysteria/pkg/transport" - "github.com/tobyxdd/hysteria/pkg/utils" "net" "net/http" "time" + "github.com/tobyxdd/hysteria/pkg/transport" + "github.com/tobyxdd/hysteria/pkg/utils" + "github.com/elazarl/goproxy/ext/auth" "github.com/elazarl/goproxy" @@ -18,7 +19,8 @@ import ( func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransport, idleTimeout time.Duration, aclEngine *acl.Engine, newDialFunc func(reqAddr string, action acl.Action, arg string), - basicAuthFunc func(user, password string) bool) (*goproxy.ProxyHttpServer, error) { + basicAuthFunc func(user, password string) bool, +) (*goproxy.ProxyHttpServer, error) { proxy := goproxy.NewProxyHttpServer() proxy.Logger = &nopLogger{} proxy.NonproxyHandler = http.NotFoundHandler() diff --git a/pkg/redirect/tcp_linux.go b/pkg/redirect/tcp_linux.go index b9f8130..1cd7ae1 100644 --- a/pkg/redirect/tcp_linux.go +++ b/pkg/redirect/tcp_linux.go @@ -3,11 +3,12 @@ package redirect import ( "encoding/binary" "errors" - "github.com/tobyxdd/hysteria/pkg/core" - "github.com/tobyxdd/hysteria/pkg/utils" "net" "syscall" "time" + + "github.com/tobyxdd/hysteria/pkg/core" + "github.com/tobyxdd/hysteria/pkg/utils" ) type TCPRedirect struct { @@ -21,7 +22,8 @@ type TCPRedirect struct { func NewTCPRedirect(hyClient *core.Client, listen string, timeout time.Duration, connFunc func(addr, reqAddr net.Addr), - errorFunc func(addr, reqAddr net.Addr, err error)) (*TCPRedirect, error) { + errorFunc func(addr, reqAddr net.Addr, err error), +) (*TCPRedirect, error) { tAddr, err := net.ResolveTCPAddr("tcp", listen) if err != nil { return nil, err diff --git a/pkg/redirect/tcp_stub.go b/pkg/redirect/tcp_stub.go index a7aaa1a..5e61565 100644 --- a/pkg/redirect/tcp_stub.go +++ b/pkg/redirect/tcp_stub.go @@ -5,16 +5,18 @@ package redirect import ( "errors" - "github.com/tobyxdd/hysteria/pkg/core" "net" "time" + + "github.com/tobyxdd/hysteria/pkg/core" ) type TCPRedirect struct{} func NewTCPRedirect(hyClient *core.Client, listen string, timeout time.Duration, connFunc func(addr, reqAddr net.Addr), - errorFunc func(addr, reqAddr net.Addr, err error)) (*TCPRedirect, error) { + errorFunc func(addr, reqAddr net.Addr, err error), +) (*TCPRedirect, error) { return nil, errors.New("not supported on the current system") } diff --git a/pkg/relay/tcp.go b/pkg/relay/tcp.go index 9e16349..d8d9e2c 100644 --- a/pkg/relay/tcp.go +++ b/pkg/relay/tcp.go @@ -1,10 +1,11 @@ package relay import ( - "github.com/tobyxdd/hysteria/pkg/core" - "github.com/tobyxdd/hysteria/pkg/utils" "net" "time" + + "github.com/tobyxdd/hysteria/pkg/core" + "github.com/tobyxdd/hysteria/pkg/utils" ) type TCPRelay struct { @@ -18,7 +19,8 @@ type TCPRelay struct { } func NewTCPRelay(hyClient *core.Client, listen, remote string, timeout time.Duration, - connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error)) (*TCPRelay, error) { + connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error), +) (*TCPRelay, error) { tAddr, err := net.ResolveTCPAddr("tcp", listen) if err != nil { return nil, err diff --git a/pkg/relay/udp.go b/pkg/relay/udp.go index c1181d7..0eba012 100644 --- a/pkg/relay/udp.go +++ b/pkg/relay/udp.go @@ -2,11 +2,12 @@ package relay import ( "errors" - "github.com/tobyxdd/hysteria/pkg/core" "net" "sync" "sync/atomic" "time" + + "github.com/tobyxdd/hysteria/pkg/core" ) const udpBufferSize = 65535 @@ -24,7 +25,8 @@ type UDPRelay struct { } func NewUDPRelay(hyClient *core.Client, listen, remote string, timeout time.Duration, - connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error)) (*UDPRelay, error) { + connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error), +) (*UDPRelay, error) { uAddr, err := net.ResolveUDPAddr("udp", listen) if err != nil { return nil, err diff --git a/pkg/socks5/server.go b/pkg/socks5/server.go index 3c50c4b..0e33f20 100644 --- a/pkg/socks5/server.go +++ b/pkg/socks5/server.go @@ -4,17 +4,19 @@ import ( "encoding/binary" "errors" "fmt" + "strconv" + "github.com/tobyxdd/hysteria/pkg/acl" "github.com/tobyxdd/hysteria/pkg/core" "github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/utils" - "strconv" ) import ( - "github.com/txthinking/socks5" "net" "time" + + "github.com/txthinking/socks5" ) const udpBufferSize = 65535 @@ -47,7 +49,8 @@ func NewServer(hyClient *core.Client, transport *transport.ClientTransport, addr aclEngine *acl.Engine, disableUDP bool, tcpReqFunc func(addr net.Addr, reqAddr string, action acl.Action, arg string), tcpErrorFunc func(addr net.Addr, reqAddr string, err error), - udpAssocFunc func(addr net.Addr), udpErrorFunc func(addr net.Addr, err error)) (*Server, error) { + udpAssocFunc func(addr net.Addr), udpErrorFunc func(addr net.Addr, err error), +) (*Server, error) { tAddr, err := net.ResolveTCPAddr("tcp", addr) if err != nil { return nil, err diff --git a/pkg/tproxy/tcp_linux.go b/pkg/tproxy/tcp_linux.go index 3d8fc11..fd9bb50 100644 --- a/pkg/tproxy/tcp_linux.go +++ b/pkg/tproxy/tcp_linux.go @@ -1,11 +1,12 @@ package tproxy import ( + "net" + "time" + "github.com/LiamHaworth/go-tproxy" "github.com/tobyxdd/hysteria/pkg/core" "github.com/tobyxdd/hysteria/pkg/utils" - "net" - "time" ) type TCPTProxy struct { @@ -19,7 +20,8 @@ type TCPTProxy struct { func NewTCPTProxy(hyClient *core.Client, listen string, timeout time.Duration, connFunc func(addr, reqAddr net.Addr), - errorFunc func(addr, reqAddr net.Addr, err error)) (*TCPTProxy, error) { + errorFunc func(addr, reqAddr net.Addr, err error), +) (*TCPTProxy, error) { tAddr, err := net.ResolveTCPAddr("tcp", listen) if err != nil { return nil, err diff --git a/pkg/tproxy/tcp_stub.go b/pkg/tproxy/tcp_stub.go index a527c07..ff5766d 100644 --- a/pkg/tproxy/tcp_stub.go +++ b/pkg/tproxy/tcp_stub.go @@ -5,16 +5,18 @@ package tproxy import ( "errors" - "github.com/tobyxdd/hysteria/pkg/core" "net" "time" + + "github.com/tobyxdd/hysteria/pkg/core" ) type TCPTProxy struct{} func NewTCPTProxy(hyClient *core.Client, listen string, timeout time.Duration, connFunc func(addr, reqAddr net.Addr), - errorFunc func(addr, reqAddr net.Addr, err error)) (*TCPTProxy, error) { + errorFunc func(addr, reqAddr net.Addr, err error), +) (*TCPTProxy, error) { return nil, errors.New("not supported on the current system") } diff --git a/pkg/tproxy/udp_linux.go b/pkg/tproxy/udp_linux.go index f28b95b..4df1b5f 100644 --- a/pkg/tproxy/udp_linux.go +++ b/pkg/tproxy/udp_linux.go @@ -1,10 +1,11 @@ package tproxy import ( - "github.com/LiamHaworth/go-tproxy" - "github.com/tobyxdd/hysteria/pkg/core" "net" "time" + + "github.com/LiamHaworth/go-tproxy" + "github.com/tobyxdd/hysteria/pkg/core" ) const udpBufferSize = 65535 @@ -20,7 +21,8 @@ type UDPTProxy struct { func NewUDPTProxy(hyClient *core.Client, listen string, timeout time.Duration, connFunc func(addr, reqAddr net.Addr), - errorFunc func(addr, reqAddr net.Addr, err error)) (*UDPTProxy, error) { + errorFunc func(addr, reqAddr net.Addr, err error), +) (*UDPTProxy, error) { uAddr, err := net.ResolveUDPAddr("udp", listen) if err != nil { return nil, err diff --git a/pkg/tproxy/udp_stub.go b/pkg/tproxy/udp_stub.go index 98b5c42..4fe65df 100644 --- a/pkg/tproxy/udp_stub.go +++ b/pkg/tproxy/udp_stub.go @@ -5,9 +5,10 @@ package tproxy import ( "errors" - "github.com/tobyxdd/hysteria/pkg/core" "net" "time" + + "github.com/tobyxdd/hysteria/pkg/core" ) var ErrTimeout = errors.New("inactivity timeout") @@ -15,7 +16,8 @@ var ErrTimeout = errors.New("inactivity timeout") type UDPTProxy struct{} func NewUDPTProxy(hyClient *core.Client, listen string, timeout time.Duration, - connFunc func(addr, reqAddr net.Addr), errorFunc func(addr, reqAddr net.Addr, err error)) (*UDPTProxy, error) { + connFunc func(addr, reqAddr net.Addr), errorFunc func(addr, reqAddr net.Addr, err error), +) (*UDPTProxy, error) { return nil, errors.New("not supported on the current system") } diff --git a/pkg/transport/client.go b/pkg/transport/client.go index 4ee1722..80417d5 100644 --- a/pkg/transport/client.go +++ b/pkg/transport/client.go @@ -3,13 +3,14 @@ package transport import ( "crypto/tls" "fmt" + "net" + "time" + "github.com/lucas-clemente/quic-go" "github.com/tobyxdd/hysteria/pkg/conns/faketcp" "github.com/tobyxdd/hysteria/pkg/conns/udp" "github.com/tobyxdd/hysteria/pkg/conns/wechat" "github.com/tobyxdd/hysteria/pkg/obfs" - "net" - "time" ) type ClientTransport struct { diff --git a/pkg/transport/server.go b/pkg/transport/server.go index 9890ab3..a2a702d 100644 --- a/pkg/transport/server.go +++ b/pkg/transport/server.go @@ -3,6 +3,10 @@ package transport import ( "crypto/tls" "fmt" + "net" + "strconv" + "time" + "github.com/lucas-clemente/quic-go" "github.com/tobyxdd/hysteria/pkg/conns/faketcp" "github.com/tobyxdd/hysteria/pkg/conns/udp" @@ -10,9 +14,6 @@ import ( "github.com/tobyxdd/hysteria/pkg/obfs" "github.com/tobyxdd/hysteria/pkg/sockopt" "github.com/tobyxdd/hysteria/pkg/utils" - "net" - "strconv" - "time" ) type ServerTransport struct { diff --git a/pkg/transport/socks5.go b/pkg/transport/socks5.go index 50b4388..469db7a 100644 --- a/pkg/transport/socks5.go +++ b/pkg/transport/socks5.go @@ -4,9 +4,10 @@ import ( "encoding/binary" "errors" "fmt" - "github.com/txthinking/socks5" "net" "time" + + "github.com/txthinking/socks5" ) type SOCKS5Client struct { diff --git a/pkg/tun/server.go b/pkg/tun/server.go index b3ed73d..3089a1e 100644 --- a/pkg/tun/server.go +++ b/pkg/tun/server.go @@ -5,6 +5,13 @@ package tun import ( "fmt" + "net" + "os" + "os/signal" + "strconv" + "syscall" + "time" + "github.com/sirupsen/logrus" "github.com/tobyxdd/hysteria/pkg/core" t2score "github.com/xjasonlyu/tun2socks/v2/core" @@ -13,12 +20,6 @@ import ( "github.com/xjasonlyu/tun2socks/v2/core/device/fdbased" "github.com/xjasonlyu/tun2socks/v2/core/device/tun" "gvisor.dev/gvisor/pkg/tcpip/stack" - "net" - "os" - "os/signal" - "strconv" - "syscall" - "time" ) var _ adapter.TransportHandler = (*Server)(nil) diff --git a/pkg/tun/tcp.go b/pkg/tun/tcp.go index df61dcc..9858271 100644 --- a/pkg/tun/tcp.go +++ b/pkg/tun/tcp.go @@ -4,9 +4,10 @@ package tun import ( + "net" + "github.com/tobyxdd/hysteria/pkg/utils" "github.com/xjasonlyu/tun2socks/v2/core/adapter" - "net" ) func (s *Server) HandleTCP(localConn adapter.TCPConn) { diff --git a/pkg/tun/udp.go b/pkg/tun/udp.go index 167fbf3..8b92c67 100644 --- a/pkg/tun/udp.go +++ b/pkg/tun/udp.go @@ -5,11 +5,12 @@ package tun import ( "fmt" - "github.com/tobyxdd/hysteria/pkg/core" - "github.com/xjasonlyu/tun2socks/v2/core/adapter" "net" "strconv" "time" + + "github.com/tobyxdd/hysteria/pkg/core" + "github.com/xjasonlyu/tun2socks/v2/core/adapter" ) const udpBufferSize = 65535