summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/Presence.hs4
-rw-r--r--ToxToXMPP.hs21
-rw-r--r--examples/dhtd.hs9
3 files changed, 21 insertions, 13 deletions
diff --git a/Presence/Presence.hs b/Presence/Presence.hs
index a55d49ab..678a5c99 100644
--- a/Presence/Presence.hs
+++ b/Presence/Presence.hs
@@ -99,7 +99,8 @@ data ToxManager k = ToxManager
99 99
100data PresenceState = forall status. PresenceState 100data PresenceState = forall status. PresenceState
101 { clients :: TVar (Map ConnectionKey ClientState) 101 { clients :: TVar (Map ConnectionKey ClientState)
102 , clientsByUser :: TVar (Map Text LocalPresence) 102 , clientsByUser :: TVar (Map Text LocalPresence) -- TODO: For tox-enabled clients, the lookup key should be the client's toxid
103 -- rather than the unix user.
103 , remotesByPeer :: TVar (Map ConnectionKey 104 , remotesByPeer :: TVar (Map ConnectionKey
104 (Map UserName RemotePresence)) 105 (Map UserName RemotePresence))
105 , server :: TMVar (XMPPServer, Connection.Manager status Text) 106 , server :: TMVar (XMPPServer, Connection.Manager status Text)
@@ -601,6 +602,7 @@ deliverMessage state fail msg =
601 let to' = unsplitJID (n,h,r) 602 let to' = unsplitJID (n,h,r)
602 cmap <- atomically . readTVar $ clientsByUser state 603 cmap <- atomically . readTVar $ clientsByUser state
603 chans <- fmap (fromMaybe []) $ do 604 chans <- fmap (fromMaybe []) $ do
605 -- TODO: Tox-enabled clients need to be found by tox key.
604 forM (n >>= flip Map.lookup cmap) $ \presence_container -> do 606 forM (n >>= flip Map.lookup cmap) $ \presence_container -> do
605 let ks = Map.keys (networkClients presence_container) 607 let ks = Map.keys (networkClients presence_container)
606 chans = do 608 chans = do
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index f4a7cbab..2ab59568 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -83,18 +83,23 @@ xmppToTox = doNestingXML $ fix $ \loop -> do
83 dput DPut.XMan $ "xmppToTox: " ++ show e 83 dput DPut.XMan $ "xmppToTox: " ++ show e
84 loop 84 loop
85 85
86toxToXmpp :: Monad m => Text -> Conduit Tox.CryptoMessage m XML.Event 86toxToXmpp :: Monad m => SockAddr -> PublicKey -> Text -> Conduit Tox.CryptoMessage m XML.Event
87toxToXmpp toxhost = do 87toxToXmpp laddr me theirhost = do
88 CL.sourceList $ XMPP.greet' "jabber:server" toxhost 88 CL.sourceList $ XMPP.greet' "jabber:server" theirhost
89 let me_u = T.pack $ show (key2id me)
89 awaitForever $ \toxmsg -> do 90 awaitForever $ \toxmsg -> do
90 xmppInstantMessage "jabber:server" (Just toxhost) (T.pack $ show $ msgID toxmsg) 91 xmppInstantMessage "jabber:server"
92 (Just theirhost) -- /from/
93 (Just $ unsplitJID (me_u,T.pack (show laddr),Nothing)) -- /to/ should match local address of this node.
94 (T.pack $ show $ msgID toxmsg)
91 95
92xmppInstantMessage :: Monad m => Text -> Maybe Text -> Text -> ConduitM i Event m () 96xmppInstantMessage :: Monad m => Text -> Maybe Text -> Maybe Text -> Text -> ConduitM i Event m ()
93xmppInstantMessage namespace mfrom text = do 97xmppInstantMessage namespace mfrom mto text = do
94 let ns n = n { nameNamespace = Just namespace } 98 let ns n = n { nameNamespace = Just namespace }
95 C.yield $ EventBeginElement (ns "message") 99 C.yield $ EventBeginElement (ns "message")
96 ((maybe id (\t->(attr "from" t:)) mfrom) 100 ( maybe id (\t->(attr "from" t:)) mfrom
97 [attr "type" "normal" ]) 101 $ maybe id (\t->(attr "to" t:)) mto
102 $ [attr "type" "normal" ] )
98 C.yield $ EventBeginElement (ns "body") [] 103 C.yield $ EventBeginElement (ns "body") []
99 C.yield $ EventContent $ ContentText text 104 C.yield $ EventContent $ ContentText text
100 C.yield $ EventEndElement (ns "body") 105 C.yield $ EventEndElement (ns "body")
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index 2b5974f1..b81e88b5 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -1375,7 +1375,8 @@ newXmmpSink session@(Tox.NCrypto { ncOutgoingQueue = outGoingQVar, ncPacketQueue
1375 1375
1376-- | Called upon a new Tox friend-connection session with a remote peer in 1376-- | Called upon a new Tox friend-connection session with a remote peer in
1377-- order to set up translating conduits that simulate a remote XMPP server. 1377-- order to set up translating conduits that simulate a remote XMPP server.
1378announceToxJabberPeer :: PublicKey -- ^ Remote tox node's long-term user key. 1378announceToxJabberPeer :: PublicKey -- ^ This node's long-term user key.
1379 -> PublicKey -- ^ Remote tox node's long-term user key.
1379 -> TChan ((ConnectionKey,SockAddr), Tcp.ConnectionEvent XML.Event) 1380 -> TChan ((ConnectionKey,SockAddr), Tcp.ConnectionEvent XML.Event)
1380 -> SockAddr -- ^ Local bind address for incoming Tox packets. 1381 -> SockAddr -- ^ Local bind address for incoming Tox packets.
1381 -> SockAddr -- ^ Remote address for this connection. 1382 -> SockAddr -- ^ Remote address for this connection.
@@ -1383,14 +1384,14 @@ announceToxJabberPeer :: PublicKey -- ^ Remote tox node's long-term user key.
1383 -> C.Source IO Tox.CryptoMessage 1384 -> C.Source IO Tox.CryptoMessage
1384 -> C.Sink (Flush Tox.CryptoMessage) IO () 1385 -> C.Sink (Flush Tox.CryptoMessage) IO ()
1385 -> IO (Maybe (Tox.NetCryptoSession -> Tox.NetCryptoSession)) 1386 -> IO (Maybe (Tox.NetCryptoSession -> Tox.NetCryptoSession))
1386announceToxJabberPeer them echan laddr saddr pingflag tsrc tsnk 1387announceToxJabberPeer me them echan laddr saddr pingflag tsrc tsnk
1387 = do 1388 = do
1388 atomically $ writeTChan echan 1389 atomically $ writeTChan echan
1389 ( (PeerKey saddr, laddr ) 1390 ( (PeerKey saddr, laddr )
1390 , Tcp.Connection pingflag xsrc xsnk ) 1391 , Tcp.Connection pingflag xsrc xsnk )
1391 return Nothing 1392 return Nothing
1392 where 1393 where
1393 xsrc = tsrc =$= toxToXmpp (T.pack $ show (Tox.key2id them) ++ ".tox") 1394 xsrc = tsrc =$= toxToXmpp laddr me (T.pack $ show (Tox.key2id them) ++ ".tox")
1394 xsnk = flushPassThrough xmppToTox =$= tsnk 1395 xsnk = flushPassThrough xmppToTox =$= tsnk
1395 1396
1396vShowMe :: Tox.ViewSnapshot -> Int -> B.ByteString 1397vShowMe :: Tox.ViewSnapshot -> Int -> B.ByteString
@@ -1783,7 +1784,7 @@ main = do
1783 xmppSink = newXmmpSink netcrypto 1784 xmppSink = newXmmpSink netcrypto
1784 forM_ msv $ \sv -> do 1785 forM_ msv $ \sv -> do
1785 let Tox.HaveDHTKey saddr = Tox.ncSockAddr netcrypto 1786 let Tox.HaveDHTKey saddr = Tox.ncSockAddr netcrypto
1786 announceToxJabberPeer (Tox.ncTheirPublicKey netcrypto) (xmppEventChannel sv) addrTox saddr pingflag xmppSrc xmppSink 1787 announceToxJabberPeer (Tox.ncMyPublicKey netcrypto) (Tox.ncTheirPublicKey netcrypto) (xmppEventChannel sv) addrTox saddr pingflag xmppSrc xmppSink
1787 forM_ mbtox $ \tox -> do 1788 forM_ mbtox $ \tox -> do
1788 let ContactInfo{accounts} = Tox.toxContactInfo tox 1789 let ContactInfo{accounts} = Tox.toxContactInfo tox
1789 mbacc <- HashMap.lookup (Tox.key2id $ Tox.ncMyPublicKey netcrypto) 1790 mbacc <- HashMap.lookup (Tox.key2id $ Tox.ncMyPublicKey netcrypto)