-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathclient_info.go
87 lines (69 loc) · 2.34 KB
/
client_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package chconn
import (
"os/user"
"github.com/vahid-sohrabloo/chconn/v2/internal/helper"
)
// ClientInfo Information about client for query.
// Some fields are passed explicitly from client and some are calculated automatically.
// Contains info about initial query source, for tracing distributed queries
// where one query initiates many other queries.
type ClientInfo struct {
InitialUser string
InitialQueryID string
OSUser string
ClientHostname string
ClientName string
ClientVersionMajor uint64
ClientVersionMinor uint64
ClientVersionPatch uint64
ClientRevision uint64
DistributedDepth uint64
QuotaKey string
}
// Write Only values that are not calculated automatically or passed separately are serialized.
// Revisions are passed to use format that server will understand or client was used.
func (c *ClientInfo) write(ch *conn) {
// InitialQuery
ch.writer.Uint8(1)
ch.writer.String(c.InitialUser)
ch.writer.String(c.InitialQueryID)
ch.writer.String("[::ffff:127.0.0.1]:0")
if ch.serverInfo.Revision >= helper.DbmsMinProtocolVersionWithInitialQueryStartTime {
ch.writer.Uint64(0)
}
// iface type
ch.writer.Uint8(1) // tcp
ch.writer.String(c.OSUser)
ch.writer.String(c.ClientHostname)
ch.writer.String(c.ClientName)
ch.writer.Uvarint(c.ClientVersionMajor)
ch.writer.Uvarint(c.ClientVersionMinor)
ch.writer.Uvarint(c.ClientRevision)
if ch.serverInfo.Revision >= helper.DbmsMinRevisionWithQuotaKeyInClientInfo {
ch.writer.String(c.QuotaKey)
}
if ch.serverInfo.Revision >= helper.DbmsMinProtocolVersionWithDistributedDepth {
ch.writer.Uvarint(c.DistributedDepth)
}
if ch.serverInfo.Revision >= helper.DbmsMinRevisionWithVersionPatch {
ch.writer.Uvarint(c.ClientVersionPatch)
}
if ch.serverInfo.Revision >= helper.DbmsMinRevisionWithOpenTelemetry {
ch.writer.Uint8(0)
}
if ch.serverInfo.Revision >= helper.DbmsMinProtocolVersionWithParallelReplicas {
ch.writer.Uvarint(0) // collaborate_with_initiator
ch.writer.Uvarint(0) // count_participating_replicas
ch.writer.Uvarint(0) // number_of_current_replica
}
}
func (c *ClientInfo) fillOSUserHostNameAndVersionInfo() {
u, err := user.Current()
if err == nil {
c.OSUser = u.Username
}
c.ClientVersionMajor = dbmsVersionMajor
c.ClientVersionMinor = dbmsVersionMinor
c.ClientVersionPatch = dbmsVersionPatch
c.ClientRevision = dbmsVersionRevision
}