Refactor self-connection handling and improve message processing
- Removed self-connection detection logic from the Listener and Server, simplifying the message handling process. - Updated the HandleMessage and handle-websocket functions to eliminate checks for self-connections, enhancing clarity and maintainability. - Adjusted AUTH challenge logic to focus solely on blacklisted IPs, streamlining connection management.
This commit is contained in:
@@ -49,33 +49,6 @@ type Server struct {
|
||||
policyManager *policy.P
|
||||
}
|
||||
|
||||
// isSelfConnection checks if the connection is coming from the relay itself
|
||||
func (s *Server) isSelfConnection(remote string) bool {
|
||||
// Check for localhost connections
|
||||
if strings.HasPrefix(remote, "127.0.0.1:") || strings.HasPrefix(remote, "::1:") || strings.HasPrefix(remote, "[::1]:") {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check for connections from the same IP as the server
|
||||
// This handles cases where the relay connects to itself via its public IP
|
||||
if s.Config.Listen != "" {
|
||||
// Extract IP from listen address (e.g., "0.0.0.0" -> "0.0.0.0")
|
||||
listenIP := s.Config.Listen
|
||||
if listenIP == "0.0.0.0" || listenIP == "" {
|
||||
// If listening on all interfaces, check if remote IP matches any local interface
|
||||
// For now, we'll be conservative and only check localhost
|
||||
return false
|
||||
}
|
||||
// Check if remote IP matches the listen IP
|
||||
remoteIP := strings.Split(remote, ":")[0]
|
||||
if remoteIP == listenIP {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// isIPBlacklisted checks if an IP address is blacklisted using the managed ACL system
|
||||
func (s *Server) isIPBlacklisted(remote string) bool {
|
||||
// Extract IP from remote address (e.g., "192.168.1.1:12345" -> "192.168.1.1")
|
||||
|
||||
Reference in New Issue
Block a user