mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:18:31 +02:00
refactor: code cleanup
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/net/types"
|
||||
gpnet "github.com/yusing/go-proxy/internal/net/types"
|
||||
U "github.com/yusing/go-proxy/internal/utils"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ type (
|
||||
Stream struct {
|
||||
*StreamRoute
|
||||
|
||||
listener types.StreamListener
|
||||
listener gpnet.StreamListener
|
||||
targetAddr net.Addr
|
||||
}
|
||||
)
|
||||
@@ -56,7 +56,7 @@ func (stream *Stream) Setup() error {
|
||||
}
|
||||
// in case ListeningPort was zero, get the actual port
|
||||
stream.Port.Listening = tcpListener.Addr().(*net.TCPAddr).Port
|
||||
stream.listener = types.NetListener(tcpListener)
|
||||
stream.listener = gpnet.NetListener(tcpListener)
|
||||
case "udp":
|
||||
stream.targetAddr, err = net.ResolveUDPAddr("udp", stream.ProxyURL.Host)
|
||||
if err != nil {
|
||||
@@ -80,7 +80,7 @@ func (stream *Stream) Setup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (stream *Stream) Accept() (conn types.StreamConn, err error) {
|
||||
func (stream *Stream) Accept() (conn gpnet.StreamConn, err error) {
|
||||
if stream.listener == nil {
|
||||
return nil, errors.New("listener is nil")
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (stream *Stream) Accept() (conn types.StreamConn, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (stream *Stream) Handle(conn types.StreamConn) error {
|
||||
func (stream *Stream) Handle(conn gpnet.StreamConn) error {
|
||||
switch conn := conn.(type) {
|
||||
case *UDPConn:
|
||||
switch stream := stream.listener.(type) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/yusing/go-proxy/internal/gperr"
|
||||
"github.com/yusing/go-proxy/internal/logging"
|
||||
"github.com/yusing/go-proxy/internal/net/types"
|
||||
gpnet "github.com/yusing/go-proxy/internal/net/types"
|
||||
F "github.com/yusing/go-proxy/internal/utils/functional"
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ func (w *UDPForwarder) Addr() net.Addr {
|
||||
return w.forwarder.LocalAddr()
|
||||
}
|
||||
|
||||
func (w *UDPForwarder) Accept() (types.StreamConn, error) {
|
||||
func (w *UDPForwarder) Accept() (gpnet.StreamConn, error) {
|
||||
buf := newUDPBuf()
|
||||
addr, err := w.readFromListener(buf)
|
||||
if err != nil {
|
||||
@@ -161,7 +161,7 @@ func (w *UDPForwarder) getInitConn(conn *UDPConn, key string) (*UDPConn, error)
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func (w *UDPForwarder) Handle(streamConn types.StreamConn) error {
|
||||
func (w *UDPForwarder) Handle(streamConn gpnet.StreamConn) error {
|
||||
conn, ok := streamConn.(*UDPConn)
|
||||
if !ok {
|
||||
panic("unexpected conn type")
|
||||
|
||||
Reference in New Issue
Block a user