summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Assistant/Threads/PushNotifier.hs29
-rw-r--r--doc/design/assistant/xmpp.mdwn8
2 files changed, 26 insertions, 11 deletions
diff --git a/Assistant/Threads/PushNotifier.hs b/Assistant/Threads/PushNotifier.hs
index 9f15d5419..46a1d3ebf 100644
--- a/Assistant/Threads/PushNotifier.hs
+++ b/Assistant/Threads/PushNotifier.hs
@@ -17,11 +17,13 @@ import Assistant.DaemonStatus
import Assistant.Pushes
import Assistant.Sync
import qualified Remote
+import Utility.ThreadScheduler
import Network.Protocol.XMPP
import Control.Concurrent
import qualified Data.Set as S
import qualified Git.Branch
+import Data.Time.Clock
thisThread :: ThreadName
thisThread = "PushNotifier"
@@ -31,14 +33,27 @@ pushNotifierThread st dstatus pushnotifier = NamedThread thisThread $ do
v <- runThreadState st $ getXMPPCreds
case v of
Nothing -> return () -- no creds? exit thread
- Just c -> void $ connectXMPP c $ \jid -> do
- fulljid <- bindJID jid
- liftIO $ debug thisThread ["XMPP connected", show fulljid]
- s <- getSession
- _ <- liftIO $ forkIO $ void $ runXMPP s $
- receivenotifications
- sendnotifications
+ Just c -> loop c =<< getCurrentTime
where
+ loop c starttime = do
+ void $ connectXMPP c $ \jid -> do
+ fulljid <- bindJID jid
+ liftIO $ debug thisThread ["XMPP connected", show fulljid]
+ s <- getSession
+ _ <- liftIO $ forkIO $ void $ runXMPP s $
+ receivenotifications
+ sendnotifications
+ now <- getCurrentTime
+ if diffUTCTime now starttime > 300
+ then do
+ debug thisThread ["XMPP connection lost; reconnecting"]
+ loop c now
+ else do
+ debug thisThread ["XMPP connection failed; will retry"]
+ threadDelaySeconds (Seconds 300)
+ loop c =<< getCurrentTime
+
+
sendnotifications = forever $ do
us <- liftIO $ waitPush pushnotifier
let payload = [extendedAway, encodePushNotification us]
diff --git a/doc/design/assistant/xmpp.mdwn b/doc/design/assistant/xmpp.mdwn
index c58d42ca9..9eaf078b7 100644
--- a/doc/design/assistant/xmpp.mdwn
+++ b/doc/design/assistant/xmpp.mdwn
@@ -4,20 +4,20 @@ who share a repository, that is stored in the [[cloud]].
### TODO
-* Track down segfault when the XMPP library is starting up a client connection.
-* test with big servers, eg google chat
* Prevent idle disconnection. Probably means sending or receiving pings,
but would prefer to avoid eg pinging every 60 seconds as some clients do.
+* Make the NetWatcher restart the XMPP connection when there's a new default
+ route. Currently, if moving networks, it needs to go through a TCP timeout.
* Make the git-annex clients invisible, so a user can use their regular
account without always seeming to be present when git-annex is logged in.
See <http://xmpp.org/extensions/xep-0126.html>
-* webapp configuration
+* (re)start PushNotifier when webapp is used to change XMPP config.
* After pulling from a remote, may need to scan for transfers, which
could involve other remotes (ie, S3). Since the remote client is not able to
talk to us directly, it won't be able to upload any new files to us.
Need a fast way to find new files, and get them transferring. The expensive
transfer scan may be needed to get fully in sync, but is too expensive to
- run every time this happens.
+ run every time this happens. Send transfer notifications using XMPP?
## design goals