Commit 2f188238 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Add support for optional client IP address passthrough to runtime Satori client.

parent 3980ebc7
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Added JavaScript runtime function to clear all localcache data.
- Added support for per-key TTL in Lua runtime localcache.
- Added support for per-key TTL in JavaScript runtime localcache.
- Add support for optional client IP address passthrough to runtime Satori client.

### Changed
- Remove unused config 'matchmaker.batch_pool_size'.
+1 −1
Changes for go.mod: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ require (
	github.com/gorilla/mux v1.8.0
	github.com/gorilla/websocket v1.5.0
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
	github.com/heroiclabs/nakama-common v0.0.0-20231110231506-a6d791dbc20f
	github.com/heroiclabs/nakama-common v0.0.0-20231111182915-5206c3ece9b0
	github.com/jackc/pgconn v1.14.0
	github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
	github.com/jackc/pgtype v1.14.0
+2 −2
Changes for go.sum: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -302,8 +302,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/heroiclabs/nakama-common v0.0.0-20231110231506-a6d791dbc20f h1:sthlTetnKYxex7iS4BgW5S49s5zqPtBzg2XN1NPfvq0=
github.com/heroiclabs/nakama-common v0.0.0-20231110231506-a6d791dbc20f/go.mod h1:Os8XeXGvHAap/p6M/8fQ3gle4eEXDGRQmoRNcPQTjXs=
github.com/heroiclabs/nakama-common v0.0.0-20231111182915-5206c3ece9b0 h1:iGR26K0+AIhf5pJuRsDeDxTt6BeVJfyv6ys94xgiEnY=
github.com/heroiclabs/nakama-common v0.0.0-20231111182915-5206c3ece9b0/go.mod h1:Os8XeXGvHAap/p6M/8fQ3gle4eEXDGRQmoRNcPQTjXs=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
+10 −1
Changes for internal/satori/satori.go: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"errors"
	"fmt"
	"io"
	"net"
	"net/http"
	"net/url"
	"strings"
@@ -141,8 +142,9 @@ type authenticateBody struct {
// @summary Create a new identity.
// @param ctx(type=context.Context) The context object represents information about the server and requester.
// @param id(type=string) The identifier of the identity.
// @param ipAddress(type=string, optional=true) An optional client IP address to pass on to Satori for geo-IP lookup.
// @return error(error) An optional error value if an error occurred.
func (s *SatoriClient) Authenticate(ctx context.Context, id string) error {
func (s *SatoriClient) Authenticate(ctx context.Context, id string, ipAddress ...string) error {
	if s.invalidConfig {
		return runtime.ErrSatoriConfigurationInvalid
	}
@@ -162,6 +164,13 @@ func (s *SatoriClient) Authenticate(ctx context.Context, id string) error {
	}
	req.Header.Set("Content-Type", "application/json")
	req.SetBasicAuth(s.apiKey, "")
	if len(ipAddress) > 0 && ipAddress[0] != "" {
		if ipAddr := net.ParseIP(ipAddress[0]); ipAddr != nil {
			req.Header.Set("X-Forwarded-For", ipAddr.String())
		}
	} else if ipAddr, ok := ctx.Value(runtime.RUNTIME_CTX_CLIENT_IP).(string); ok {
		req.Header.Set("X-Forwarded-For", ipAddr)
	}

	res, err := s.httpc.Do(req)
	if err != nil {
+1 −1
Changes for server/api_test.go: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ var (
		DiscardUnknown: false,
	}
	metrics       = NewLocalMetrics(logger, logger, nil, cfg)
	storageIdx, _ = NewLocalStorageIndex(logger, nil, &StorageConfig{DisableIndexOnly: false})
	storageIdx, _ = NewLocalStorageIndex(logger, nil, &StorageConfig{DisableIndexOnly: false}, metrics)
	_             = CheckConfig(logger, cfg)
)

Loading