Quellcode durchsuchen

Log ICE candidates (censor IP and port)

Lennart Grahl vor 8 Jahren
Ursprung
Commit
16b7a9f43c
2 geänderte Dateien mit 26 neuen und 0 gelöschten Zeilen
  1. 1 0
      package.json
  2. 25 0
      src/services/peerconnection.ts

+ 1 - 0
package.json

@@ -59,6 +59,7 @@
     "node-sass": "~3.10.0",
     "saltyrtc-client": "~0.9.1",
     "saltyrtc-task-webrtc": "~0.9.1",
+    "sdp": "~1.3.0",
     "tsify": "~2.0.1",
     "tweetnacl": "~0.14.4",
     "typescript": "~2.1.0",

+ 25 - 0
src/services/peerconnection.ts

@@ -16,6 +16,7 @@
  */
 
 /// <reference types="saltyrtc-task-webrtc" />
+import * as SDPUtils from 'sdp';
 
 /**
  * Wrapper around the WebRTC PeerConnection.
@@ -95,6 +96,8 @@ export class PeerConnectionHelper {
         this.$log.debug(this.logTag, 'Setting up ICE candidate handling');
         this.pc.onicecandidate = (e: RTCPeerConnectionIceEvent) => {
             if (e.candidate) {
+                this.$log.debug(this.logTag, 'Gathered local ICE candidate:',
+                    PeerConnectionHelper.censorCandidate(e.candidate.candidate));
                 this.webrtcTask.sendCandidate({
                     candidate: e.candidate.candidate,
                     sdpMid: e.candidate.sdpMid,
@@ -135,6 +138,12 @@ export class PeerConnectionHelper {
         };
         this.webrtcTask.on('candidates', (e: saltyrtc.tasks.webrtc.CandidatesEvent) => {
             for (let candidateInit of e.data) {
+                if (candidateInit) {
+                    this.$log.debug(this.logTag, 'Adding remote ICE candidate:',
+                        PeerConnectionHelper.censorCandidate(candidateInit.candidate));
+                } else {
+                    this.$log.debug(this.logTag, 'No more remote ICE candidates');
+                }
                 this.pc.addIceCandidate(candidateInit);
             }
         });
@@ -233,4 +242,20 @@ export class PeerConnectionHelper {
             }
         });
     }
+
+    /**
+     * Censor an ICE candidate's address and port.
+     *
+     * Return the censored ICE candidate.
+     */
+    private static censorCandidate(candidateInit: string): string {
+        let candidate = SDPUtils.parseCandidate(candidateInit);
+        if (candidate.type !== 'relay') {
+            candidate.ip = '***';
+            candidate.port = 1;
+        }
+        candidate.relatedAddress = '***';
+        candidate.relatedPort = 2;
+        return SDPUtils.writeCandidate(candidate);
+    }
 }