diff options
author | 2013-11-02 15:10:29 -0400 | |
---|---|---|
committer | 2013-11-02 15:10:29 -0400 | |
commit | 6c84eaf5a01046a0fa175d75e7027f686e00a6ee (patch) | |
tree | f17a9dbbe95514ec5b2950b954b2279fb1b4d349 /Assistant/Threads/PairListener.hs | |
parent | 15b4cd87363a872d0d165fa1c02c48a8cb63cccf (diff) |
Improve local pairing behavior when two computers both try to start the pairing process separately.
I was able to reproduce something very like this bug by starting
pairing separately on both computers under poor network conditions (ie,
weak wifi on my front porch). Neither computer showed an alert for the
PairReq messages it was seeing (intermittently) from the other.
So, I've made a new PairReq message that has not been seen before
always make the alert pop up, even if the assistant thinks it is
in the middle of its own pairing process (or even another pairing
process with a different box on the LAN).
(This shouldn't cause a rogue PairAck to disrupt a pairing process part
way through.)
Diffstat (limited to 'Assistant/Threads/PairListener.hs')
-rw-r--r-- | Assistant/Threads/PairListener.hs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Assistant/Threads/PairListener.hs b/Assistant/Threads/PairListener.hs index 0d3be4660..cd95ab5a4 100644 --- a/Assistant/Threads/PairListener.hs +++ b/Assistant/Threads/PairListener.hs @@ -43,20 +43,32 @@ pairListenerThread urlrenderer = namedThread "PairListener" $ do (pip, verified) <- verificationCheck m =<< (pairingInProgress <$> getDaemonStatus) let wrongstage = maybe False (\p -> pairMsgStage m <= inProgressPairStage p) pip - case (wrongstage, sane, pairMsgStage m) of - -- ignore our own messages, and - -- out of order messages - (_, False, _) -> go reqs cache sock - (True, _, _) -> go reqs cache sock - (_, _, PairReq) -> if m `elem` reqs + let fromus = maybe False (\p -> remoteSshPubKey (pairMsgData m) == remoteSshPubKey (inProgressPairData p)) pip + case (wrongstage, fromus, sane, pairMsgStage m) of + (_, True, _, _) -> do + debug ["ignoring message that looped back"] + go reqs cache sock + (_, _, False, _) -> go reqs cache sock + -- PairReq starts a pairing process, so a + -- new one is always heeded, even if + -- some other pairing is in process. + (_, _, _, PairReq) -> if m `elem` reqs then go reqs (invalidateCache m cache) sock else do pairReqReceived verified urlrenderer m go (m:take 10 reqs) (invalidateCache m cache) sock - (_, _, PairAck) -> do + (True, _, _, _) -> do + debug + ["ignoring out of order message" + , show (pairMsgStage m) + , "expected" + , show (succ . inProgressPairStage <$> pip) + ] + go reqs cache sock + (_, _, _, PairAck) -> do cache' <- pairAckReceived verified pip m cache go reqs cache' sock - (_, _, PairDone) -> do + (_,_ , _, PairDone) -> do pairDoneReceived verified pip m go reqs cache sock |