diff options
-rw-r--r-- | Presence/SendMessage.hs | 6 | ||||
-rw-r--r-- | Presence/SocketLike.hs | 2 | ||||
-rw-r--r-- | Presence/XMPP.hs | 29 |
3 files changed, 24 insertions, 13 deletions
diff --git a/Presence/SendMessage.hs b/Presence/SendMessage.hs index 71b6a3bd..e7b3db33 100644 --- a/Presence/SendMessage.hs +++ b/Presence/SendMessage.hs | |||
@@ -53,6 +53,7 @@ import ServerC (packetSink) | |||
53 | import ControlMaybe | 53 | import ControlMaybe |
54 | import Data.Conduit (Sink,Source) | 54 | import Data.Conduit (Sink,Source) |
55 | import qualified Data.ByteString as S (ByteString) | 55 | import qualified Data.ByteString as S (ByteString) |
56 | import qualified Data.ByteString.Lazy.Char8 as L | ||
56 | import XMLToByteStrings | 57 | import XMLToByteStrings |
57 | import Logging | 58 | import Logging |
58 | import ByteStringOperators | 59 | import ByteStringOperators |
@@ -125,7 +126,8 @@ sendMessage (OutgoingConnections cons interpretCommands) msg peer0 = do | |||
125 | ThreadFinished -> died | 126 | ThreadFinished -> died |
126 | ) | 127 | ) |
127 | found | 128 | found |
128 | -- L.putStrLn $ "sendMessage ->"<++>showPeer peer<++>": "<++>bshow msg | 129 | if is_new then L.putStrLn $ "sendMessage NEW ->"<++>showPeer peer<++>": "<++>bshow msg |
130 | else L.putStrLn $ "sendMessage ->"<++>showPeer peer<++>": "<++>bshow msg | ||
129 | atomically $ writeTChan (fst entry) msg | 131 | atomically $ writeTChan (fst entry) msg |
130 | when is_new . atomically $ | 132 | when is_new . atomically $ |
131 | readTVar cons >>= writeTVar cons . Map.insert peer entry | 133 | readTVar cons >>= writeTVar cons . Map.insert peer entry |
@@ -163,7 +165,7 @@ connect_to_server chan peer toPeer = (>> return ()) . runMaybeT $ do | |||
163 | MaybeT $ handleOutgoingToPeer toPeer (restrictSocket sock) cache chan snk | 165 | MaybeT $ handleOutgoingToPeer toPeer (restrictSocket sock) cache chan snk |
164 | 166 | ||
165 | liftIO $ cacheCmd retry cached | 167 | liftIO $ cacheCmd retry cached |
166 | -- liftIO $ putStrLn $ "retrying " ++ show retry | 168 | liftIO $ putStrLn $ "retrying " ++ show retry |
167 | sendmsgs | 169 | sendmsgs |
168 | 170 | ||
169 | connect' :: SockAddr -> Int -> IO (Maybe Socket) | 171 | connect' :: SockAddr -> Int -> IO (Maybe Socket) |
diff --git a/Presence/SocketLike.hs b/Presence/SocketLike.hs index c2f14460..af0249ae 100644 --- a/Presence/SocketLike.hs +++ b/Presence/SocketLike.hs | |||
@@ -67,7 +67,7 @@ instance SocketLike RestrictedSocket where | |||
67 | sIsListening (Restricted mb sock) = NS.sIsListening sock | 67 | sIsListening (Restricted mb sock) = NS.sIsListening sock |
68 | sIsReadable (Restricted mb sock) = NS.sIsReadable sock | 68 | sIsReadable (Restricted mb sock) = NS.sIsReadable sock |
69 | sIsWritable (Restricted mb sock) = NS.sIsWritable sock | 69 | sIsWritable (Restricted mb sock) = NS.sIsWritable sock |
70 | sClose (Restricted mb sock) = maybe (NS.sClose sock) hClose mb | 70 | sClose (Restricted mb sock) = maybe (NS.sClose sock) (\h -> hClose h >> NS.sClose sock) mb |
71 | 71 | ||
72 | restrictSocket :: NS.Socket -> RestrictedSocket | 72 | restrictSocket :: NS.Socket -> RestrictedSocket |
73 | restrictSocket socket = Restricted Nothing socket | 73 | restrictSocket socket = Restricted Nothing socket |
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs index 853b015a..c7525159 100644 --- a/Presence/XMPP.hs +++ b/Presence/XMPP.hs | |||
@@ -933,7 +933,7 @@ fromPeer sock session = doNestingXML $ do | |||
933 | xs <- gatherElement stanza Seq.empty | 933 | xs <- gatherElement stanza Seq.empty |
934 | prettyPrint "P: " (toList xs) | 934 | prettyPrint "P: " (toList xs) |
935 | case () of | 935 | case () of |
936 | _ | stanza `isIQOf` iqTypeGet -> handlePeerIQGet session stanza | 936 | _ | stanza `isServerIQOf` iqTypeGet -> handlePeerIQGet session stanza |
937 | _ | stanza `isPresenceOf` presenceTypeOnline | 937 | _ | stanza `isPresenceOf` presenceTypeOnline |
938 | -> handlePeerPresence session stanza True | 938 | -> handlePeerPresence session stanza True |
939 | _ | stanza `isPresenceOf` presenceTypeOffline | 939 | _ | stanza `isPresenceOf` presenceTypeOffline |
@@ -985,7 +985,7 @@ instance CommandCache CachedMessages where | |||
985 | updateCache (Rejection from to) cache = | 985 | updateCache (Rejection from to) cache = |
986 | cache { approvals= mmInsert (False,from) to $ approvals cache } | 986 | cache { approvals= mmInsert (False,from) to $ approvals cache } |
987 | updateCache (OutBoundMessage msg) cache = cache -- TODO: cache chat? | 987 | updateCache (OutBoundMessage msg) cache = cache -- TODO: cache chat? |
988 | updateCache (Pong _ _ _) cache = cache -- pings are not cached | 988 | updateCache (Pong _ _ _) cache = trace "(DISCARDING Pong)" cache -- pings are not cached |
989 | updateCache (Unsupported _ _ _ _) cache = cache -- error messages are not cached | 989 | updateCache (Unsupported _ _ _ _) cache = cache -- error messages are not cached |
990 | updateCache (ActivityBump sock) cache = cache | 990 | updateCache (ActivityBump sock) cache = cache |
991 | 991 | ||
@@ -1078,7 +1078,8 @@ toPeer sock cache chan fail = do | |||
1078 | sendOrFail (xmlifyMessageForPeer sock msg) | 1078 | sendOrFail (xmlifyMessageForPeer sock msg) |
1079 | (OutBoundMessage msg) | 1079 | (OutBoundMessage msg) |
1080 | 1080 | ||
1081 | sendPong from to mid = | 1081 | sendPong from to mid = do |
1082 | liftIO . debugL $ "SEND PONG" | ||
1082 | sendOrFail (xmlifyPong sock from to mid) | 1083 | sendOrFail (xmlifyPong sock from to mid) |
1083 | (Pong from to mid) | 1084 | (Pong from to mid) |
1084 | where | 1085 | where |
@@ -1146,9 +1147,11 @@ toPeer sock cache chan fail = do | |||
1146 | 1147 | ||
1147 | sockref <- liftIO $ atomically newEmptyTMVar | 1148 | sockref <- liftIO $ atomically newEmptyTMVar |
1148 | let bump fromsock = do | 1149 | let bump fromsock = do |
1149 | remote <- getPeerName sock | 1150 | remote <- liftIO $ catchIO (fmap Just $ getPeerName sock) |
1150 | debugL $ "PING BUMP" <++> showPeer (RemotePeer remote) | 1151 | (\_ -> return Nothing) |
1152 | debugL $ "PING BUMP" <++?> fmap (showPeer . RemotePeer) remote | ||
1151 | timer <- atomically $ do | 1153 | timer <- atomically $ do |
1154 | tryTakeTMVar sockref | ||
1152 | putTMVar sockref fromsock | 1155 | putTMVar sockref fromsock |
1153 | (timer,v) <- readTVar pingref | 1156 | (timer,v) <- readTVar pingref |
1154 | writeTVar pingref (timer,0) | 1157 | writeTVar pingref (timer,0) |
@@ -1160,23 +1163,27 @@ toPeer sock cache chan fail = do | |||
1160 | return v | 1163 | return v |
1161 | 1164 | ||
1162 | fix $ \loop -> do | 1165 | fix $ \loop -> do |
1166 | liftIO . debugStr $ "LOOP waiting..." | ||
1163 | event <- lift . atomically $ orElse (Left `fmap` readTChan chan) | 1167 | event <- lift . atomically $ orElse (Left `fmap` readTChan chan) |
1164 | (Right `fmap` waitPing) | 1168 | (Right `fmap` waitPing) |
1169 | liftIO . debugStr $ "LOOP event = " ++ show event | ||
1165 | let sendPing n = do | 1170 | let sendPing n = do |
1166 | ping_timer <- liftIO $ newDelay five_sec | ||
1167 | liftIO . atomically $ writeTVar pingref (ping_timer,1) | ||
1168 | case n of | 1171 | case n of |
1169 | 0 -> do | 1172 | 0 -> do |
1170 | ping <- liftIO makePing | 1173 | ping <- liftIO makePing |
1171 | yield ping | 1174 | yield ping |
1175 | liftIO . debugL $ "SEND PING" | ||
1172 | prettyPrint ">P: " ping | 1176 | prettyPrint ">P: " ping |
1177 | ping_timer <- liftIO $ newDelay five_sec | ||
1178 | liftIO . atomically $ writeTVar pingref (ping_timer,1) | ||
1173 | loop | 1179 | loop |
1174 | _ -> do | 1180 | 1 -> do |
1175 | remote <- liftIO $ getPeerName sock | 1181 | remote <- liftIO $ getPeerName sock |
1176 | liftIO . debugL $ "PING TIMEOUT: " <++> showPeer (RemotePeer remote) | 1182 | liftIO . debugL $ "PING TIMEOUT: " <++> showPeer (RemotePeer remote) |
1177 | fromsock <- liftIO $ atomically $ readTMVar sockref | 1183 | fromsock <- liftIO $ atomically $ readTMVar sockref |
1178 | liftIO $ sClose fromsock | 1184 | liftIO $ sClose fromsock |
1179 | return () -- PING TIMEOUT (loop quits) | 1185 | return () -- PING TIMEOUT (loop quits) |
1186 | x -> error ("What? "++show x) | ||
1180 | where makePing = do | 1187 | where makePing = do |
1181 | addr <- getSocketName sock | 1188 | addr <- getSocketName sock |
1182 | remote <- getPeerName sock | 1189 | remote <- getPeerName sock |
@@ -1188,7 +1195,7 @@ toPeer sock cache chan fail = do | |||
1188 | $ (case mid of | 1195 | $ (case mid of |
1189 | Just c -> (("id",[c]):) | 1196 | Just c -> (("id",[c]):) |
1190 | _ -> id ) | 1197 | _ -> id ) |
1191 | [("type",[ContentText "error"]) | 1198 | [ ("type",[ContentText "get"]) |
1192 | , attr "to" to | 1199 | , attr "to" to |
1193 | , attr "from" from | 1200 | , attr "from" from |
1194 | ] | 1201 | ] |
@@ -1211,7 +1218,9 @@ toPeer sock cache chan fail = do | |||
1211 | liftIO . debugL $ "sending rejection "<++>bshow (from,to) | 1218 | liftIO . debugL $ "sending rejection "<++>bshow (from,to) |
1212 | sendApproval False from to | 1219 | sendApproval False from to |
1213 | OutBoundMessage msg -> sendMessage msg | 1220 | OutBoundMessage msg -> sendMessage msg |
1214 | Pong from to mid -> sendPong from to mid | 1221 | Pong from to mid -> do |
1222 | liftIO . debugL $ "sending pong "<++>bshow (from,to) | ||
1223 | sendPong from to mid | ||
1215 | Unsupported from to mid tag -> sendUnsupported from to mid tag | 1224 | Unsupported from to mid tag -> sendUnsupported from to mid tag |
1216 | Disconnect -> return () | 1225 | Disconnect -> return () |
1217 | ActivityBump fromsock -> liftIO (bump fromsock) | 1226 | ActivityBump fromsock -> liftIO (bump fromsock) |