Skip to content

Commit

Permalink
Moved generateId into an external module
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokaiser committed Sep 11, 2012
1 parent 781d519 commit 587cb14
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
19 changes: 2 additions & 17 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var qs = require('querystring')
, parse = require('url').parse
, readFileSync = require('fs').readFileSync
, crypto = require('crypto')
, base64id = require('base64id')
, transports = require('./transports')
, EventEmitter = require('events').EventEmitter
, Socket = require('./socket')
Expand Down Expand Up @@ -110,22 +111,6 @@ Server.prototype.prepare = function(req){
}
};

/**
* Generates an id.
*
* @api private
*/

Server.prototype.id = function(){
var rand = new Buffer(15);
this.sequenceNumber = (this.sequenceNumber + 1) | 0;
rand.writeInt32BE(this.sequenceNumber, 11);
crypto.randomBytes(12).copy(rand);
var id = rand.toString('base64').replace(/\//g, '_').replace(/\+/g, '-');
if (this.clients[id]) return this.id();
return id;
};

/**
* Closes all clients.
*
Expand Down Expand Up @@ -178,7 +163,7 @@ Server.prototype.handleRequest = function(req, res){
*/

Server.prototype.handshake = function(transport, req){
var id = this.id();
var id = base64id.generateId();

debug('handshaking client "%d"', id);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"debug": "0.6.0"
, "engine.io-client": "0.2.2"
, "ws": "~0.4.21"
, "base64id": "0.1.0"
}
, "devDependencies": {
"mocha": "*"
Expand Down

0 comments on commit 587cb14

Please sign in to comment.