Skip to content

Commit

Permalink
Signaling: Ensure that responder id does not conflict with own address
Browse files Browse the repository at this point in the history
Refs #24
  • Loading branch information
threema-danilo committed Jul 11, 2016
1 parent 964c233 commit b538163
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions saltyrtc/signaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ export class Signaling {
* Do the server handshake.
*
* The `buffer` argument contains the `server-hello` packet.
*
* If an exception is thrown in this method, it will be converted to a
* protocol error.
*/
private async serverHandshake(buffer: ArrayBuffer): Promise<void> {

Expand Down Expand Up @@ -421,6 +424,11 @@ export class Signaling {
if (this.role == 'initiator') {
this.responders = new Map<number, Responder>();
for (let id of message.responders) {
// Make sure that responder id is different from own id
if (id === this.address) {
console.error(this.logTag, 'Responder id matches own address.');
throw 'address-conflict';
}
this.responders.set(id, new Responder(id));
this.client.emit({type: 'new-responder', data: id});
}
Expand Down Expand Up @@ -721,6 +729,10 @@ export class Signaling {
// A new responder wants to connect. Store id.
const id = (message as saltyrtc.messages.NewResponder).id;
if (!this.responders.has(id)) {
if (id === this.address) {
console.error(this.logTag, 'Responder id matches own address.');
abort();
}
this.responders.set(id, new Responder(id));
this.client.emit({type: 'new-responder', data: id});
} else {
Expand Down

0 comments on commit b538163

Please sign in to comment.