format: gofumpt

This commit is contained in:
Toby
2022-08-13 11:04:28 -07:00
parent 4747be198e
commit 1462cadfdc
41 changed files with 210 additions and 132 deletions

View File

@@ -3,11 +3,13 @@ package main
import ( import (
"context" "context"
"crypto/tls" "crypto/tls"
"github.com/caddyserver/certmagic" "github.com/caddyserver/certmagic"
) )
func acmeTLSConfig(domains []string, email string, disableHTTP bool, disableTLSALPN bool, 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.Agreed = true
certmagic.DefaultACME.Email = email certmagic.DefaultACME.Email = email
certmagic.DefaultACME.DisableHTTPChallenge = disableHTTP certmagic.DefaultACME.DisableHTTPChallenge = disableHTTP

View File

@@ -1,11 +1,12 @@
package auth package auth
import ( import (
"github.com/sirupsen/logrus"
"net" "net"
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
"github.com/sirupsen/logrus"
) )
type CmdAuthProvider struct { type CmdAuthProvider struct {

View File

@@ -3,10 +3,11 @@ package auth
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"github.com/sirupsen/logrus"
) )
type HTTPAuthProvider struct { type HTTPAuthProvider struct {

View File

@@ -4,10 +4,6 @@ import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors" "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"
"io/ioutil" "io/ioutil"
"net" "net"
@@ -15,6 +11,11 @@ import (
"os" "os"
"time" "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"
"github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/congestion"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"

View File

@@ -4,13 +4,14 @@
package main package main
import ( import (
"github.com/sirupsen/logrus"
"github.com/tobyxdd/hysteria/pkg/core"
"github.com/tobyxdd/hysteria/pkg/tun"
"io" "io"
"net" "net"
"strings" "strings"
"time" "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. const license = `Hysteria is a feature-packed proxy & relay utility optimized for lossy, unstable connections.

View File

@@ -3,11 +3,12 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/sirupsen/logrus"
"github.com/yosuke-furukawa/json5/encoding/json5"
"regexp" "regexp"
"strconv" "strconv"
"time" "time"
"github.com/sirupsen/logrus"
"github.com/yosuke-furukawa/json5/encoding/json5"
) )
const ( const (

View File

@@ -2,9 +2,10 @@ package main
import ( import (
"crypto/tls" "crypto/tls"
"sync"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"sync"
) )
type keypairLoader struct { type keypairLoader struct {

View File

@@ -1,12 +1,13 @@
package main package main
import ( import (
"github.com/oschwald/geoip2-golang"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"io" "io"
"net/http" "net/http"
"os" "os"
"github.com/oschwald/geoip2-golang"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
) )
func downloadMMDB(filename string) error { func downloadMMDB(filename string) error {

View File

@@ -2,10 +2,11 @@ package main
import ( import (
"errors" "errors"
rdns "github.com/folbricht/routedns"
"github.com/tobyxdd/hysteria/pkg/utils"
"net" "net"
"strings" "strings"
rdns "github.com/folbricht/routedns"
"github.com/tobyxdd/hysteria/pkg/utils"
) )
var errInvalidSyntax = errors.New("invalid syntax") var errInvalidSyntax = errors.New("invalid syntax")

View File

@@ -3,6 +3,11 @@ package main
import ( import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"io"
"net"
"net/http"
"time"
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/congestion"
"github.com/oschwald/geoip2-golang" "github.com/oschwald/geoip2-golang"
@@ -18,10 +23,6 @@ import (
"github.com/tobyxdd/hysteria/pkg/sockopt" "github.com/tobyxdd/hysteria/pkg/sockopt"
"github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/transport"
"github.com/yosuke-furukawa/json5/encoding/json5" "github.com/yosuke-furukawa/json5/encoding/json5"
"io"
"net"
"net/http"
"time"
) )
func server(config *serverConfig) { func server(config *serverConfig) {

View File

@@ -2,12 +2,13 @@ package acl
import ( import (
"bufio" "bufio"
lru "github.com/hashicorp/golang-lru"
"github.com/oschwald/geoip2-golang"
"github.com/tobyxdd/hysteria/pkg/utils"
"net" "net"
"os" "os"
"strings" "strings"
lru "github.com/hashicorp/golang-lru"
"github.com/oschwald/geoip2-golang"
"github.com/tobyxdd/hysteria/pkg/utils"
) )
const entryCacheSize = 1024 const entryCacheSize = 1024

View File

@@ -2,10 +2,11 @@ package acl
import ( import (
"errors" "errors"
lru "github.com/hashicorp/golang-lru"
"net" "net"
"strings" "strings"
"testing" "testing"
lru "github.com/hashicorp/golang-lru"
) )
func TestEngine_ResolveAndMatch(t *testing.T) { func TestEngine_ResolveAndMatch(t *testing.T) {

View File

@@ -3,14 +3,17 @@ package acl
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/oschwald/geoip2-golang"
"net" "net"
"strconv" "strconv"
"strings" "strings"
"github.com/oschwald/geoip2-golang"
) )
type Action byte type (
type Protocol byte Action byte
Protocol byte
)
const ( const (
ActionDirect = Action(iota) ActionDirect = Action(iota)

View File

@@ -19,46 +19,64 @@ func TestParseEntry(t *testing.T) {
wantErr bool wantErr bool
}{ }{
{name: "empty", args: args{""}, want: Entry{}, wantErr: true}, {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{ want: Entry{ActionDirect, "", &domainMatcher{
matcherBase: matcherBase{}, matcherBase: matcherBase{},
Domain: "google.com", Domain: "google.com",
Suffix: true, Suffix: true,
}}, }},
wantErr: false}, wantErr: false,
{name: "ok 2", args: args{"proxy domain shithole"}, },
{
name: "ok 2", args: args{"proxy domain shithole"},
want: Entry{ActionProxy, "", &domainMatcher{ want: Entry{ActionProxy, "", &domainMatcher{
matcherBase: matcherBase{}, matcherBase: matcherBase{},
Domain: "shithole", Domain: "shithole",
Suffix: false, Suffix: false,
}}, }},
wantErr: false}, wantErr: false,
{name: "ok 3", args: args{"block cidr 8.8.8.0/24 */53"}, },
{
name: "ok 3", args: args{"block cidr 8.8.8.0/24 */53"},
want: Entry{ActionBlock, "", &netMatcher{ want: Entry{ActionBlock, "", &netMatcher{
matcherBase: matcherBase{ProtocolAll, 53}, matcherBase: matcherBase{ProtocolAll, 53},
Net: ok3net, Net: ok3net,
}}, }},
wantErr: false}, wantErr: false,
{name: "ok 4", args: args{"hijack all udp/* udpblackhole.net"}, },
{
name: "ok 4", args: args{"hijack all udp/* udpblackhole.net"},
want: Entry{ActionHijack, "udpblackhole.net", &allMatcher{ want: Entry{ActionHijack, "udpblackhole.net", &allMatcher{
matcherBase: matcherBase{ProtocolUDP, 0}, matcherBase: matcherBase{ProtocolUDP, 0},
}}, }},
wantErr: false}, wantErr: false,
{name: "err 1", args: args{"what the heck"}, },
{
name: "err 1", args: args{"what the heck"},
want: Entry{}, want: Entry{},
wantErr: true}, wantErr: true,
{name: "err 2", args: args{"proxy sucks ass"}, },
{
name: "err 2", args: args{"proxy sucks ass"},
want: Entry{}, want: Entry{},
wantErr: true}, wantErr: true,
{name: "err 3", args: args{"block ip 999.999.999.999"}, },
{
name: "err 3", args: args{"block ip 999.999.999.999"},
want: Entry{}, want: Entry{},
wantErr: true}, wantErr: true,
{name: "err 4", args: args{"hijack domain google.com"}, },
{
name: "err 4", args: args{"hijack domain google.com"},
want: Entry{}, want: Entry{},
wantErr: true}, wantErr: true,
{name: "err 5", args: args{"hijack domain google.com bing.com 123"}, },
{
name: "err 5", args: args{"hijack domain google.com bing.com 123"},
want: Entry{}, want: Entry{},
wantErr: true}, wantErr: true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@@ -1,8 +1,9 @@
package congestion package congestion
import ( import (
"github.com/lucas-clemente/quic-go/congestion"
"time" "time"
"github.com/lucas-clemente/quic-go/congestion"
) )
const ( const (
@@ -66,12 +67,14 @@ func (b *BrutalSender) GetCongestionWindow() congestion.ByteCount {
} }
func (b *BrutalSender) OnPacketSent(sentTime time.Time, bytesInFlight 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) b.pacer.SentPacket(sentTime, bytes)
} }
func (b *BrutalSender) OnPacketAcked(number congestion.PacketNumber, ackedBytes congestion.ByteCount, 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() currentTimestamp := eventTime.Unix()
slot := currentTimestamp % pktInfoSlotCount slot := currentTimestamp % pktInfoSlotCount
if b.pktInfoSlots[slot].Timestamp == currentTimestamp { 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, func (b *BrutalSender) OnPacketLost(number congestion.PacketNumber, lostBytes congestion.ByteCount,
priorInFlight congestion.ByteCount) { priorInFlight congestion.ByteCount,
) {
currentTimestamp := time.Now().Unix() currentTimestamp := time.Now().Unix()
slot := currentTimestamp % pktInfoSlotCount slot := currentTimestamp % pktInfoSlotCount
if b.pktInfoSlots[slot].Timestamp == currentTimestamp { if b.pktInfoSlots[slot].Timestamp == currentTimestamp {

View File

@@ -1,9 +1,10 @@
package congestion package congestion
import ( import (
"github.com/lucas-clemente/quic-go/congestion"
"math" "math"
"time" "time"
"github.com/lucas-clemente/quic-go/congestion"
) )
const ( const (

View File

@@ -1,11 +1,12 @@
package faketcp package faketcp
import ( import (
"github.com/tobyxdd/hysteria/pkg/obfs"
"net" "net"
"sync" "sync"
"syscall" "syscall"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/obfs"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535

View File

@@ -11,12 +11,14 @@ import (
"testing" "testing"
) )
//const testPortStream = "127.0.0.1:3456" // const testPortStream = "127.0.0.1:3456"
//const testPortPacket = "127.0.0.1:3457" // const testPortPacket = "127.0.0.1:3457"
const testPortStream = "127.0.0.1:3456" const (
const portServerPacket = "[::]:3457" testPortStream = "127.0.0.1:3456"
const portRemotePacket = "127.0.0.1:3457" portServerPacket = "[::]:3457"
portRemotePacket = "127.0.0.1:3457"
)
func init() { func init() {
startTCPServer() startTCPServer()
@@ -70,7 +72,7 @@ func startTCPRawServer() *TCPConn {
log.Println("server readfrom:", err) log.Println("server readfrom:", err)
return return
} }
//echo // echo
n, err = conn.WriteTo(buf[:n], addr) n, err = conn.WriteTo(buf[:n], addr)
if err != nil { if err != nil {
log.Println("server writeTo:", err) log.Println("server writeTo:", err)

View File

@@ -1,12 +1,13 @@
package udp package udp
import ( import (
"github.com/tobyxdd/hysteria/pkg/obfs"
"net" "net"
"os" "os"
"sync" "sync"
"syscall" "syscall"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/obfs"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535

View File

@@ -2,13 +2,14 @@ package wechat
import ( import (
"encoding/binary" "encoding/binary"
"github.com/tobyxdd/hysteria/pkg/obfs"
"math/rand" "math/rand"
"net" "net"
"os" "os"
"sync" "sync"
"syscall" "syscall"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/obfs"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535

View File

@@ -6,6 +6,12 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"math/rand"
"net"
"strconv"
"sync"
"time"
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/congestion" "github.com/lucas-clemente/quic-go/congestion"
"github.com/lunixbochs/struc" "github.com/lunixbochs/struc"
@@ -13,16 +19,9 @@ import (
"github.com/tobyxdd/hysteria/pkg/pmtud_fix" "github.com/tobyxdd/hysteria/pkg/pmtud_fix"
"github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/transport"
"github.com/tobyxdd/hysteria/pkg/utils" "github.com/tobyxdd/hysteria/pkg/utils"
"math/rand"
"net"
"strconv"
"sync"
"time"
) )
var ( var ErrClosed = errors.New("closed")
ErrClosed = errors.New("closed")
)
type CongestionFactory func(refBPS uint64) congestion.CongestionControl 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, func NewClient(serverAddr string, protocol string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config,
transport *transport.ClientTransport, sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory, 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 quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud_fix.DisablePathMTUDiscovery
c := &Client{ c := &Client{
transport: transport, transport: transport,

View File

@@ -32,7 +32,7 @@ func Test_fragUDPMessage(t *testing.T) {
100, 100,
}, },
[]udpMessage{ []udpMessage{
udpMessage{ {
SessionID: 123, SessionID: 123,
HostLen: 4, HostLen: 4,
Host: "test", Host: "test",
@@ -62,7 +62,7 @@ func Test_fragUDPMessage(t *testing.T) {
22, 22,
}, },
[]udpMessage{ []udpMessage{
udpMessage{ {
SessionID: 123, SessionID: 123,
HostLen: 4, HostLen: 4,
Host: "test", Host: "test",
@@ -73,7 +73,7 @@ func Test_fragUDPMessage(t *testing.T) {
DataLen: 4, DataLen: 4,
Data: []byte("hell"), Data: []byte("hell"),
}, },
udpMessage{ {
SessionID: 123, SessionID: 123,
HostLen: 4, HostLen: 4,
Host: "test", Host: "test",
@@ -103,7 +103,7 @@ func Test_fragUDPMessage(t *testing.T) {
23, 23,
}, },
[]udpMessage{ []udpMessage{
udpMessage{ {
SessionID: 123, SessionID: 123,
HostLen: 4, HostLen: 4,
Host: "test", Host: "test",
@@ -114,7 +114,7 @@ func Test_fragUDPMessage(t *testing.T) {
DataLen: 5, DataLen: 5,
Data: []byte("wow w"), Data: []byte("wow w"),
}, },
udpMessage{ {
SessionID: 123, SessionID: 123,
HostLen: 4, HostLen: 4,
Host: "test", Host: "test",
@@ -125,7 +125,7 @@ func Test_fragUDPMessage(t *testing.T) {
DataLen: 5, DataLen: 5,
Data: []byte("ow wo"), Data: []byte("ow wo"),
}, },
udpMessage{ {
SessionID: 123, SessionID: 123,
HostLen: 4, HostLen: 4,
Host: "test", Host: "test",
@@ -136,7 +136,7 @@ func Test_fragUDPMessage(t *testing.T) {
DataLen: 5, DataLen: 5,
Data: []byte("w lol"), Data: []byte("w lol"),
}, },
udpMessage{ {
SessionID: 123, SessionID: 123,
HostLen: 4, HostLen: 4,
Host: "test", Host: "test",

View File

@@ -5,6 +5,8 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"net"
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
"github.com/lunixbochs/struc" "github.com/lunixbochs/struc"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@@ -12,15 +14,16 @@ import (
"github.com/tobyxdd/hysteria/pkg/obfs" "github.com/tobyxdd/hysteria/pkg/obfs"
"github.com/tobyxdd/hysteria/pkg/pmtud_fix" "github.com/tobyxdd/hysteria/pkg/pmtud_fix"
"github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/transport"
"net"
) )
type ConnectFunc func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string) type (
type DisconnectFunc func(addr net.Addr, auth []byte, err error) ConnectFunc func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string)
type TCPRequestFunc func(addr net.Addr, auth []byte, reqAddr string, action acl.Action, arg string) DisconnectFunc func(addr net.Addr, auth []byte, err error)
type TCPErrorFunc func(addr net.Addr, auth []byte, reqAddr string, err error) TCPRequestFunc func(addr net.Addr, auth []byte, reqAddr string, action acl.Action, arg string)
type UDPRequestFunc func(addr net.Addr, auth []byte, sessionID uint32) TCPErrorFunc func(addr net.Addr, auth []byte, reqAddr string, err error)
type UDPErrorFunc func(addr net.Addr, auth []byte, sessionID uint32, 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 { type Server struct {
transport *transport.ServerTransport 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, sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory, disableUDP bool, aclEngine *acl.Engine,
obfuscator obfs.Obfuscator, connectFunc ConnectFunc, disconnectFunc DisconnectFunc, obfuscator obfs.Obfuscator, connectFunc ConnectFunc, disconnectFunc DisconnectFunc,
tcpRequestFunc TCPRequestFunc, tcpErrorFunc TCPErrorFunc, 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 quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud_fix.DisablePathMTUDiscovery
listener, err := transport.QUICListen(protocol, addr, tlsConfig, quicConfig, obfuscator) listener, err := transport.QUICListen(protocol, addr, tlsConfig, quicConfig, obfuscator)
if err != nil { if err != nil {

View File

@@ -4,16 +4,17 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/base64" "encoding/base64"
"math/rand"
"net"
"strconv"
"sync"
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
"github.com/lunixbochs/struc" "github.com/lunixbochs/struc"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/tobyxdd/hysteria/pkg/acl" "github.com/tobyxdd/hysteria/pkg/acl"
"github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/transport"
"github.com/tobyxdd/hysteria/pkg/utils" "github.com/tobyxdd/hysteria/pkg/utils"
"math/rand"
"net"
"strconv"
"sync"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535
@@ -44,7 +45,8 @@ func newServerClient(v2 bool, cs quic.Connection, tr *transport.ServerTransport,
CTCPRequestFunc TCPRequestFunc, CTCPErrorFunc TCPErrorFunc, CTCPRequestFunc TCPRequestFunc, CTCPErrorFunc TCPErrorFunc,
CUDPRequestFunc UDPRequestFunc, CUDPErrorFunc UDPErrorFunc, CUDPRequestFunc UDPRequestFunc, CUDPErrorFunc UDPErrorFunc,
UpCounterVec, DownCounterVec *prometheus.CounterVec, UpCounterVec, DownCounterVec *prometheus.CounterVec,
ConnGaugeVec *prometheus.GaugeVec) *serverClient { ConnGaugeVec *prometheus.GaugeVec,
) *serverClient {
sc := &serverClient{ sc := &serverClient{
V2: v2, V2: v2,
CS: cs, CS: cs,

View File

@@ -2,8 +2,9 @@ package core
import ( import (
"context" "context"
"github.com/lucas-clemente/quic-go"
"time" "time"
"github.com/lucas-clemente/quic-go"
) )
// Handle stream close properly // Handle stream close properly

View File

@@ -3,12 +3,13 @@ package http
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/tobyxdd/hysteria/pkg/transport"
"github.com/tobyxdd/hysteria/pkg/utils"
"net" "net"
"net/http" "net/http"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/transport"
"github.com/tobyxdd/hysteria/pkg/utils"
"github.com/elazarl/goproxy/ext/auth" "github.com/elazarl/goproxy/ext/auth"
"github.com/elazarl/goproxy" "github.com/elazarl/goproxy"
@@ -18,7 +19,8 @@ import (
func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransport, idleTimeout time.Duration, func NewProxyHTTPServer(hyClient *core.Client, transport *transport.ClientTransport, idleTimeout time.Duration,
aclEngine *acl.Engine, newDialFunc func(reqAddr string, action acl.Action, arg string), 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 := goproxy.NewProxyHttpServer()
proxy.Logger = &nopLogger{} proxy.Logger = &nopLogger{}
proxy.NonproxyHandler = http.NotFoundHandler() proxy.NonproxyHandler = http.NotFoundHandler()

View File

@@ -3,11 +3,12 @@ package redirect
import ( import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"github.com/tobyxdd/hysteria/pkg/core"
"github.com/tobyxdd/hysteria/pkg/utils"
"net" "net"
"syscall" "syscall"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/core"
"github.com/tobyxdd/hysteria/pkg/utils"
) )
type TCPRedirect struct { type TCPRedirect struct {
@@ -21,7 +22,8 @@ type TCPRedirect struct {
func NewTCPRedirect(hyClient *core.Client, listen string, timeout time.Duration, func NewTCPRedirect(hyClient *core.Client, listen string, timeout time.Duration,
connFunc func(addr, reqAddr net.Addr), 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) tAddr, err := net.ResolveTCPAddr("tcp", listen)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -5,16 +5,18 @@ package redirect
import ( import (
"errors" "errors"
"github.com/tobyxdd/hysteria/pkg/core"
"net" "net"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/core"
) )
type TCPRedirect struct{} type TCPRedirect struct{}
func NewTCPRedirect(hyClient *core.Client, listen string, timeout time.Duration, func NewTCPRedirect(hyClient *core.Client, listen string, timeout time.Duration,
connFunc func(addr, reqAddr net.Addr), 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") return nil, errors.New("not supported on the current system")
} }

View File

@@ -1,10 +1,11 @@
package relay package relay
import ( import (
"github.com/tobyxdd/hysteria/pkg/core"
"github.com/tobyxdd/hysteria/pkg/utils"
"net" "net"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/core"
"github.com/tobyxdd/hysteria/pkg/utils"
) )
type TCPRelay struct { type TCPRelay struct {
@@ -18,7 +19,8 @@ type TCPRelay struct {
} }
func NewTCPRelay(hyClient *core.Client, listen, remote string, timeout time.Duration, 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) tAddr, err := net.ResolveTCPAddr("tcp", listen)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -2,11 +2,12 @@ package relay
import ( import (
"errors" "errors"
"github.com/tobyxdd/hysteria/pkg/core"
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/core"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535
@@ -24,7 +25,8 @@ type UDPRelay struct {
} }
func NewUDPRelay(hyClient *core.Client, listen, remote string, timeout time.Duration, 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) uAddr, err := net.ResolveUDPAddr("udp", listen)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -4,17 +4,19 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"strconv"
"github.com/tobyxdd/hysteria/pkg/acl" "github.com/tobyxdd/hysteria/pkg/acl"
"github.com/tobyxdd/hysteria/pkg/core" "github.com/tobyxdd/hysteria/pkg/core"
"github.com/tobyxdd/hysteria/pkg/transport" "github.com/tobyxdd/hysteria/pkg/transport"
"github.com/tobyxdd/hysteria/pkg/utils" "github.com/tobyxdd/hysteria/pkg/utils"
"strconv"
) )
import ( import (
"github.com/txthinking/socks5"
"net" "net"
"time" "time"
"github.com/txthinking/socks5"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535
@@ -47,7 +49,8 @@ func NewServer(hyClient *core.Client, transport *transport.ClientTransport, addr
aclEngine *acl.Engine, disableUDP bool, aclEngine *acl.Engine, disableUDP bool,
tcpReqFunc func(addr net.Addr, reqAddr string, action acl.Action, arg string), tcpReqFunc func(addr net.Addr, reqAddr string, action acl.Action, arg string),
tcpErrorFunc func(addr net.Addr, reqAddr string, err error), 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) tAddr, err := net.ResolveTCPAddr("tcp", addr)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -1,11 +1,12 @@
package tproxy package tproxy
import ( import (
"net"
"time"
"github.com/LiamHaworth/go-tproxy" "github.com/LiamHaworth/go-tproxy"
"github.com/tobyxdd/hysteria/pkg/core" "github.com/tobyxdd/hysteria/pkg/core"
"github.com/tobyxdd/hysteria/pkg/utils" "github.com/tobyxdd/hysteria/pkg/utils"
"net"
"time"
) )
type TCPTProxy struct { type TCPTProxy struct {
@@ -19,7 +20,8 @@ type TCPTProxy struct {
func NewTCPTProxy(hyClient *core.Client, listen string, timeout time.Duration, func NewTCPTProxy(hyClient *core.Client, listen string, timeout time.Duration,
connFunc func(addr, reqAddr net.Addr), 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) tAddr, err := net.ResolveTCPAddr("tcp", listen)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -5,16 +5,18 @@ package tproxy
import ( import (
"errors" "errors"
"github.com/tobyxdd/hysteria/pkg/core"
"net" "net"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/core"
) )
type TCPTProxy struct{} type TCPTProxy struct{}
func NewTCPTProxy(hyClient *core.Client, listen string, timeout time.Duration, func NewTCPTProxy(hyClient *core.Client, listen string, timeout time.Duration,
connFunc func(addr, reqAddr net.Addr), 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") return nil, errors.New("not supported on the current system")
} }

View File

@@ -1,10 +1,11 @@
package tproxy package tproxy
import ( import (
"github.com/LiamHaworth/go-tproxy"
"github.com/tobyxdd/hysteria/pkg/core"
"net" "net"
"time" "time"
"github.com/LiamHaworth/go-tproxy"
"github.com/tobyxdd/hysteria/pkg/core"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535
@@ -20,7 +21,8 @@ type UDPTProxy struct {
func NewUDPTProxy(hyClient *core.Client, listen string, timeout time.Duration, func NewUDPTProxy(hyClient *core.Client, listen string, timeout time.Duration,
connFunc func(addr, reqAddr net.Addr), 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) uAddr, err := net.ResolveUDPAddr("udp", listen)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -5,9 +5,10 @@ package tproxy
import ( import (
"errors" "errors"
"github.com/tobyxdd/hysteria/pkg/core"
"net" "net"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/core"
) )
var ErrTimeout = errors.New("inactivity timeout") var ErrTimeout = errors.New("inactivity timeout")
@@ -15,7 +16,8 @@ var ErrTimeout = errors.New("inactivity timeout")
type UDPTProxy struct{} type UDPTProxy struct{}
func NewUDPTProxy(hyClient *core.Client, listen string, timeout time.Duration, 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") return nil, errors.New("not supported on the current system")
} }

View File

@@ -3,13 +3,14 @@ package transport
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net"
"time"
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
"github.com/tobyxdd/hysteria/pkg/conns/faketcp" "github.com/tobyxdd/hysteria/pkg/conns/faketcp"
"github.com/tobyxdd/hysteria/pkg/conns/udp" "github.com/tobyxdd/hysteria/pkg/conns/udp"
"github.com/tobyxdd/hysteria/pkg/conns/wechat" "github.com/tobyxdd/hysteria/pkg/conns/wechat"
"github.com/tobyxdd/hysteria/pkg/obfs" "github.com/tobyxdd/hysteria/pkg/obfs"
"net"
"time"
) )
type ClientTransport struct { type ClientTransport struct {

View File

@@ -3,6 +3,10 @@ package transport
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net"
"strconv"
"time"
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
"github.com/tobyxdd/hysteria/pkg/conns/faketcp" "github.com/tobyxdd/hysteria/pkg/conns/faketcp"
"github.com/tobyxdd/hysteria/pkg/conns/udp" "github.com/tobyxdd/hysteria/pkg/conns/udp"
@@ -10,9 +14,6 @@ import (
"github.com/tobyxdd/hysteria/pkg/obfs" "github.com/tobyxdd/hysteria/pkg/obfs"
"github.com/tobyxdd/hysteria/pkg/sockopt" "github.com/tobyxdd/hysteria/pkg/sockopt"
"github.com/tobyxdd/hysteria/pkg/utils" "github.com/tobyxdd/hysteria/pkg/utils"
"net"
"strconv"
"time"
) )
type ServerTransport struct { type ServerTransport struct {

View File

@@ -4,9 +4,10 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"github.com/txthinking/socks5"
"net" "net"
"time" "time"
"github.com/txthinking/socks5"
) )
type SOCKS5Client struct { type SOCKS5Client struct {

View File

@@ -5,6 +5,13 @@ package tun
import ( import (
"fmt" "fmt"
"net"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/tobyxdd/hysteria/pkg/core" "github.com/tobyxdd/hysteria/pkg/core"
t2score "github.com/xjasonlyu/tun2socks/v2/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/fdbased"
"github.com/xjasonlyu/tun2socks/v2/core/device/tun" "github.com/xjasonlyu/tun2socks/v2/core/device/tun"
"gvisor.dev/gvisor/pkg/tcpip/stack" "gvisor.dev/gvisor/pkg/tcpip/stack"
"net"
"os"
"os/signal"
"strconv"
"syscall"
"time"
) )
var _ adapter.TransportHandler = (*Server)(nil) var _ adapter.TransportHandler = (*Server)(nil)

View File

@@ -4,9 +4,10 @@
package tun package tun
import ( import (
"net"
"github.com/tobyxdd/hysteria/pkg/utils" "github.com/tobyxdd/hysteria/pkg/utils"
"github.com/xjasonlyu/tun2socks/v2/core/adapter" "github.com/xjasonlyu/tun2socks/v2/core/adapter"
"net"
) )
func (s *Server) HandleTCP(localConn adapter.TCPConn) { func (s *Server) HandleTCP(localConn adapter.TCPConn) {

View File

@@ -5,11 +5,12 @@ package tun
import ( import (
"fmt" "fmt"
"github.com/tobyxdd/hysteria/pkg/core"
"github.com/xjasonlyu/tun2socks/v2/core/adapter"
"net" "net"
"strconv" "strconv"
"time" "time"
"github.com/tobyxdd/hysteria/pkg/core"
"github.com/xjasonlyu/tun2socks/v2/core/adapter"
) )
const udpBufferSize = 65535 const udpBufferSize = 65535