summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-08 15:30:04 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-08 15:30:04 -0400
commit5401b9f2497c7719dfe65d9d576f645bec282785 (patch)
treed7d1d469c066a05b890082e5a04756400844dbf6 /Assistant
parent61ee1e16602900b279b96eb6e53192b1181ad581 (diff)
filter out our own pairing requests
Due to being multicast, requests sent by one thread are received by the listener in another thread.
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/Pairing.hs5
-rw-r--r--Assistant/Threads/PairListener.hs11
2 files changed, 12 insertions, 4 deletions
diff --git a/Assistant/Pairing.hs b/Assistant/Pairing.hs
index eced43793..a157e28f8 100644
--- a/Assistant/Pairing.hs
+++ b/Assistant/Pairing.hs
@@ -47,7 +47,10 @@ type UserName = String
{- A pairing that is in progress has a secret, and a thread that is
- broadcasting pairing requests. -}
-data PairingInProgress = PairingInProgress Secret ThreadId
+data PairingInProgress = PairingInProgress
+ { inProgressSecret :: Secret
+ , inProgressThreadId :: ThreadId
+ }
data SomeAddr = IPv4Addr HostAddress | IPv6Addr HostAddress6
deriving (Ord, Eq, Read, Show)
diff --git a/Assistant/Threads/PairListener.hs b/Assistant/Threads/PairListener.hs
index bb9ab6d0f..58d8fd969 100644
--- a/Assistant/Threads/PairListener.hs
+++ b/Assistant/Threads/PairListener.hs
@@ -39,13 +39,18 @@ pairListenerThread st dstatus = thread $ withSocketsDo $ do
chunksz = 1024
dispatch Nothing = noop
- dispatch (Just (PairReqM (PairReq r))) = void $ do
- let pairdata = verifiableVal r
+ dispatch (Just (PairReqM (PairReq v))) = unlessM (mypair v) $ do
+ let pairdata = verifiableVal v
let repo = remoteUserName pairdata ++ "@" ++
fromMaybe (showAddr $ remoteAddress pairdata)
(remoteHostName pairdata)
let msg = repo ++ " is sending a pair request."
{- Pair request alerts from the same host combine,
- so repeated requests do not add additional alerts. -}
- addAlert dstatus $ pairRequestAlert repo msg
+ void $ addAlert dstatus $ pairRequestAlert repo msg
dispatch (Just (PairAckM _)) = noop -- TODO
+
+ {- Filter out our own pair requests, by checking if we
+ - can verify using the secrets of any of them. -}
+ mypair v = any (verified v . inProgressSecret) . pairingInProgress
+ <$> getDaemonStatus dstatus