summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/Presence.hs28
-rw-r--r--Presence/XMPPServer.hs21
-rw-r--r--examples/dhtd.hs5
3 files changed, 29 insertions, 25 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index 244bbead..befe47e1 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -578,17 +578,13 @@ deliverMessage state fail msg =
578 mto <- fmap join $ mapM rewriteJIDForPeer (stanzaTo msg) 578 mto <- fmap join $ mapM rewriteJIDForPeer (stanzaTo msg)
579 fromMaybe fail {- reverse lookup failure -} $ mto <&> \(to',k) -> do 579 fromMaybe fail {- reverse lookup failure -} $ mto <&> \(to',k) -> do
580 chans <- atomically $ readTVar (pkeyToChan state) 580 chans <- atomically $ readTVar (pkeyToChan state)
581 fromMaybe fail $ (Map.lookup k chans) <&> \Conn { connChan = chan 581 fromMaybe fail $ (Map.lookup k chans) <&> \conn -> do
582 , auxData = ConnectionData (Left (Local laddr))
583 ctyp
584 } -> do
585 (n,r) <- forClient state senderk (return (Nothing,Nothing))
586 $ \c -> return (Just (clientUser c), Just (clientResource c))
587 -- original 'from' address is discarded. 582 -- original 'from' address is discarded.
588 let from' = unsplitJID (n,addrToText laddr,r) 583 from' <- forClient state senderk (return Nothing)
584 $ return . Just . clientJID conn
589 -- dup <- atomically $ cloneStanza (msg { stanzaTo=Just to', stanzaFrom=Just from' }) 585 -- dup <- atomically $ cloneStanza (msg { stanzaTo=Just to', stanzaFrom=Just from' })
590 let dup = (msg { stanzaTo=Just to', stanzaFrom=Just from' }) 586 let dup = (msg { stanzaTo=Just to', stanzaFrom=from' })
591 sendModifiedStanzaToPeer dup chan 587 sendModifiedStanzaToPeer dup (connChan conn)
592 PeerOrigin senderk _ -> do 588 PeerOrigin senderk _ -> do
593 (pchans,cchans) <- atomically $ do 589 (pchans,cchans) <- atomically $ do
594 pc <- readTVar (pkeyToChan state) 590 pc <- readTVar (pkeyToChan state)
@@ -596,14 +592,14 @@ deliverMessage state fail msg =
596 return (pc,cc) 592 return (pc,cc)
597 fromMaybe fail $ (Map.lookup senderk pchans) 593 fromMaybe fail $ (Map.lookup senderk pchans)
598 <&> \(Conn { connChan = sender_chan 594 <&> \(Conn { connChan = sender_chan
599 , auxData = ConnectionData (Left laddr) ctyp }) -> do 595 , auxData = ConnectionData (Left laddr) ctyp cprof }) -> do
600 fromMaybe fail $ (stanzaTo msg) <&> \to -> do 596 fromMaybe fail $ (stanzaTo msg) <&> \to -> do
601 (mine,(n,h,r)) <- rewriteJIDForClient laddr to [] 597 (mine,(n,h,r)) <- rewriteJIDForClient laddr to []
602 if not mine then fail else do 598 if not mine then fail else do
603 let to' = unsplitJID (n,h,r) 599 let to' = unsplitJID (n,h,r)
604 let (cmapVar,ckey) = case ctyp of 600 let (cmapVar,ckey) = case ctyp of
605 Tox -> (clientsByProfile state , n <&> (<> ".tox") ) 601 Tox -> (clientsByProfile state , Just cprof )
606 XMPP -> (clientsByUser state , n ) 602 XMPP -> (clientsByUser state , n )
607 cmap <- atomically . readTVar $ cmapVar 603 cmap <- atomically . readTVar $ cmapVar
608 chans <- fmap (fromMaybe []) $ do 604 chans <- fmap (fromMaybe []) $ do
609 forM (ckey >>= flip Map.lookup cmap) $ \presence_container -> do 605 forM (ckey >>= flip Map.lookup cmap) $ \presence_container -> do
@@ -1084,14 +1080,12 @@ peerSubscriptionRequest state fail k stanza chan = do
1084 cmap <- readTVar (clients state) 1080 cmap <- readTVar (clients state)
1085 return (pktc,cktc,cmap) 1081 return (pktc,cktc,cmap)
1086 fromMaybe fail $ (Map.lookup k pktc) 1082 fromMaybe fail $ (Map.lookup k pktc)
1087 <&> \Conn { auxData=ConnectionData (Left laddr) ctyp } -> do 1083 <&> \Conn { auxData=ConnectionData (Left laddr) ctyp profile } -> do
1088 (mine,totup) <- rewriteJIDForClient laddr to [] 1084 (mine,totup) <- rewriteJIDForClient laddr to []
1089 if not mine then fail else do 1085 if not mine then fail else do
1090 (_,fromtup) <- rewriteJIDForClient laddr from [] 1086 (_,fromtup) <- rewriteJIDForClient laddr from []
1091 fromMaybe fail $ mto_u <&> \u -> do 1087 fromMaybe fail $ mto_u <&> \u -> do
1092 fromMaybe fail $ mfrom_u <&> \from_u -> do 1088 fromMaybe fail $ mfrom_u <&> \from_u -> do
1093 profiles <- releventProfiles ctyp u
1094 forM_ profiles $ \profile -> do
1095 resolved_subs <- resolvedFromRoster ConfigFiles.getSubscribers u profile 1089 resolved_subs <- resolvedFromRoster ConfigFiles.getSubscribers u profile
1096 let already_subscribed = elem (mfrom_u,k) resolved_subs 1090 let already_subscribed = elem (mfrom_u,k) resolved_subs
1097 is_wanted = case stanzaType stanza of 1091 is_wanted = case stanzaType stanza of
@@ -1225,7 +1219,7 @@ peerInformSubscription state fail k stanza = do
1225 return (pktc,cktc,cmap) 1219 return (pktc,cktc,cmap)
1226 fromMaybe fail $ (Map.lookup k ktc) 1220 fromMaybe fail $ (Map.lookup k ktc)
1227 <&> \(Conn { connChan=sender_chan 1221 <&> \(Conn { connChan=sender_chan
1228 , auxData =ConnectionData (Left laddr) ctyp }) -> do 1222 , auxData =ConnectionData (Left laddr) ctyp profile}) -> do
1229 (_,(from_u,from_h,_)) <- rewriteJIDForClient laddr from [] 1223 (_,(from_u,from_h,_)) <- rewriteJIDForClient laddr from []
1230 let from'' = unsplitJID (from_u,from_h,Nothing) 1224 let from'' = unsplitJID (from_u,from_h,Nothing)
1231 muser = do 1225 muser = do
@@ -1237,8 +1231,6 @@ peerInformSubscription state fail k stanza = do
1237 -- This would allow us to answer anonymous probes with 'unsubscribed'. 1231 -- This would allow us to answer anonymous probes with 'unsubscribed'.
1238 fromMaybe fail $ muser <&> \user -> do 1232 fromMaybe fail $ muser <&> \user -> do
1239 addrs <- resolvePeer from_h 1233 addrs <- resolvePeer from_h
1240 profiles <- releventProfiles ctyp user
1241 forM_ profiles $ \profile -> do
1242 was_solicited <- removeFromRosterFile ConfigFiles.modifySolicited user profile from'' addrs 1234 was_solicited <- removeFromRosterFile ConfigFiles.modifySolicited user profile from'' addrs
1243 subs <- resolvedFromRoster ConfigFiles.getSubscribers user profile 1235 subs <- resolvedFromRoster ConfigFiles.getSubscribers user profile
1244 let is_sub = not . null $ map (from_u,) addrs `intersect` subs 1236 let is_sub = not . null $ map (from_u,) addrs `intersect` subs
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index 1de6a26a..49cfbb95 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -1254,8 +1254,9 @@ forkConnection :: Server SockAddr ConnectionData releaseKey XML.Event
1254 -> Sink (Flush XML.Event) IO () 1254 -> Sink (Flush XML.Event) IO ()
1255 -> TChan Stanza 1255 -> TChan Stanza
1256 -> IO (TChan Stanza) 1256 -> IO (TChan Stanza)
1257forkConnection sv xmpp saddr (ConnectionData auxAddr _) pingflag src snk stanzas = do 1257forkConnection sv xmpp saddr cdta pingflag src snk stanzas = do
1258 let clientOrServer@(namespace,tellmyname,telltheirname,_) = case auxAddr of 1258 let auxAddr = cdAddr cdta
1259 clientOrServer@(namespace,tellmyname,telltheirname,_) = case auxAddr of
1259 Right _ -> ("jabber:client", xmppTellMyNameToClient xmpp (ClientAddress saddr) 1260 Right _ -> ("jabber:client", xmppTellMyNameToClient xmpp (ClientAddress saddr)
1260 , xmppTellClientHisName xmpp (ClientAddress saddr) 1261 , xmppTellClientHisName xmpp (ClientAddress saddr)
1261 , ClientOrigin (ClientAddress saddr)) 1262 , ClientOrigin (ClientAddress saddr))
@@ -1414,13 +1415,19 @@ peerKey bind_addr sock = do
1414 else return laddr -- Weird hack: addr is would-be peer name 1415 else return laddr -- Weird hack: addr is would-be peer name
1415 -- Assume remote peers are listening on the same port that we do. 1416 -- Assume remote peers are listening on the same port that we do.
1416 let peerport = fromIntegral $ fromMaybe 5269 $ bind_addr >>= sockAddrPort 1417 let peerport = fromIntegral $ fromMaybe 5269 $ bind_addr >>= sockAddrPort
1417 return $ (raddr `withPort` peerport,ConnectionData (Left (Local laddr)) XMPP) 1418 return $ ( raddr `withPort` peerport
1419 , ConnectionData { cdAddr = Left (Local laddr)
1420 , cdType = XMPP
1421 , cdProfile = "." } )
1418 1422
1419clientKey :: SocketLike sock => sock -> IO (SockAddr,ConnectionData) 1423clientKey :: SocketLike sock => sock -> IO (SockAddr,ConnectionData)
1420clientKey sock = do 1424clientKey sock = do
1421 laddr <- getSocketName sock 1425 laddr <- getSocketName sock
1422 raddr <- getPeerName sock 1426 raddr <- getPeerName sock
1423 return $ (laddr,ConnectionData (Right (Remote raddr)) XMPP) 1427 return $ ( laddr
1428 , ConnectionData { cdAddr = Right (Remote raddr)
1429 , cdType = XMPP
1430 , cdProfile = "." } )
1424 1431
1425xmlifyRosterItems :: Monad m => Set Text -> Text -> Set Text -> ConduitM i Event m () 1432xmlifyRosterItems :: Monad m => Set Text -> Text -> Set Text -> ConduitM i Event m ()
1426xmlifyRosterItems solicited stype set = mapM_ item (Set.toList set) 1433xmlifyRosterItems solicited stype set = mapM_ item (Set.toList set)
@@ -1830,7 +1837,11 @@ data ConnectionType = XMPP | Tox
1830data ConnectionData = ConnectionData 1837data ConnectionData = ConnectionData
1831 { cdAddr :: Either (Local SockAddr) -- Peer connection local address 1838 { cdAddr :: Either (Local SockAddr) -- Peer connection local address
1832 (Remote SockAddr) -- Client connection remote address 1839 (Remote SockAddr) -- Client connection remote address
1833 , cdType :: ConnectionType 1840 , cdType :: ConnectionType
1841 , cdProfile :: Text -- Currently ignored for clients. Instead, see
1842 -- 'clientProfile' field of 'ClientState'.
1843 --
1844 -- For peers: "." for XMPP, otherwise the ".tox" hostname.
1834 } 1845 }
1835 deriving (Eq,Ord,Show) 1846 deriving (Eq,Ord,Show)
1836 1847
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 7aa5cd2c..3d6b5f7b 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -1547,11 +1547,12 @@ announceToxJabberPeer :: PublicKey -- ^ This node's long-term user key.
1547announceToxJabberPeer me them echan laddr saddr pingflag tsrc tsnk 1547announceToxJabberPeer me them echan laddr saddr pingflag tsrc tsnk
1548 = do 1548 = do
1549 atomically $ writeTChan echan 1549 atomically $ writeTChan echan
1550 ( (saddr, ConnectionData (Left (Local laddr)) XMPPServer.Tox ) 1550 ( (saddr, ConnectionData (Left (Local laddr)) XMPPServer.Tox (toHostname me) )
1551 , Tcp.Connection pingflag xsrc xsnk ) 1551 , Tcp.Connection pingflag xsrc xsnk )
1552 return Nothing 1552 return Nothing
1553 where 1553 where
1554 xsrc = tsrc =$= toxToXmpp laddr me (T.pack $ show (Tox.key2id them) ++ ".tox") 1554 toHostname k = T.pack $ show (Tox.key2id k) ++ ".tox"
1555 xsrc = tsrc =$= toxToXmpp laddr me (toHostname them)
1555 xsnk = flushPassThrough xmppToTox =$= tsnk 1556 xsnk = flushPassThrough xmppToTox =$= tsnk
1556 1557
1557vShowMe :: Tox.ViewSnapshot -> Int -> B.ByteString 1558vShowMe :: Tox.ViewSnapshot -> Int -> B.ByteString