mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-17 03:19:08 +00:00
Hysteria inbound: Use transport's authentication when there are no clients (#5942)
This commit is contained in:
@@ -82,24 +82,13 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||||||
inbound := session.InboundFromContext(ctx)
|
inbound := session.InboundFromContext(ctx)
|
||||||
inbound.Name = "hysteria"
|
inbound.Name = "hysteria"
|
||||||
inbound.CanSpliceCopy = 3
|
inbound.CanSpliceCopy = 3
|
||||||
|
inbound.User = &protocol.MemoryUser{}
|
||||||
|
|
||||||
iConn := stat.TryUnwrapStatsConn(conn)
|
iConn := stat.TryUnwrapStatsConn(conn)
|
||||||
|
|
||||||
var useremail string
|
|
||||||
var userlevel uint32
|
|
||||||
type User interface{ User() *protocol.MemoryUser }
|
type User interface{ User() *protocol.MemoryUser }
|
||||||
if v, ok := iConn.(User); ok {
|
if v, ok := iConn.(User); ok && v.User() != nil {
|
||||||
inbound.User = v.User()
|
inbound.User = v.User()
|
||||||
if inbound.User != nil {
|
|
||||||
useremail = inbound.User.Email
|
|
||||||
userlevel = inbound.User.Level
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// get a dummy user
|
|
||||||
inbound.User = &protocol.MemoryUser{
|
|
||||||
Email: "",
|
|
||||||
Level: 0,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := iConn.(*hysteria.InterUdpConn); ok {
|
if _, ok := iConn.(*hysteria.InterUdpConn); ok {
|
||||||
@@ -154,7 +143,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||||||
Writer: writer,
|
Writer: writer,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
sessionPolicy := s.policyManager.ForLevel(userlevel)
|
sessionPolicy := s.policyManager.ForLevel(inbound.User.Level)
|
||||||
|
|
||||||
common.Must(conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)))
|
common.Must(conn.SetReadDeadline(time.Now().Add(sessionPolicy.Timeouts.Handshake)))
|
||||||
addr, err := ReadTCPRequest(conn)
|
addr, err := ReadTCPRequest(conn)
|
||||||
@@ -178,7 +167,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||||||
To: dest,
|
To: dest,
|
||||||
Status: log.AccessAccepted,
|
Status: log.AccessAccepted,
|
||||||
Reason: "",
|
Reason: "",
|
||||||
Email: useremail,
|
Email: inbound.User.Email,
|
||||||
})
|
})
|
||||||
errors.LogInfo(ctx, "tunnelling request to ", dest)
|
errors.LogInfo(ctx, "tunnelling request to ", dest)
|
||||||
|
|
||||||
|
|||||||
@@ -450,6 +450,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
requireDatagram := hyCtx.RequireDatagramFromContext(ctx)
|
requireDatagram := hyCtx.RequireDatagramFromContext(ctx)
|
||||||
|
dest.Network = net.Network_UDP
|
||||||
config := streamSettings.ProtocolSettings.(*Config)
|
config := streamSettings.ProtocolSettings.(*Config)
|
||||||
|
|
||||||
initmanager.Do(func() {
|
initmanager.Do(func() {
|
||||||
@@ -464,8 +465,8 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
},
|
},
|
||||||
}).Start()
|
}).Start()
|
||||||
})
|
})
|
||||||
|
|
||||||
manager.mutex.Lock()
|
manager.mutex.Lock()
|
||||||
dest.Network = net.Network_UDP
|
|
||||||
c, ok := manager.m[dialerConf{Destination: dest, MemoryStreamConfig: streamSettings}]
|
c, ok := manager.m[dialerConf{Destination: dest, MemoryStreamConfig: streamSettings}]
|
||||||
if !ok {
|
if !ok {
|
||||||
c = &client{
|
c = &client{
|
||||||
|
|||||||
@@ -175,10 +175,10 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
var user *protocol.MemoryUser
|
var user *protocol.MemoryUser
|
||||||
var ok bool
|
var ok bool
|
||||||
if h.validator != nil {
|
if h.validator != nil && h.validator.GetCount() > 0 {
|
||||||
user = h.validator.Get(auth)
|
user = h.validator.Get(auth)
|
||||||
} else if auth == h.config.Auth {
|
} else if h.config.Auth != "" {
|
||||||
ok = true
|
ok = auth == h.config.Auth
|
||||||
}
|
}
|
||||||
|
|
||||||
if user != nil || ok {
|
if user != nil || ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user