mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 23:16:13 -04:00
Minor server performance improvements
This commit is contained in:
parent
dc050dc41e
commit
bd3103a2fe
1 changed files with 20 additions and 16 deletions
|
@ -31,17 +31,32 @@ exports.create = function(server) {
|
||||||
type: ua.device.type
|
type: ua.device.type
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hash(text) {
|
||||||
|
// A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm.
|
||||||
|
var h = 5381,
|
||||||
|
index = text.length;
|
||||||
|
while (index) {
|
||||||
|
h = (h * 33) ^ text.charCodeAt(--index);
|
||||||
|
}
|
||||||
|
return h >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIP(socket) {
|
||||||
|
return socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress;
|
||||||
|
}
|
||||||
// Wait for new user connections
|
// Wait for new user connections
|
||||||
bs.on('connection', function(client) {
|
bs.on('connection', function(client) {
|
||||||
console.log('connection received!', client._socket.upgradeReq.connection.remoteAddress);
|
//console.log('connection received!', client._socket.upgradeReq.connection.remoteAddress);
|
||||||
|
|
||||||
client.uuidRaw = guid();
|
client.uuidRaw = guid();
|
||||||
|
//ip is hashed to prevent injections by spoofing the 'x-forwarded-for' header
|
||||||
|
client.hashedIp = hash(getIP(client._socket));
|
||||||
|
|
||||||
client.deviceName = getDeviceName(client._socket.upgradeReq);
|
client.deviceName = getDeviceName(client._socket.upgradeReq);
|
||||||
|
|
||||||
// Incoming stream from browsers
|
// Incoming stream from browsers
|
||||||
client.on('stream', function(stream, meta) {
|
client.on('stream', function(stream, meta) {
|
||||||
console.log('stream received!', meta);
|
|
||||||
if (meta && meta.serverMsg === 'rtc-support') {
|
if (meta && meta.serverMsg === 'rtc-support') {
|
||||||
client.uuid = (meta.rtc ? 'rtc_' : '') + client.uuidRaw;
|
client.uuid = (meta.rtc ? 'rtc_' : '') + client.uuidRaw;
|
||||||
client.send({
|
client.send({
|
||||||
|
@ -75,26 +90,15 @@ exports.create = function(server) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIP(socket) {
|
|
||||||
return socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hash(text) {
|
|
||||||
// A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm.
|
|
||||||
var h = 5381,
|
|
||||||
index = text.length;
|
|
||||||
while (index) {
|
|
||||||
h = (h * 33) ^ text.charCodeAt(--index);
|
|
||||||
}
|
|
||||||
return h >>> 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function notifyBuddiesX() {
|
function notifyBuddiesX() {
|
||||||
var locations = {};
|
var locations = {};
|
||||||
//group all clients by location (by public ip address)
|
//group all clients by location (by public ip address)
|
||||||
forEachClient(function(client) {
|
forEachClient(function(client) {
|
||||||
//ip is hashed to prevent injections by spoofing the 'x-forwarded-for' header
|
var ip = client.hashedIp;
|
||||||
var ip = hash(getIP(client._socket));
|
|
||||||
locations[ip] = locations[ip] || [];
|
locations[ip] = locations[ip] || [];
|
||||||
locations[ip].push({
|
locations[ip].push({
|
||||||
socket: client,
|
socket: client,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue