mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-08 13:29:53 +00:00
chore: naming adjustments
This commit is contained in:
parent
a2fbcc6507
commit
1f499f07c7
@ -146,8 +146,8 @@ func (h *h3sHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if !h.config.DisableUDP {
|
||||
h.udpOnce.Do(func() {
|
||||
sm := newUDPSessionManager(
|
||||
&udpsmIO{h.conn, id, h.config.TrafficLogger, h.config.Outbound},
|
||||
&udpsmEventLogger{h.conn, id, h.config.EventLogger},
|
||||
&udpIOImpl{h.conn, id, h.config.TrafficLogger, h.config.Outbound},
|
||||
&udpEventLoggerImpl{h.conn, id, h.config.EventLogger},
|
||||
udpSessionIdleTimeout)
|
||||
h.udpSM = sm
|
||||
go sm.Run()
|
||||
@ -231,15 +231,15 @@ func (h *h3sHandler) masqHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// udpsmIO is the IO implementation for udpSessionManager with TrafficLogger support
|
||||
type udpsmIO struct {
|
||||
// udpIOImpl is the IO implementation for udpSessionManager with TrafficLogger support
|
||||
type udpIOImpl struct {
|
||||
Conn quic.Connection
|
||||
AuthID string
|
||||
TrafficLogger TrafficLogger
|
||||
Outbound Outbound
|
||||
}
|
||||
|
||||
func (io *udpsmIO) ReceiveMessage() (*protocol.UDPMessage, error) {
|
||||
func (io *udpIOImpl) ReceiveMessage() (*protocol.UDPMessage, error) {
|
||||
for {
|
||||
msg, err := io.Conn.ReceiveMessage()
|
||||
if err != nil {
|
||||
@ -263,7 +263,7 @@ func (io *udpsmIO) ReceiveMessage() (*protocol.UDPMessage, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (io *udpsmIO) SendMessage(buf []byte, msg *protocol.UDPMessage) error {
|
||||
func (io *udpIOImpl) SendMessage(buf []byte, msg *protocol.UDPMessage) error {
|
||||
if io.TrafficLogger != nil {
|
||||
ok := io.TrafficLogger.Log(io.AuthID, 0, uint64(len(msg.Data)))
|
||||
if !ok {
|
||||
@ -280,23 +280,23 @@ func (io *udpsmIO) SendMessage(buf []byte, msg *protocol.UDPMessage) error {
|
||||
return io.Conn.SendMessage(buf[:msgN])
|
||||
}
|
||||
|
||||
func (io *udpsmIO) DialUDP(reqAddr string) (UDPConn, error) {
|
||||
func (io *udpIOImpl) DialUDP(reqAddr string) (UDPConn, error) {
|
||||
return io.Outbound.DialUDP(reqAddr)
|
||||
}
|
||||
|
||||
type udpsmEventLogger struct {
|
||||
type udpEventLoggerImpl struct {
|
||||
Conn quic.Connection
|
||||
AuthID string
|
||||
EventLogger EventLogger
|
||||
}
|
||||
|
||||
func (l *udpsmEventLogger) New(sessionID uint32, reqAddr string) {
|
||||
func (l *udpEventLoggerImpl) New(sessionID uint32, reqAddr string) {
|
||||
if l.EventLogger != nil {
|
||||
l.EventLogger.UDPRequest(l.Conn.RemoteAddr(), l.AuthID, sessionID, reqAddr)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *udpsmEventLogger) Closed(sessionID uint32, err error) {
|
||||
func (l *udpEventLoggerImpl) Closed(sessionID uint32, err error) {
|
||||
if l.EventLogger != nil {
|
||||
l.EventLogger.UDPError(l.Conn.RemoteAddr(), l.AuthID, sessionID, err)
|
||||
}
|
||||
|
@ -17,13 +17,13 @@ const (
|
||||
idleCleanupInterval = 1 * time.Second
|
||||
)
|
||||
|
||||
type udpSessionManagerIO interface {
|
||||
type udpIO interface {
|
||||
ReceiveMessage() (*protocol.UDPMessage, error)
|
||||
SendMessage([]byte, *protocol.UDPMessage) error
|
||||
DialUDP(reqAddr string) (UDPConn, error)
|
||||
}
|
||||
|
||||
type udpSessionManagerEventLogger interface {
|
||||
type udpEventLogger interface {
|
||||
New(sessionID uint32, reqAddr string)
|
||||
Closed(sessionID uint32, err error)
|
||||
}
|
||||
@ -54,7 +54,7 @@ func (e *udpSessionEntry) Feed(msg *protocol.UDPMessage) (int, error) {
|
||||
// and sends using the provided io.
|
||||
// Exit and returns error when either the underlying UDP connection returns
|
||||
// error (e.g. closed), or the provided io returns error when sending.
|
||||
func (e *udpSessionEntry) ReceiveLoop(io udpSessionManagerIO) error {
|
||||
func (e *udpSessionEntry) ReceiveLoop(io udpIO) error {
|
||||
udpBuf := make([]byte, protocol.MaxUDPSize)
|
||||
msgBuf := make([]byte, protocol.MaxUDPSize)
|
||||
for {
|
||||
@ -82,7 +82,7 @@ func (e *udpSessionEntry) ReceiveLoop(io udpSessionManagerIO) error {
|
||||
// sendMessageAutoFrag tries to send a UDP message as a whole first,
|
||||
// but if it fails due to quic.ErrMessageTooLarge, it tries again by
|
||||
// fragmenting the message.
|
||||
func sendMessageAutoFrag(io udpSessionManagerIO, buf []byte, msg *protocol.UDPMessage) error {
|
||||
func sendMessageAutoFrag(io udpIO, buf []byte, msg *protocol.UDPMessage) error {
|
||||
err := io.SendMessage(buf, msg)
|
||||
var errTooLarge quic.ErrMessageTooLarge
|
||||
if errors.As(err, &errTooLarge) {
|
||||
@ -107,8 +107,8 @@ func sendMessageAutoFrag(io udpSessionManagerIO, buf []byte, msg *protocol.UDPMe
|
||||
// Similar to standard NAT, a UDP session is destroyed when no UDP message is received
|
||||
// for a certain period of time (specified by idleTimeout).
|
||||
type udpSessionManager struct {
|
||||
io udpSessionManagerIO
|
||||
eventLogger udpSessionManagerEventLogger
|
||||
io udpIO
|
||||
eventLogger udpEventLogger
|
||||
idleTimeout time.Duration
|
||||
|
||||
mutex sync.Mutex
|
||||
@ -116,11 +116,7 @@ type udpSessionManager struct {
|
||||
nextID uint32
|
||||
}
|
||||
|
||||
func newUDPSessionManager(
|
||||
io udpSessionManagerIO,
|
||||
eventLogger udpSessionManagerEventLogger,
|
||||
idleTimeout time.Duration,
|
||||
) *udpSessionManager {
|
||||
func newUDPSessionManager(io udpIO, eventLogger udpEventLogger, idleTimeout time.Duration) *udpSessionManager {
|
||||
return &udpSessionManager{
|
||||
io: io,
|
||||
eventLogger: eventLogger,
|
||||
|
@ -46,12 +46,12 @@ func (c *echoUDPConn) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type udpsmMockIO struct {
|
||||
type udpMockIO struct {
|
||||
ReceiveCh <-chan *protocol.UDPMessage
|
||||
SendCh chan<- *protocol.UDPMessage
|
||||
}
|
||||
|
||||
func (io *udpsmMockIO) ReceiveMessage() (*protocol.UDPMessage, error) {
|
||||
func (io *udpMockIO) ReceiveMessage() (*protocol.UDPMessage, error) {
|
||||
m := <-io.ReceiveCh
|
||||
if m == nil {
|
||||
return nil, errors.New("closed")
|
||||
@ -59,7 +59,7 @@ func (io *udpsmMockIO) ReceiveMessage() (*protocol.UDPMessage, error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (io *udpsmMockIO) SendMessage(buf []byte, msg *protocol.UDPMessage) error {
|
||||
func (io *udpMockIO) SendMessage(buf []byte, msg *protocol.UDPMessage) error {
|
||||
nMsg := *msg
|
||||
nMsg.Data = make([]byte, len(msg.Data))
|
||||
copy(nMsg.Data, msg.Data)
|
||||
@ -67,45 +67,45 @@ func (io *udpsmMockIO) SendMessage(buf []byte, msg *protocol.UDPMessage) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (io *udpsmMockIO) DialUDP(reqAddr string) (UDPConn, error) {
|
||||
func (io *udpMockIO) DialUDP(reqAddr string) (UDPConn, error) {
|
||||
return &echoUDPConn{
|
||||
PktCh: make(chan echoUDPConnPkt, 10),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type udpsmMockEventNew struct {
|
||||
type udpMockEventNew struct {
|
||||
SessionID uint32
|
||||
ReqAddr string
|
||||
}
|
||||
|
||||
type udpsmMockEventClosed struct {
|
||||
type udpMockEventClosed struct {
|
||||
SessionID uint32
|
||||
Err error
|
||||
}
|
||||
|
||||
type udpsmMockEventLogger struct {
|
||||
NewCh chan<- udpsmMockEventNew
|
||||
ClosedCh chan<- udpsmMockEventClosed
|
||||
type udpMockEventLogger struct {
|
||||
NewCh chan<- udpMockEventNew
|
||||
ClosedCh chan<- udpMockEventClosed
|
||||
}
|
||||
|
||||
func (l *udpsmMockEventLogger) New(sessionID uint32, reqAddr string) {
|
||||
l.NewCh <- udpsmMockEventNew{sessionID, reqAddr}
|
||||
func (l *udpMockEventLogger) New(sessionID uint32, reqAddr string) {
|
||||
l.NewCh <- udpMockEventNew{sessionID, reqAddr}
|
||||
}
|
||||
|
||||
func (l *udpsmMockEventLogger) Closed(sessionID uint32, err error) {
|
||||
l.ClosedCh <- udpsmMockEventClosed{sessionID, err}
|
||||
func (l *udpMockEventLogger) Closed(sessionID uint32, err error) {
|
||||
l.ClosedCh <- udpMockEventClosed{sessionID, err}
|
||||
}
|
||||
|
||||
func TestUDPSessionManager(t *testing.T) {
|
||||
msgReceiveCh := make(chan *protocol.UDPMessage, 10)
|
||||
msgSendCh := make(chan *protocol.UDPMessage, 10)
|
||||
io := &udpsmMockIO{
|
||||
io := &udpMockIO{
|
||||
ReceiveCh: msgReceiveCh,
|
||||
SendCh: msgSendCh,
|
||||
}
|
||||
eventNewCh := make(chan udpsmMockEventNew, 10)
|
||||
eventClosedCh := make(chan udpsmMockEventClosed, 10)
|
||||
eventLogger := &udpsmMockEventLogger{
|
||||
eventNewCh := make(chan udpMockEventNew, 10)
|
||||
eventClosedCh := make(chan udpMockEventClosed, 10)
|
||||
eventLogger := &udpMockEventLogger{
|
||||
NewCh: eventNewCh,
|
||||
ClosedCh: eventClosedCh,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user