From 6787377f59c4bb2a1bf6998b9c108dc2a50f3bb4 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Tue, 6 Jun 2017 17:49:10 +0200 Subject: [PATCH] device: handle split brain Handle a scenario when we thing we are not paired, but device sends us a packet that clearly indicates we have a channel open. In this case assume that we are paired and send a pair packet ourselves. Signed-off-by: Maciek Borzecki --- src/mconnect/device.vala | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mconnect/device.vala b/src/mconnect/device.vala index 037c8be..f9e04bf 100644 --- a/src/mconnect/device.vala +++ b/src/mconnect/device.vala @@ -274,10 +274,11 @@ class Device : Object { // we sent a pair request, but got another packet, // supposedly meaning we're alredy paired since the device // is sending us data - if (_pair_in_progress == true) { - _pair_in_progress = false; - // just to be clear, send paired signal - paired(true); + if (this.is_paired == false) { + warning("not paired and still got a packet, " + + "assuming device is paired", + Packet.PAIR); + handle_pair(true, ""); } // emit signal @@ -332,13 +333,19 @@ class Device : Object { // pair completed _pair_in_progress = false; } else { - debug("unsolicited pair change from device"); + debug("unsolicited pair change from device, pair status: %s", + pair.to_string()); if (pair == false) { // unpair from device this.is_paired = false; } else { - // pair request from device + // split brain, pair was not initiated by us, but we were called + // with information that we are paired, assume we are paired and + // send a pair packet, but not expecting a response this time + this.pair.begin(false); + + this.is_paired = true; } }