Skip to content

Commit

Permalink
fix: receive proxy protocol (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
haveachin authored Mar 10, 2022
1 parent 84ca696 commit b43977f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cmd/infrared/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"flag"
"github.com/haveachin/infrared/api"
"log"
"os"
"strconv"

"github.com/haveachin/infrared/api"

"github.com/haveachin/infrared"
)

Expand Down Expand Up @@ -105,7 +106,7 @@ func main() {
}
}()

gateway := infrared.Gateway{}
gateway := infrared.Gateway{ReceiveProxyProtocol: receiveProxyProtocol}
go func() {
for {
cfg, ok := <-outCfgs
Expand Down
4 changes: 2 additions & 2 deletions gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ var (
)

type Gateway struct {
ReceiveProxyProtocol bool
listeners sync.Map
Proxies sync.Map
closed chan bool
wg sync.WaitGroup
receiveProxyProtocol bool
}

func (gateway *Gateway) ListenAndServe(proxies []*Proxy) error {
Expand Down Expand Up @@ -180,7 +180,7 @@ func (gateway *Gateway) listenAndServe(listener Listener, addr string) error {

func (gateway *Gateway) serve(conn Conn, addr string) error {
connRemoteAddr := conn.RemoteAddr()
if gateway.receiveProxyProtocol {
if gateway.ReceiveProxyProtocol {
header, err := proxyproto.Read(conn.Reader())
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func TestProxyProtocol(t *testing.T) {
go func(wg *sync.WaitGroup) {
config := createProxyProtocolConfig(tc.portEnd, tc.proxyproto)
gateway := Gateway{
receiveProxyProtocol: tc.receiveProxyproto,
ReceiveProxyProtocol: tc.receiveProxyproto,
}
proxies := configToProxies(config)
if err := gateway.ListenAndServe(proxies); err != nil {
Expand Down

0 comments on commit b43977f

Please sign in to comment.