Skip to content

Commit

Permalink
option to send server time in connect result
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed May 10, 2024
1 parent 8e2a8d5 commit 2b65b72
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions _examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/centrifugal/centrifuge => ../
require (
github.com/FZambia/tarantool v0.2.2
github.com/centrifugal/centrifuge v0.8.2
github.com/centrifugal/protocol v0.12.1
github.com/centrifugal/protocol v0.12.2-0.20240510082212-95d0d6be417a
github.com/cristalhq/jwt/v5 v5.4.0
github.com/dchest/uniuri v1.2.0
github.com/gin-contrib/sessions v0.0.3
Expand All @@ -30,7 +30,6 @@ require (
)

require (
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
github.com/FZambia/eagle v0.1.0 // indirect
github.com/Yiling-J/theine-go v0.3.2 // indirect
Expand All @@ -42,6 +41,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gammazero/deque v0.2.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
Expand Down
12 changes: 2 additions & 10 deletions _examples/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
cloud.google.com/go/compute v1.24.0 h1:phWcR2eWzRJaL/kOiJwfFsPs4BaKq1j6vnpZrc1YlVg=
cloud.google.com/go/compute v1.24.0/go.mod h1:kw1/T+h/+tK2LJK0wiPPx1intgdAM3j/g3hFDlscY40=
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/FZambia/eagle v0.1.0 h1:9gyX6x+xjoIfglgyPTcYm7dvY7FJ93us1QY5De4CyXA=
Expand All @@ -18,8 +14,8 @@ github.com/bradleypeabody/gorilla-sessions-memcache v0.0.0-20181103040241-659414
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/centrifugal/protocol v0.12.1 h1:hGbIl9Y0UbVsESgLcsqgZ7duwEnrZebFUYdu5Opwzgo=
github.com/centrifugal/protocol v0.12.1/go.mod h1:5Z0SuNdXEt83Fkoi34BCyY23p1P8+zQakQS6/BfJHak=
github.com/centrifugal/protocol v0.12.2-0.20240510082212-95d0d6be417a h1:22cS8zoI28nYvewmoXnBvgzM5imqwzHcSfKltJ2f+ws=
github.com/centrifugal/protocol v0.12.2-0.20240510082212-95d0d6be417a/go.mod h1:lM54PGU/u5WupYSb755Zv6tZ2ju1SqNKCp6A4s0DeG4=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
Expand Down Expand Up @@ -200,8 +196,6 @@ golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg=
golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8=
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
Expand All @@ -219,8 +213,6 @@ golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8=
google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4=
Expand Down
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,9 @@ func (c *Client) connectCmd(req *protocol.ConnectRequest, cmd *protocol.Command,
if c.transport.Emulation() {
res.Node = c.node.ID()
}
if c.node.config.ClientConnectIncludeServerTime {
res.Time = time.Now().UnixMilli()
}

// Client successfully connected.
c.mu.Lock()
Expand Down
2 changes: 2 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func TestClientConnectNoCredentialsNoToken(t *testing.T) {
func TestClientConnectContextCredentials(t *testing.T) {
node := defaultTestNode()
defer func() { _ = node.Shutdown(context.Background()) }()
node.config.ClientConnectIncludeServerTime = true

transport := newTestTransport(func() {})
ctx := context.Background()
Expand All @@ -284,6 +285,7 @@ func TestClientConnectContextCredentials(t *testing.T) {
result := extractConnectReply(rwWrapper.replies)
require.Equal(t, false, result.Expires)
require.Equal(t, uint32(0), result.Ttl)
require.NotZero(t, result.TimeMs)

Check failure on line 288 in client_test.go

View workflow job for this annotation

GitHub Actions / Lint

result.TimeMs undefined (type *protocol.ConnectResult has no field or method TimeMs) (typecheck)

Check failure on line 288 in client_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.21 Redis 5

result.TimeMs undefined (type *protocol.ConnectResult has no field or method TimeMs)

Check failure on line 288 in client_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.21 Redis 6

result.TimeMs undefined (type *protocol.ConnectResult has no field or method TimeMs)

Check failure on line 288 in client_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.21 Redis 7

result.TimeMs undefined (type *protocol.ConnectResult has no field or method TimeMs)

Check failure on line 288 in client_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.22 Redis 5

result.TimeMs undefined (type *protocol.ConnectResult has no field or method TimeMs)

Check failure on line 288 in client_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.22 Redis 6

result.TimeMs undefined (type *protocol.ConnectResult has no field or method TimeMs)

Check failure on line 288 in client_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.22 Redis 7

result.TimeMs undefined (type *protocol.ConnectResult has no field or method TimeMs)
require.True(t, client.authenticated)
require.Equal(t, "42", client.UserID())
}
Expand Down
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Config struct {
// aggregation. It's not reasonable to have it less than one second.
// Zero value means 60 * time.Second.
NodeInfoMetricsAggregateInterval time.Duration
// ClientConnectIncludeServerTime tells Centrifuge to append time_ms to Connect result of client protocol.
// By default, server time is not included.
ClientConnectIncludeServerTime bool
// ClientPresenceUpdateInterval sets an interval how often connected
// clients update presence information.
// Zero value means 25 * time.Second.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/FZambia/eagle v0.1.0
github.com/Yiling-J/theine-go v0.3.2
github.com/centrifugal/protocol v0.12.1
github.com/centrifugal/protocol v0.12.2-0.20240510082212-95d0d6be417a
github.com/google/uuid v1.6.0
github.com/prometheus/client_golang v1.19.0
github.com/redis/rueidis v1.0.36
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/Yiling-J/theine-go v0.3.2 h1:XcSdMPV9DwBD9gqqSxbBfVJnP8CCiqNSqp3C6Ypm
github.com/Yiling-J/theine-go v0.3.2/go.mod h1:ygLXqrWPZT/a+PzK5hQ0+a6gu0lpAY5IudTcgnPleqI=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/centrifugal/protocol v0.12.1 h1:hGbIl9Y0UbVsESgLcsqgZ7duwEnrZebFUYdu5Opwzgo=
github.com/centrifugal/protocol v0.12.1/go.mod h1:5Z0SuNdXEt83Fkoi34BCyY23p1P8+zQakQS6/BfJHak=
github.com/centrifugal/protocol v0.12.2-0.20240510082212-95d0d6be417a h1:22cS8zoI28nYvewmoXnBvgzM5imqwzHcSfKltJ2f+ws=
github.com/centrifugal/protocol v0.12.2-0.20240510082212-95d0d6be417a/go.mod h1:lM54PGU/u5WupYSb755Zv6tZ2ju1SqNKCp6A4s0DeG4=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down

0 comments on commit 2b65b72

Please sign in to comment.