3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 07:29:31 +01:00

add PROXY protocol support

This commit is contained in:
Jeremy Latt 2014-02-10 18:40:06 -08:00
parent a8141a0e1c
commit 4379cb8e1c
2 changed files with 39 additions and 1 deletions

View File

@ -28,6 +28,7 @@ var (
"PING": NewPingCommand, "PING": NewPingCommand,
"PONG": NewPongCommand, "PONG": NewPongCommand,
"PRIVMSG": NewPrivMsgCommand, "PRIVMSG": NewPrivMsgCommand,
"PROXY": NewProxyCommand,
"QUIT": NewQuitCommand, "QUIT": NewQuitCommand,
"TOPIC": NewTopicCommand, "TOPIC": NewTopicCommand,
"USER": NewUserMsgCommand, "USER": NewUserMsgCommand,
@ -581,3 +582,30 @@ func NewCapCommand(args []string) (editableCommand, error) {
args: args, args: args,
}, nil }, 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
}

View File

@ -60,7 +60,8 @@ func (server *Server) receiveCommands(commands <-chan Command) {
} else { } else {
switch command.(type) { switch command.(type) {
case *PassCommand, *CapCommand: case *PassCommand, *CapCommand, *ProxyCommand:
// no-op
default: default:
client.Reply(ErrPasswdMismatch(server)) client.Reply(ErrPasswdMismatch(server))
client.Destroy() client.Destroy()
@ -401,3 +402,12 @@ func (msg *OperCommand) HandleServer(server *Server) {
func (msg *CapCommand) HandleServer(server *Server) { func (msg *CapCommand) HandleServer(server *Server) {
// TODO // 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)
}