Skip to content

Commit

Permalink
Revert "MongoDB 3.6: implement the new wire protocol (#61)"
Browse files Browse the repository at this point in the history
This reverts commit 90c056c.
  • Loading branch information
domodwyer committed Jan 7, 2018
1 parent a104bfb commit 02f13d7
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 1,058 deletions.
24 changes: 14 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ language: go

go_import_path: github.com/globalsign/mgo

go:
- 1.8.x
- 1.9.x

env:
global:
- BUCKET=https://s3.eu-west-2.amazonaws.com/globalsign-mgo
- FASTDL=https://fastdl.mongodb.org/linux
matrix:
- MONGODB=x86_64-ubuntu1404-3.0.15
- MONGODB=x86_64-ubuntu1404-3.2.17
- MONGODB=x86_64-ubuntu1404-3.4.10
- MONGODB=x86_64-ubuntu1404-3.6.0
- GO=1.7 MONGODB=x86_64-2.6.11
- GO=1.8.x MONGODB=x86_64-2.6.11
- GO=1.7 MONGODB=x86_64-3.0.9
- GO=1.8.x MONGODB=x86_64-3.0.9
- GO=1.7 MONGODB=x86_64-3.2.3-nojournal
- GO=1.8.x MONGODB=x86_64-3.2.3-nojournal
- GO=1.7 MONGODB=x86_64-3.2.12
- GO=1.8.x MONGODB=x86_64-3.2.12
- GO=1.7 MONGODB=x86_64-3.2.16
- GO=1.8.x MONGODB=x86_64-3.2.16
- GO=1.7 MONGODB=x86_64-3.4.8
- GO=1.8.x MONGODB=x86_64-3.4.8

install:
- eval "$(gimme $GO)"

- wget $FASTDL/mongodb-linux-$MONGODB.tgz
- wget $BUCKET/mongodb-linux-$MONGODB.tgz
- tar xzvf mongodb-linux-$MONGODB.tgz
- export PATH=$PWD/mongodb-linux-$MONGODB/bin:$PATH

Expand Down
57 changes: 30 additions & 27 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ func (socket *mongoSocket) Login(cred Credential) error {
return nil
}
}
if socket.dropLogout(cred) {
debugf("Socket %p to %s: login: db=%q user=%q (cached)", socket, socket.addr, cred.Source, cred.Username)
socket.creds = append(socket.creds, cred)
socket.Unlock()
return nil
}
socket.Unlock()

debugf("Socket %p to %s: login: db=%q user=%q", socket, socket.addr, cred.Source, cred.Username)
Expand Down Expand Up @@ -406,50 +412,36 @@ func (socket *mongoSocket) Logout(db string) {
cred, found := socket.dropAuth(db)
if found {
debugf("Socket %p to %s: logout: db=%q (flagged)", socket, socket.addr, db)
socket.Unlock()
err := socket.flushLogout(cred)
if err != nil {
debugf("fail to logout for cred %v; error: %v", cred, err)
}
} else {
socket.Unlock()
socket.logout = append(socket.logout, cred)
}
socket.Unlock()
}

func (socket *mongoSocket) LogoutAll() {
socket.Lock()
if l := len(socket.creds); l > 0 {
credCopy := make([]Credential, l)
copy(credCopy, socket.creds)
socket.creds = socket.creds[0:0]
socket.Unlock()
debugf("Socket %p to %s: logout all (flagged %d)", socket, socket.addr, l)
err := socket.flushLogout(credCopy...)
if err != nil {
debugf("fail to logout for cred %v, error: %v", credCopy, err)
}
} else {
socket.Unlock()
socket.logout = append(socket.logout, socket.creds...)
socket.creds = socket.creds[0:0]
}
socket.Unlock()
}

func (socket *mongoSocket) flushLogout(cred ...Credential) error {
if l := len(cred); l > 0 {
func (socket *mongoSocket) flushLogout() (ops []interface{}) {
socket.Lock()
if l := len(socket.logout); l > 0 {
debugf("Socket %p to %s: logout all (flushing %d)", socket, socket.addr, l)
ops := make([]interface{}, l)
for i := 0; i != l; i++ {
op := queryOp{}
op.query = &logoutCmd{1}
op.collection = cred[i].Source + ".$cmd"
op.collection = socket.logout[i].Source + ".$cmd"
op.limit = -1
ops[i] = &op
}
err := socket.Query(ops...)
if err != nil {
return fmt.Errorf("fail to logout: %v", err)
ops = append(ops, &op)
}
socket.logout = socket.logout[0:0]
}
return nil
socket.Unlock()
return
}

func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
Expand All @@ -462,3 +454,14 @@ func (socket *mongoSocket) dropAuth(db string) (cred Credential, found bool) {
}
return cred, false
}

func (socket *mongoSocket) dropLogout(cred Credential) (found bool) {
for i, sockCred := range socket.logout {
if sockCred == cred {
copy(socket.logout[i:], socket.logout[i+1:])
socket.logout = socket.logout[:len(socket.logout)-1]
return true
}
}
return false
}
Loading

0 comments on commit 02f13d7

Please sign in to comment.