mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-23 13:09:49 +00:00
feat: dynamic client IP for server logs (connection migration)
This commit is contained in:
parent
72b9ddcfa4
commit
21b2830289
@ -23,7 +23,6 @@ type serverClient struct {
|
|||||||
CC quic.Connection
|
CC quic.Connection
|
||||||
Transport *transport.ServerTransport
|
Transport *transport.ServerTransport
|
||||||
Auth []byte
|
Auth []byte
|
||||||
ClientAddr net.Addr
|
|
||||||
DisableUDP bool
|
DisableUDP bool
|
||||||
ACLEngine *acl.Engine
|
ACLEngine *acl.Engine
|
||||||
CTCPRequestFunc TCPRequestFunc
|
CTCPRequestFunc TCPRequestFunc
|
||||||
@ -50,7 +49,6 @@ func newServerClient(cc quic.Connection, tr *transport.ServerTransport, auth []b
|
|||||||
CC: cc,
|
CC: cc,
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
ClientAddr: cc.RemoteAddr(),
|
|
||||||
DisableUDP: disableUDP,
|
DisableUDP: disableUDP,
|
||||||
ACLEngine: ACLEngine,
|
ACLEngine: ACLEngine,
|
||||||
CTCPRequestFunc: CTCPRequestFunc,
|
CTCPRequestFunc: CTCPRequestFunc,
|
||||||
@ -68,6 +66,12 @@ func newServerClient(cc quic.Connection, tr *transport.ServerTransport, auth []b
|
|||||||
return sc
|
return sc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *serverClient) ClientAddr() net.Addr {
|
||||||
|
// quic.Connection's remote address may change since we have connection migration now,
|
||||||
|
// so logs need to dynamically get the remote address every time.
|
||||||
|
return c.CC.RemoteAddr()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *serverClient) Run() error {
|
func (c *serverClient) Run() error {
|
||||||
if !c.DisableUDP {
|
if !c.DisableUDP {
|
||||||
go func() {
|
go func() {
|
||||||
@ -200,10 +204,10 @@ func (c *serverClient) handleTCP(stream quic.Stream, host string, port uint16) {
|
|||||||
OK: false,
|
OK: false,
|
||||||
Message: "host resolution failure",
|
Message: "host resolution failure",
|
||||||
})
|
})
|
||||||
c.CTCPErrorFunc(c.ClientAddr, c.Auth, addrStr, err)
|
c.CTCPErrorFunc(c.ClientAddr(), c.Auth, addrStr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.CTCPRequestFunc(c.ClientAddr, c.Auth, addrStr, action, arg)
|
c.CTCPRequestFunc(c.ClientAddr(), c.Auth, addrStr, action, arg)
|
||||||
|
|
||||||
var conn net.Conn // Connection to be piped
|
var conn net.Conn // Connection to be piped
|
||||||
switch action {
|
switch action {
|
||||||
@ -221,7 +225,7 @@ func (c *serverClient) handleTCP(stream quic.Stream, host string, port uint16) {
|
|||||||
OK: false,
|
OK: false,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
c.CTCPErrorFunc(c.ClientAddr, c.Auth, addrStr, err)
|
c.CTCPErrorFunc(c.ClientAddr(), c.Auth, addrStr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case acl.ActionBlock:
|
case acl.ActionBlock:
|
||||||
@ -237,7 +241,7 @@ func (c *serverClient) handleTCP(stream quic.Stream, host string, port uint16) {
|
|||||||
OK: false,
|
OK: false,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
c.CTCPErrorFunc(c.ClientAddr, c.Auth, addrStr, err)
|
c.CTCPErrorFunc(c.ClientAddr(), c.Auth, addrStr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
addrEx := &transport.AddrEx{
|
addrEx := &transport.AddrEx{
|
||||||
@ -253,7 +257,7 @@ func (c *serverClient) handleTCP(stream quic.Stream, host string, port uint16) {
|
|||||||
OK: false,
|
OK: false,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
c.CTCPErrorFunc(c.ClientAddr, c.Auth, addrStr, err)
|
c.CTCPErrorFunc(c.ClientAddr(), c.Auth, addrStr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -282,7 +286,7 @@ func (c *serverClient) handleTCP(stream quic.Stream, host string, port uint16) {
|
|||||||
} else {
|
} else {
|
||||||
err = utils.Pipe2Way(stream, conn, nil)
|
err = utils.Pipe2Way(stream, conn, nil)
|
||||||
}
|
}
|
||||||
c.CTCPErrorFunc(c.ClientAddr, c.Auth, addrStr, err)
|
c.CTCPErrorFunc(c.ClientAddr(), c.Auth, addrStr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *serverClient) handleUDP(stream quic.Stream) {
|
func (c *serverClient) handleUDP(stream quic.Stream) {
|
||||||
@ -293,7 +297,7 @@ func (c *serverClient) handleUDP(stream quic.Stream) {
|
|||||||
OK: false,
|
OK: false,
|
||||||
Message: "UDP initialization failed",
|
Message: "UDP initialization failed",
|
||||||
})
|
})
|
||||||
c.CUDPErrorFunc(c.ClientAddr, c.Auth, 0, err)
|
c.CUDPErrorFunc(c.ClientAddr(), c.Auth, 0, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
@ -312,7 +316,7 @@ func (c *serverClient) handleUDP(stream quic.Stream) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.CUDPRequestFunc(c.ClientAddr, c.Auth, id)
|
c.CUDPRequestFunc(c.ClientAddr(), c.Auth, id)
|
||||||
|
|
||||||
// Receive UDP packets, send them to the client
|
// Receive UDP packets, send them to the client
|
||||||
go func() {
|
go func() {
|
||||||
@ -362,7 +366,7 @@ func (c *serverClient) handleUDP(stream quic.Stream) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.CUDPErrorFunc(c.ClientAddr, c.Auth, id, err)
|
c.CUDPErrorFunc(c.ClientAddr(), c.Auth, id, err)
|
||||||
|
|
||||||
// Remove the session
|
// Remove the session
|
||||||
c.udpSessionMutex.Lock()
|
c.udpSessionMutex.Lock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user