Completely ephemeral Peer ID
cherry picked from commit 56ab2357a66797e56db1dfb489eda32150f8d3a5 on willstott101/snapdrop
This commit is contained in:
parent
b242a5fd01
commit
4c40c3d011
1 changed files with 6 additions and 15 deletions
21
index.js
21
index.js
|
@ -85,7 +85,6 @@ class SnapdropServer {
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
this._wss = new WebSocket.Server({ server });
|
this._wss = new WebSocket.Server({ server });
|
||||||
this._wss.on('connection', (socket, request) => this._onConnection(new Peer(socket, request)));
|
this._wss.on('connection', (socket, request) => this._onConnection(new Peer(socket, request)));
|
||||||
this._wss.on('headers', (headers, response) => this._onHeaders(headers, response));
|
|
||||||
|
|
||||||
this._rooms = {};
|
this._rooms = {};
|
||||||
|
|
||||||
|
@ -108,12 +107,6 @@ class SnapdropServer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onHeaders(headers, request) {
|
|
||||||
if (request.headers.cookie && request.headers.cookie.indexOf('peerid=') > -1) return;
|
|
||||||
request.peerId = Peer.uuid();
|
|
||||||
headers.push('Set-Cookie: peerid=' + request.peerId + "; SameSite=Strict; Secure");
|
|
||||||
}
|
|
||||||
|
|
||||||
_onMessage(sender, message) {
|
_onMessage(sender, message) {
|
||||||
// Try to parse message
|
// Try to parse message
|
||||||
try {
|
try {
|
||||||
|
@ -233,16 +226,18 @@ class Peer {
|
||||||
// set socket
|
// set socket
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
|
|
||||||
|
|
||||||
// set remote ip
|
// set remote ip
|
||||||
this._setIP(request);
|
this._setIP(request);
|
||||||
|
|
||||||
// set peer id
|
// set peer id
|
||||||
this._setPeerId(request)
|
this._setPeerId()
|
||||||
|
|
||||||
// is WebRTC supported ?
|
// is WebRTC supported ?
|
||||||
this.rtcSupported = request.url.indexOf('webrtc') > -1;
|
this.rtcSupported = request.url.indexOf('webrtc') > -1;
|
||||||
|
|
||||||
// set name
|
// set name
|
||||||
this._setName(request);
|
this._setName(request);
|
||||||
|
|
||||||
// for keepalive
|
// for keepalive
|
||||||
this.timerId = 0;
|
this.timerId = 0;
|
||||||
this.lastBeat = Date.now();
|
this.lastBeat = Date.now();
|
||||||
|
@ -302,12 +297,8 @@ class Peer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_setPeerId(request) {
|
_setPeerId() {
|
||||||
if (request.peerId) {
|
this.id = Peer.uuid();
|
||||||
this.id = request.peerId;
|
|
||||||
} else {
|
|
||||||
this.id = request.headers.cookie.replace('peerid=', '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
|
|
Loading…
Reference in a new issue