From a6b7d7654408d08915b7d65bdf29bb5bf611f99b Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Fri, 21 Jul 2017 23:55:11 +0200 Subject: [PATCH 1/4] bugfix: unable to deliver message. fixes receiving message before authentication --- src/Connector.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Connector.js b/src/Connector.js index c04e53f7..b062f528 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -141,7 +141,9 @@ export default function extendConnector (Y/* :any */) { this.log('User joined: %s', user) this.connections[user] = { isSynced: false, - role: role + role: role, + waitingMessages: [], + auth: null } let defer = {} defer.promise = new Promise(function (resolve) { defer.resolve = resolve }) @@ -267,11 +269,17 @@ export default function extendConnector (Y/* :any */) { }) return Promise.reject(new Error('Incompatible protocol version')) } - if (message.auth != null && this.connections[sender] != null) { + if (message.type === 'sync step 1' && this.connections[sender] != null && this.connections[sender].auth == null) { // authenticate using auth in message var auth = this.checkAuth(message.auth, this.y) this.connections[sender].auth = auth auth.then(auth => { + // in case operations were received before sender was received + // we apply the messages after authentication + this.connections[sender].waitingMessages.forEach(msg => { + this.receiveMessage(sender, msg) + }) + this.connections[sender].waitingMessages = null for (var f of this.userEventListeners) { f({ action: 'userAuthenticated', @@ -280,9 +288,6 @@ export default function extendConnector (Y/* :any */) { }) } }) - } else if (this.connections[sender] != null && this.connections[sender].auth == null) { - // authenticate without otherwise - this.connections[sender].auth = this.checkAuth(null, this.y) } if (this.connections[sender] != null && this.connections[sender].auth != null) { return this.connections[sender].auth.then((auth) => { @@ -382,8 +387,13 @@ export default function extendConnector (Y/* :any */) { this.y.db.apply(message.ops) } }) + } else if (this.connections[sender] != null) { + // wait for authentication + let senderConn = this.connection[sender] + senderConn.waitingMessages = senderConn.waitingMessages || [] + senderConn.waitingMessages.push(message) } else { - return Promise.reject(new Error('Unable to deliver message')) + return Promise.reject(new Error('Unknown user - Unable to deliver message')) } } _setSyncedWith (user) { From 2c18b9ffadc3d4b86794713aaee9a2a4b4c6fffd Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Fri, 21 Jul 2017 23:56:13 +0200 Subject: [PATCH 2/4] 13.0.0-6 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 538dac7c..3fa974c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.0.0-5", + "version": "13.0.0-6", "lockfileVersion": 1, "dependencies": { "acorn": { diff --git a/package.json b/package.json index 8cb4cfe0..4508facf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.0.0-5", + "version": "13.0.0-6", "description": "A framework for real-time p2p shared editing on any data", "main": "./y.node.js", "browser": "./y.js", From 67b47fd868fbb9f323d0e9a52072c5630385ec43 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Sat, 22 Jul 2017 01:15:13 +0200 Subject: [PATCH 3/4] bugfix - sync step 2 also authenticates) --- src/Connector.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Connector.js b/src/Connector.js index b062f528..03be952e 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -269,17 +269,20 @@ export default function extendConnector (Y/* :any */) { }) return Promise.reject(new Error('Incompatible protocol version')) } - if (message.type === 'sync step 1' && this.connections[sender] != null && this.connections[sender].auth == null) { + if ((message.type === 'sync step 1' || message.type === 'sync step 2') && this.connections[sender] != null && this.connections[sender].auth == null) { // authenticate using auth in message var auth = this.checkAuth(message.auth, this.y) this.connections[sender].auth = auth auth.then(auth => { // in case operations were received before sender was received // we apply the messages after authentication - this.connections[sender].waitingMessages.forEach(msg => { - this.receiveMessage(sender, msg) + this.connections[sender].syncStep2.promise.then(() => { + // we do it after sync step 1 + this.connections[sender].waitingMessages.forEach(msg => { + this.receiveMessage(sender, msg) + }) + this.connections[sender].waitingMessages = null }) - this.connections[sender].waitingMessages = null for (var f of this.userEventListeners) { f({ action: 'userAuthenticated', @@ -389,7 +392,7 @@ export default function extendConnector (Y/* :any */) { }) } else if (this.connections[sender] != null) { // wait for authentication - let senderConn = this.connection[sender] + let senderConn = this.connections[sender] senderConn.waitingMessages = senderConn.waitingMessages || [] senderConn.waitingMessages.push(message) } else { From bb45abbb701250f77cbee8f6310b6639740c2815 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Sat, 22 Jul 2017 01:16:50 +0200 Subject: [PATCH 4/4] 13.0.0-7 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3fa974c8..22f3af77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.0.0-6", + "version": "13.0.0-7", "lockfileVersion": 1, "dependencies": { "acorn": { diff --git a/package.json b/package.json index 4508facf..0c5296ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yjs", - "version": "13.0.0-6", + "version": "13.0.0-7", "description": "A framework for real-time p2p shared editing on any data", "main": "./y.node.js", "browser": "./y.js",