mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-08 05:19:56 +00:00
Fix import cycles
This commit is contained in:
parent
5ac95d987a
commit
3667778ca7
@ -14,6 +14,7 @@ import (
|
||||
"github.com/tobyxdd/hysteria/pkg/relay"
|
||||
"github.com/tobyxdd/hysteria/pkg/socks5"
|
||||
"github.com/tobyxdd/hysteria/pkg/tproxy"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@ -75,7 +76,7 @@ func client(config *clientConfig) {
|
||||
var aclEngine *acl.Engine
|
||||
if len(config.ACL) > 0 {
|
||||
var err error
|
||||
aclEngine, err = acl.LoadFromFile(config.ACL, core.DefaultTransport)
|
||||
aclEngine, err = acl.LoadFromFile(config.ACL, transport.DefaultTransport)
|
||||
if err != nil {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
@ -84,7 +85,7 @@ func client(config *clientConfig) {
|
||||
}
|
||||
}
|
||||
// Client
|
||||
client, err := core.NewClient(config.Server, auth, tlsConfig, quicConfig, core.DefaultTransport,
|
||||
client, err := core.NewClient(config.Server, auth, tlsConfig, quicConfig, transport.DefaultTransport,
|
||||
uint64(config.UpMbps)*mbpsToBps, uint64(config.DownMbps)*mbpsToBps,
|
||||
func(refBPS uint64) congestion.CongestionControl {
|
||||
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
|
||||
@ -105,7 +106,7 @@ func client(config *clientConfig) {
|
||||
return config.SOCKS5.User == user && config.SOCKS5.Password == password
|
||||
}
|
||||
}
|
||||
socks5server, err := socks5.NewServer(client, core.DefaultTransport, config.SOCKS5.Listen, authFunc,
|
||||
socks5server, err := socks5.NewServer(client, transport.DefaultTransport, config.SOCKS5.Listen, authFunc,
|
||||
time.Duration(config.SOCKS5.Timeout)*time.Second, aclEngine, config.SOCKS5.DisableUDP,
|
||||
func(addr net.Addr, reqAddr string, action acl.Action, arg string) {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
@ -161,7 +162,7 @@ func client(config *clientConfig) {
|
||||
return config.HTTP.User == user && config.HTTP.Password == password
|
||||
}
|
||||
}
|
||||
proxy, err := hyHTTP.NewProxyHTTPServer(client, core.DefaultTransport,
|
||||
proxy, err := hyHTTP.NewProxyHTTPServer(client, transport.DefaultTransport,
|
||||
time.Duration(config.HTTP.Timeout)*time.Second, aclEngine,
|
||||
func(reqAddr string, action acl.Action, arg string) {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
@ -185,7 +186,7 @@ func client(config *clientConfig) {
|
||||
|
||||
if len(config.TCPRelay.Listen) > 0 {
|
||||
go func() {
|
||||
rl, err := relay.NewTCPRelay(client, core.DefaultTransport,
|
||||
rl, err := relay.NewTCPRelay(client, transport.DefaultTransport,
|
||||
config.TCPRelay.Listen, config.TCPRelay.Remote,
|
||||
time.Duration(config.TCPRelay.Timeout)*time.Second,
|
||||
func(addr net.Addr) {
|
||||
@ -215,7 +216,7 @@ func client(config *clientConfig) {
|
||||
|
||||
if len(config.UDPRelay.Listen) > 0 {
|
||||
go func() {
|
||||
rl, err := relay.NewUDPRelay(client, core.DefaultTransport,
|
||||
rl, err := relay.NewUDPRelay(client, transport.DefaultTransport,
|
||||
config.UDPRelay.Listen, config.UDPRelay.Remote,
|
||||
time.Duration(config.UDPRelay.Timeout)*time.Second,
|
||||
func(addr net.Addr) {
|
||||
@ -245,7 +246,7 @@ func client(config *clientConfig) {
|
||||
|
||||
if len(config.TCPTProxy.Listen) > 0 {
|
||||
go func() {
|
||||
rl, err := tproxy.NewTCPTProxy(client, core.DefaultTransport,
|
||||
rl, err := tproxy.NewTCPTProxy(client, transport.DefaultTransport,
|
||||
config.TCPTProxy.Listen, time.Duration(config.TCPTProxy.Timeout)*time.Second, aclEngine,
|
||||
func(addr, reqAddr net.Addr, action acl.Action, arg string) {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
@ -278,7 +279,7 @@ func client(config *clientConfig) {
|
||||
|
||||
if len(config.UDPTProxy.Listen) > 0 {
|
||||
go func() {
|
||||
rl, err := tproxy.NewUDPTProxy(client, core.DefaultTransport,
|
||||
rl, err := tproxy.NewUDPTProxy(client, transport.DefaultTransport,
|
||||
config.UDPTProxy.Listen, time.Duration(config.UDPTProxy.Timeout)*time.Second, aclEngine,
|
||||
func(addr net.Addr) {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
hyCongestion "github.com/tobyxdd/hysteria/pkg/congestion"
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
"github.com/tobyxdd/hysteria/pkg/obfs"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"github.com/yosuke-furukawa/json5/encoding/json5"
|
||||
"io"
|
||||
"net"
|
||||
@ -104,7 +105,7 @@ func server(config *serverConfig) {
|
||||
// ACL
|
||||
var aclEngine *acl.Engine
|
||||
if len(config.ACL) > 0 {
|
||||
aclEngine, err = acl.LoadFromFile(config.ACL, core.DefaultTransport)
|
||||
aclEngine, err = acl.LoadFromFile(config.ACL, transport.DefaultTransport)
|
||||
if err != nil {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
@ -123,7 +124,7 @@ func server(config *serverConfig) {
|
||||
logrus.WithField("error", err).Fatal("Prometheus HTTP server error")
|
||||
}()
|
||||
}
|
||||
server, err := core.NewServer(config.Listen, tlsConfig, quicConfig, core.DefaultTransport,
|
||||
server, err := core.NewServer(config.Listen, tlsConfig, quicConfig, transport.DefaultTransport,
|
||||
uint64(config.UpMbps)*mbpsToBps, uint64(config.DownMbps)*mbpsToBps,
|
||||
func(refBPS uint64) congestion.CongestionControl {
|
||||
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
|
||||
|
@ -3,7 +3,7 @@ package acl
|
||||
import (
|
||||
"bufio"
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
@ -15,7 +15,7 @@ type Engine struct {
|
||||
DefaultAction Action
|
||||
Entries []Entry
|
||||
Cache *lru.ARCCache
|
||||
Transport core.Transport
|
||||
Transport transport.Transport
|
||||
}
|
||||
|
||||
type cacheEntry struct {
|
||||
@ -23,7 +23,7 @@ type cacheEntry struct {
|
||||
Arg string
|
||||
}
|
||||
|
||||
func LoadFromFile(filename string, transport core.Transport) (*Engine, error) {
|
||||
func LoadFromFile(filename string, transport transport.Transport) (*Engine, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/lucas-clemente/quic-go/congestion"
|
||||
"github.com/lunixbochs/struc"
|
||||
transport2 "github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"github.com/tobyxdd/hysteria/pkg/utils"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -23,7 +24,7 @@ var (
|
||||
type CongestionFactory func(refBPS uint64) congestion.CongestionControl
|
||||
|
||||
type Client struct {
|
||||
transport Transport
|
||||
transport transport2.Transport
|
||||
serverAddr string
|
||||
sendBPS, recvBPS uint64
|
||||
auth []byte
|
||||
@ -41,7 +42,7 @@ type Client struct {
|
||||
udpSessionMap map[uint32]chan *udpMessage
|
||||
}
|
||||
|
||||
func NewClient(serverAddr string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config, transport Transport,
|
||||
func NewClient(serverAddr string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config, transport transport2.Transport,
|
||||
sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory, obfuscator Obfuscator) (*Client, error) {
|
||||
c := &Client{
|
||||
transport: transport,
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/lunixbochs/struc"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/tobyxdd/hysteria/pkg/acl"
|
||||
transport2 "github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"github.com/tobyxdd/hysteria/pkg/utils"
|
||||
"net"
|
||||
)
|
||||
@ -20,7 +21,7 @@ type UDPRequestFunc func(addr net.Addr, auth []byte, sessionID uint32)
|
||||
type UDPErrorFunc func(addr net.Addr, auth []byte, sessionID uint32, err error)
|
||||
|
||||
type Server struct {
|
||||
transport Transport
|
||||
transport transport2.Transport
|
||||
sendBPS, recvBPS uint64
|
||||
congestionFactory CongestionFactory
|
||||
disableUDP bool
|
||||
@ -37,7 +38,7 @@ type Server struct {
|
||||
listener quic.Listener
|
||||
}
|
||||
|
||||
func NewServer(addr string, tlsConfig *tls.Config, quicConfig *quic.Config, transport Transport,
|
||||
func NewServer(addr string, tlsConfig *tls.Config, quicConfig *quic.Config, transport transport2.Transport,
|
||||
sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory, disableUDP bool, aclEngine *acl.Engine,
|
||||
obfuscator Obfuscator, authFunc AuthFunc, tcpRequestFunc TCPRequestFunc, tcpErrorFunc TCPErrorFunc,
|
||||
udpRequestFunc UDPRequestFunc, udpErrorFunc UDPErrorFunc, promRegistry *prometheus.Registry) (*Server, error) {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"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"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -18,7 +19,7 @@ const udpBufferSize = 65535
|
||||
|
||||
type serverClient struct {
|
||||
CS quic.Session
|
||||
Transport Transport
|
||||
Transport transport.Transport
|
||||
Auth []byte
|
||||
ClientAddr net.Addr
|
||||
DisableUDP bool
|
||||
@ -35,7 +36,7 @@ type serverClient struct {
|
||||
nextUDPSessionID uint32
|
||||
}
|
||||
|
||||
func newServerClient(cs quic.Session, transport Transport, auth []byte, disableUDP bool, ACLEngine *acl.Engine,
|
||||
func newServerClient(cs quic.Session, transport transport.Transport, auth []byte, disableUDP bool, ACLEngine *acl.Engine,
|
||||
CTCPRequestFunc TCPRequestFunc, CTCPErrorFunc TCPErrorFunc,
|
||||
CUDPRequestFunc UDPRequestFunc, CUDPErrorFunc UDPErrorFunc,
|
||||
UpCounterVec, DownCounterVec *prometheus.CounterVec) *serverClient {
|
||||
|
@ -3,6 +3,7 @@ package http
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"github.com/tobyxdd/hysteria/pkg/utils"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -16,7 +17,7 @@ import (
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
)
|
||||
|
||||
func NewProxyHTTPServer(hyClient *core.Client, transport core.Transport, idleTimeout time.Duration, aclEngine *acl.Engine,
|
||||
func NewProxyHTTPServer(hyClient *core.Client, transport transport.Transport, idleTimeout time.Duration, aclEngine *acl.Engine,
|
||||
newDialFunc func(reqAddr string, action acl.Action, arg string),
|
||||
basicAuthFunc func(user, password string) bool) (*goproxy.ProxyHttpServer, error) {
|
||||
proxy := goproxy.NewProxyHttpServer()
|
||||
|
@ -2,6 +2,7 @@ package relay
|
||||
|
||||
import (
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"github.com/tobyxdd/hysteria/pkg/utils"
|
||||
"net"
|
||||
"time"
|
||||
@ -9,7 +10,7 @@ import (
|
||||
|
||||
type TCPRelay struct {
|
||||
HyClient *core.Client
|
||||
Transport core.Transport
|
||||
Transport transport.Transport
|
||||
ListenAddr *net.TCPAddr
|
||||
Remote string
|
||||
Timeout time.Duration
|
||||
@ -18,7 +19,7 @@ type TCPRelay struct {
|
||||
ErrorFunc func(addr net.Addr, err error)
|
||||
}
|
||||
|
||||
func NewTCPRelay(hyClient *core.Client, transport core.Transport, listen, remote string, timeout time.Duration,
|
||||
func NewTCPRelay(hyClient *core.Client, transport transport.Transport, listen, remote string, timeout time.Duration,
|
||||
connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error)) (*TCPRelay, error) {
|
||||
tAddr, err := transport.LocalResolveTCPAddr(listen)
|
||||
if err != nil {
|
||||
|
@ -3,6 +3,7 @@ package relay
|
||||
import (
|
||||
"errors"
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@ -15,7 +16,7 @@ var ErrTimeout = errors.New("inactivity timeout")
|
||||
|
||||
type UDPRelay struct {
|
||||
HyClient *core.Client
|
||||
Transport core.Transport
|
||||
Transport transport.Transport
|
||||
ListenAddr *net.UDPAddr
|
||||
Remote string
|
||||
Timeout time.Duration
|
||||
@ -24,7 +25,7 @@ type UDPRelay struct {
|
||||
ErrorFunc func(addr net.Addr, err error)
|
||||
}
|
||||
|
||||
func NewUDPRelay(hyClient *core.Client, transport core.Transport, listen, remote string, timeout time.Duration,
|
||||
func NewUDPRelay(hyClient *core.Client, transport transport.Transport, listen, remote string, timeout time.Duration,
|
||||
connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error)) (*UDPRelay, error) {
|
||||
uAddr, err := transport.LocalResolveUDPAddr(listen)
|
||||
if err != nil {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"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"
|
||||
)
|
||||
@ -25,7 +26,7 @@ var (
|
||||
|
||||
type Server struct {
|
||||
HyClient *core.Client
|
||||
Transport core.Transport
|
||||
Transport transport.Transport
|
||||
AuthFunc func(username, password string) bool
|
||||
Method byte
|
||||
TCPAddr *net.TCPAddr
|
||||
@ -41,7 +42,7 @@ type Server struct {
|
||||
tcpListener *net.TCPListener
|
||||
}
|
||||
|
||||
func NewServer(hyClient *core.Client, transport core.Transport, addr string,
|
||||
func NewServer(hyClient *core.Client, transport transport.Transport, addr string,
|
||||
authFunc func(username, password string) bool, tcpTimeout time.Duration,
|
||||
aclEngine *acl.Engine, disableUDP bool,
|
||||
tcpReqFunc func(addr net.Addr, reqAddr string, action acl.Action, arg string),
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/LiamHaworth/go-tproxy"
|
||||
"github.com/tobyxdd/hysteria/pkg/acl"
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"github.com/tobyxdd/hysteria/pkg/utils"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -14,7 +15,7 @@ import (
|
||||
|
||||
type TCPTProxy struct {
|
||||
HyClient *core.Client
|
||||
Transport core.Transport
|
||||
Transport transport.Transport
|
||||
ListenAddr *net.TCPAddr
|
||||
Timeout time.Duration
|
||||
ACLEngine *acl.Engine
|
||||
@ -23,7 +24,7 @@ type TCPTProxy struct {
|
||||
ErrorFunc func(addr, reqAddr net.Addr, err error)
|
||||
}
|
||||
|
||||
func NewTCPTProxy(hyClient *core.Client, transport core.Transport, listen string, timeout time.Duration,
|
||||
func NewTCPTProxy(hyClient *core.Client, transport transport.Transport, listen string, timeout time.Duration,
|
||||
aclEngine *acl.Engine,
|
||||
connFunc func(addr, reqAddr net.Addr, action acl.Action, arg string),
|
||||
errorFunc func(addr, reqAddr net.Addr, err error)) (*TCPTProxy, error) {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/LiamHaworth/go-tproxy"
|
||||
"github.com/tobyxdd/hysteria/pkg/acl"
|
||||
"github.com/tobyxdd/hysteria/pkg/core"
|
||||
"github.com/tobyxdd/hysteria/pkg/transport"
|
||||
"github.com/tobyxdd/hysteria/pkg/utils"
|
||||
"net"
|
||||
"strconv"
|
||||
@ -19,7 +20,7 @@ var ErrTimeout = errors.New("inactivity timeout")
|
||||
|
||||
type UDPTProxy struct {
|
||||
HyClient *core.Client
|
||||
Transport core.Transport
|
||||
Transport transport.Transport
|
||||
ListenAddr *net.UDPAddr
|
||||
Timeout time.Duration
|
||||
ACLEngine *acl.Engine
|
||||
@ -28,7 +29,7 @@ type UDPTProxy struct {
|
||||
ErrorFunc func(addr net.Addr, err error)
|
||||
}
|
||||
|
||||
func NewUDPTProxy(hyClient *core.Client, transport core.Transport, listen string, timeout time.Duration,
|
||||
func NewUDPTProxy(hyClient *core.Client, transport transport.Transport, listen string, timeout time.Duration,
|
||||
aclEngine *acl.Engine,
|
||||
connFunc func(addr net.Addr), errorFunc func(addr net.Addr, err error)) (*UDPTProxy, error) {
|
||||
uAddr, err := transport.LocalResolveUDPAddr(listen)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package transport
|
||||
|
||||
import (
|
||||
"net"
|
Loading…
x
Reference in New Issue
Block a user