From 4c40c3d011c84363bec55051cef853b25cd580cb Mon Sep 17 00:00:00 2001 From: schlagmichdoch Date: Fri, 30 Dec 2022 17:49:14 +0100 Subject: [PATCH] Completely ephemeral Peer ID cherry picked from commit 56ab2357a66797e56db1dfb489eda32150f8d3a5 on willstott101/snapdrop --- index.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index f197c66..8ecc2e2 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,6 @@ class SnapdropServer { const WebSocket = require('ws'); this._wss = new WebSocket.Server({ server }); this._wss.on('connection', (socket, request) => this._onConnection(new Peer(socket, request))); - this._wss.on('headers', (headers, response) => this._onHeaders(headers, response)); 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) { // Try to parse message try { @@ -233,16 +226,18 @@ class Peer { // set socket this.socket = socket; - // set remote ip this._setIP(request); // set peer id - this._setPeerId(request) + this._setPeerId() + // is WebRTC supported ? this.rtcSupported = request.url.indexOf('webrtc') > -1; + // set name this._setName(request); + // for keepalive this.timerId = 0; this.lastBeat = Date.now(); @@ -302,12 +297,8 @@ class Peer { return false; } - _setPeerId(request) { - if (request.peerId) { - this.id = request.peerId; - } else { - this.id = request.headers.cookie.replace('peerid=', ''); - } + _setPeerId() { + this.id = Peer.uuid(); } toString() {