Skip to content

Commit 2909a4f

Browse files
committed
Remove buildinfo from connection handshake
GODRIVER-441 Change-Id: I56f01cc62e5eff13bcaa1cda9a1c922ea2632f6d
1 parent a78cd34 commit 2909a4f

File tree

12 files changed

+38
-68
lines changed

12 files changed

+38
-68
lines changed

core/auth/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func RegisterAuthenticatorFactory(name string, factory AuthenticatorFactory) {
9191
// }
9292

9393
// Handshaker creates a connection handshaker for the given authenticator. The
94-
// handshaker will handle calling isMaster and buildInfo.
94+
// handshaker will handle calling isMaster.
9595
func Handshaker(appName string, h connection.Handshaker, authenticator Authenticator) connection.Handshaker {
9696
return connection.HandshakerFunc(func(ctx context.Context, addr address.Address, rw wiremessage.ReadWriter) (description.Server, error) {
9797
desc, err := (&command.Handshake{Client: command.ClientDoc(appName)}).Handshake(ctx, addr, rw)

core/auth/default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type DefaultAuthenticator struct {
2929
func (a *DefaultAuthenticator) Auth(ctx context.Context, desc description.Server, rw wiremessage.ReadWriter) error {
3030
var actual Authenticator
3131
var err error
32-
if err = description.ScramSHA1Supported(desc.Version); err != nil {
32+
if err = description.ScramSHA1Supported(desc.WireVersion); err != nil {
3333
actual, err = newMongoDBCRAuthenticator(a.Cred)
3434
} else {
3535
actual, err = newScramSHA1Authenticator(a.Cred)

core/auth/x509.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (a *MongoDBX509Authenticator) Auth(ctx context.Context, desc description.Se
3434
bson.EC.String("mechanism", MongoDBX509),
3535
)
3636

37-
if !desc.Version.AtLeast(3, 4) {
37+
if desc.WireVersion.Max < 5 {
3838
authRequestDoc.Append(bson.EC.String("user", a.User))
3939
}
4040

core/command/handshake.go

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,26 @@ import (
2525
type Handshake struct {
2626
Client *bson.Document
2727

28-
ismstr result.IsMaster
29-
bldinfo result.BuildInfo
30-
err error
28+
ismstr result.IsMaster
29+
err error
3130
}
3231

33-
// Encode will encode the handshake commands into two wire messages. The wire
34-
// messages are ordered with the isMaster command first and the buildInfo command
35-
// second.
36-
func (h *Handshake) Encode() ([2]wiremessage.WireMessage, error) {
37-
var wms [2]wiremessage.WireMessage
32+
// Encode will encode the handshake commands into a wire message containing isMaster
33+
func (h *Handshake) Encode() (wiremessage.WireMessage, error) {
34+
var wm wiremessage.WireMessage
3835
ismstr, err := (&IsMaster{Client: h.Client}).Encode()
3936
if err != nil {
40-
return wms, err
37+
return wm, err
4138
}
42-
buildinfo, err := (&BuildInfo{}).Encode()
43-
if err != nil {
44-
return wms, err
45-
}
46-
wms[0], wms[1] = ismstr, buildinfo
47-
return wms, nil
39+
wm = ismstr
40+
return wm, nil
4841
}
4942

50-
// Decode will decode the wire messages. The order of the wire messages are
51-
// expected to be an isMaster response first and a buildInfo response second.
43+
// Decode will decode the wire messages.
5244
// Errors during decoding are deferred until either the Result or Err methods
5345
// are called.
54-
func (h *Handshake) Decode(wms [2]wiremessage.WireMessage) *Handshake {
55-
h.ismstr, h.err = (&IsMaster{}).Decode(wms[0]).Result()
56-
if h.err != nil {
57-
return h
58-
}
59-
h.bldinfo, h.err = (&BuildInfo{}).Decode(wms[1]).Result()
46+
func (h *Handshake) Decode(wm wiremessage.WireMessage) *Handshake {
47+
h.ismstr, h.err = (&IsMaster{}).Decode(wm).Result()
6048
if h.err != nil {
6149
return h
6250
}
@@ -68,40 +56,31 @@ func (h *Handshake) Result(addr address.Address) (description.Server, error) {
6856
if h.err != nil {
6957
return description.Server{}, h.err
7058
}
71-
return description.NewServer(addr, h.ismstr, h.bldinfo), nil
59+
return description.NewServer(addr, h.ismstr), nil
7260
}
7361

7462
// Err returns the error set on this Handshake.
7563
func (h *Handshake) Err() error { return h.err }
7664

7765
// Handshake implements the connection.Handshaker interface. It is identical
7866
// to the RoundTrip methods on other types in this package. It will execute
79-
// the isMaster and buildInfo commands, using pipelining to enable a single
80-
// roundtrip.
67+
// the isMaster command.
8168
func (h *Handshake) Handshake(ctx context.Context, addr address.Address, rw wiremessage.ReadWriter) (description.Server, error) {
82-
wms, err := h.Encode()
69+
wm, err := h.Encode()
8370
if err != nil {
8471
return description.Server{}, err
8572
}
8673

87-
err = rw.WriteWireMessage(ctx, wms[0])
88-
if err != nil {
89-
return description.Server{}, err
90-
}
91-
err = rw.WriteWireMessage(ctx, wms[1])
74+
err = rw.WriteWireMessage(ctx, wm)
9275
if err != nil {
9376
return description.Server{}, err
9477
}
9578

96-
wms[0], err = rw.ReadWireMessage(ctx)
97-
if err != nil {
98-
return description.Server{}, err
99-
}
100-
wms[1], err = rw.ReadWireMessage(ctx)
79+
wm, err = rw.ReadWireMessage(ctx)
10180
if err != nil {
10281
return description.Server{}, err
10382
}
104-
return h.Decode(wms).Result(addr)
83+
return h.Decode(wm).Result(addr)
10584
}
10685

10786
// ClientDoc creates a client information document for use in an isMaster

core/description/feature.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
// MaxStalenessSupported returns an error if the given server version
1414
// does not support max staleness.
15-
func MaxStalenessSupported(serverVersion Version, wireVersion *VersionRange) error {
16-
if !serverVersion.AtLeast(3, 4, 0) || (wireVersion != nil && wireVersion.Max < 5) {
15+
func MaxStalenessSupported(wireVersion *VersionRange) error {
16+
if wireVersion != nil && wireVersion.Max < 5 {
1717
return fmt.Errorf("max staleness is only supported for servers 3.4 or newer")
1818
}
1919

@@ -22,8 +22,8 @@ func MaxStalenessSupported(serverVersion Version, wireVersion *VersionRange) err
2222

2323
// ScramSHA1Supported returns an error if the given server version
2424
// does not support scram-sha-1.
25-
func ScramSHA1Supported(version Version) error {
26-
if !version.AtLeast(3, 0, 0) {
25+
func ScramSHA1Supported(wireVersion *VersionRange) error {
26+
if wireVersion != nil && wireVersion.Max < 3 {
2727
return fmt.Errorf("SCRAM-SHA-1 is only supported for servers 3.0 or newer")
2828
}
2929

core/description/feature_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestMaxStaleness(t *testing.T) {
3535
t.Run(test.version.String(), func(t *testing.T) {
3636
t.Parallel()
3737

38-
err := MaxStalenessSupported(test.version, test.wire)
38+
err := MaxStalenessSupported(test.wire)
3939
if test.expected {
4040
require.NoError(t, err)
4141
} else {

core/description/selector_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ var readPrefTestPrimary = Server{
178178
LastUpdateTime: time.Date(2017, 2, 11, 14, 0, 2, 0, time.UTC),
179179
Kind: RSPrimary,
180180
Tags: tag.Set{tag.Tag{Name: "a", Value: "1"}},
181-
Version: Version{Parts: []uint8{3, 4, 0}},
181+
WireVersion: &VersionRange{Min: 0, Max: 5},
182182
}
183183
var readPrefTestSecondary1 = Server{
184184
Addr: address.Address("localhost:27018"),
@@ -187,7 +187,7 @@ var readPrefTestSecondary1 = Server{
187187
LastUpdateTime: time.Date(2017, 2, 11, 14, 0, 2, 0, time.UTC),
188188
Kind: RSSecondary,
189189
Tags: tag.Set{tag.Tag{Name: "a", Value: "1"}},
190-
Version: Version{Parts: []uint8{3, 4, 0}},
190+
WireVersion: &VersionRange{Min: 0, Max: 5},
191191
}
192192
var readPrefTestSecondary2 = Server{
193193
Addr: address.Address("localhost:27018"),
@@ -196,7 +196,7 @@ var readPrefTestSecondary2 = Server{
196196
LastUpdateTime: time.Date(2017, 2, 11, 14, 0, 2, 0, time.UTC),
197197
Kind: RSSecondary,
198198
Tags: tag.Set{tag.Tag{Name: "a", Value: "2"}},
199-
Version: Version{Parts: []uint8{3, 4, 0}},
199+
WireVersion: &VersionRange{Min: 0, Max: 5},
200200
}
201201
var readPrefTestTopology = Topology{
202202
Kind: ReplicaSetWithPrimary,
@@ -215,7 +215,7 @@ func TestSelector_Sharded(t *testing.T) {
215215
LastWriteTime: time.Date(2017, 2, 11, 14, 0, 0, 0, time.UTC),
216216
LastUpdateTime: time.Date(2017, 2, 11, 14, 0, 2, 0, time.UTC),
217217
Kind: Mongos,
218-
Version: Version{Parts: []uint8{3, 4, 0}},
218+
WireVersion: &VersionRange{Min: 0, Max: 5},
219219
}
220220
c := Topology{
221221
Kind: Sharded,
@@ -241,7 +241,7 @@ func TestSelector_Single(t *testing.T) {
241241
LastWriteTime: time.Date(2017, 2, 11, 14, 0, 0, 0, time.UTC),
242242
LastUpdateTime: time.Date(2017, 2, 11, 14, 0, 2, 0, time.UTC),
243243
Kind: Mongos,
244-
Version: Version{Parts: []uint8{3, 4, 0}},
244+
WireVersion: &VersionRange{Min: 0, Max: 5},
245245
}
246246
c := Topology{
247247
Kind: Single,
@@ -674,7 +674,7 @@ func TestSelector_Max_staleness_is_less_than_90_seconds(t *testing.T) {
674674
LastWriteTime: time.Date(2017, 2, 11, 14, 0, 0, 0, time.UTC),
675675
LastUpdateTime: time.Date(2017, 2, 11, 14, 0, 2, 0, time.UTC),
676676
Kind: RSPrimary,
677-
Version: Version{Parts: []uint8{3, 4, 0}},
677+
WireVersion: &VersionRange{Min: 0, Max: 5},
678678
}
679679
c := Topology{
680680
Kind: ReplicaSetWithPrimary,
@@ -700,7 +700,7 @@ func TestSelector_Max_staleness_is_too_low(t *testing.T) {
700700
LastWriteTime: time.Date(2017, 2, 11, 14, 0, 0, 0, time.UTC),
701701
LastUpdateTime: time.Date(2017, 2, 11, 14, 0, 2, 0, time.UTC),
702702
Kind: RSPrimary,
703-
Version: Version{Parts: []uint8{3, 4, 0}},
703+
WireVersion: &VersionRange{Min: 0, Max: 5},
704704
}
705705
c := Topology{
706706
Kind: ReplicaSetWithPrimary,

core/description/server.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type Server struct {
3434
AverageRTTSet bool
3535
CanonicalAddr address.Address
3636
ElectionID objectid.ObjectID
37-
GitVersion string
3837
HeartbeatInterval time.Duration
3938
LastError error
4039
LastUpdateTime time.Time
@@ -49,11 +48,10 @@ type Server struct {
4948
Tags tag.Set
5049
Kind ServerKind
5150
WireVersion *VersionRange
52-
Version Version
5351
}
5452

5553
// NewServer creates a new server description from the given parameters.
56-
func NewServer(addr address.Address, isMaster result.IsMaster, buildInfo result.BuildInfo) Server {
54+
func NewServer(addr address.Address, isMaster result.IsMaster) Server {
5755
i := Server{
5856
Addr: addr,
5957

@@ -69,12 +67,6 @@ func NewServer(addr address.Address, isMaster result.IsMaster, buildInfo result.
6967
Tags: tag.NewTagSetFromMap(isMaster.Tags),
7068
}
7169

72-
if !buildInfo.IsZero() {
73-
i.GitVersion = buildInfo.GitVersion
74-
i.Version.Desc = buildInfo.Version
75-
i.Version.Parts = buildInfo.VersionArray
76-
}
77-
7870
if i.CanonicalAddr == "" {
7971
i.CanonicalAddr = addr
8072
}

core/description/server_selector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func ReadPrefSelector(rp *readpref.ReadPref) ServerSelector {
120120
if _, set := rp.MaxStaleness(); set {
121121
for _, s := range candidates {
122122
if s.Kind != Unknown {
123-
if err := MaxStalenessSupported(s.Version, s.WireVersion); err != nil {
123+
if err := MaxStalenessSupported(s.WireVersion); err != nil {
124124
return nil, err
125125
}
126126
}

core/description/shared_spec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ func selectServers(t *testing.T, test *testCase) error {
189189
}
190190

191191
// Max staleness can't be sent to servers older than 3.4.
192-
if test.ReadPreference.MaxStaleness != nil {
193-
server.Version = Version{Desc: "3.4.0", Parts: []uint8{3, 4, 0}}
192+
if test.ReadPreference.MaxStaleness != nil && server.WireVersion == nil {
193+
server.WireVersion = &VersionRange{Max: 5}
194194
}
195195

196196
servers = append(servers, server)

0 commit comments

Comments
 (0)