mirror of
				https://github.com/ergochat/ergo.git
				synced 2025-10-31 13:57:23 +01:00 
			
		
		
		
	add PROXY protocol support
This commit is contained in:
		
							parent
							
								
									a8141a0e1c
								
							
						
					
					
						commit
						4379cb8e1c
					
				| @ -28,6 +28,7 @@ var ( | ||||
| 		"PING":    NewPingCommand, | ||||
| 		"PONG":    NewPongCommand, | ||||
| 		"PRIVMSG": NewPrivMsgCommand, | ||||
| 		"PROXY":   NewProxyCommand, | ||||
| 		"QUIT":    NewQuitCommand, | ||||
| 		"TOPIC":   NewTopicCommand, | ||||
| 		"USER":    NewUserMsgCommand, | ||||
| @ -581,3 +582,30 @@ func NewCapCommand(args []string) (editableCommand, error) { | ||||
| 		args: args, | ||||
| 	}, nil | ||||
| } | ||||
| 
 | ||||
| // HAPROXY support | ||||
| type ProxyCommand struct { | ||||
| 	BaseCommand | ||||
| 	net        string | ||||
| 	sourceIP   string | ||||
| 	destIP     string | ||||
| 	sourcePort string | ||||
| 	destPort   string | ||||
| } | ||||
| 
 | ||||
| func (msg *ProxyCommand) String() string { | ||||
| 	return fmt.Sprintf("PROXY(sourceIP=%s, sourcePort=%s)", msg.sourceIP, msg.sourcePort) | ||||
| } | ||||
| 
 | ||||
| func NewProxyCommand(args []string) (editableCommand, error) { | ||||
| 	if len(args) < 5 { | ||||
| 		return nil, NotEnoughArgsError | ||||
| 	} | ||||
| 	return &ProxyCommand{ | ||||
| 		net:        args[0], | ||||
| 		sourceIP:   args[1], | ||||
| 		destIP:     args[2], | ||||
| 		sourcePort: args[3], | ||||
| 		destPort:   args[4], | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| @ -60,7 +60,8 @@ func (server *Server) receiveCommands(commands <-chan Command) { | ||||
| 
 | ||||
| 			} else { | ||||
| 				switch command.(type) { | ||||
| 				case *PassCommand, *CapCommand: | ||||
| 				case *PassCommand, *CapCommand, *ProxyCommand: | ||||
| 					// no-op | ||||
| 				default: | ||||
| 					client.Reply(ErrPasswdMismatch(server)) | ||||
| 					client.Destroy() | ||||
| @ -401,3 +402,12 @@ func (msg *OperCommand) HandleServer(server *Server) { | ||||
| func (msg *CapCommand) HandleServer(server *Server) { | ||||
| 	// TODO | ||||
| } | ||||
| 
 | ||||
| func (msg *ProxyCommand) HandleServer(server *Server) { | ||||
| 	client := msg.Client() | ||||
| 	addr, err := net.ResolveIPAddr("ip", msg.sourceIP) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	client.hostname = LookupHostname(addr) | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Jeremy Latt
						Jeremy Latt