diff options
author | joe <joe@jerkface.net> | 2018-05-22 01:40:28 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-05-22 01:40:28 -0400 |
commit | b56fb7874cda7799b2535dee81a32dcedb09c676 (patch) | |
tree | f74e9c71e2f69cb8d97ed4d4ffad5a884d755425 /examples | |
parent | 1661192a9c84ceaad6d372bd80820a7066fa1e10 (diff) |
Configurable bind-addresses for xmpp.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dhtd.hs | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 918df327..0c0e0419 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -429,6 +429,14 @@ clientSession0 s sock cnum h = do | |||
429 | `catch` \e -> if isEOFError e then return () | 429 | `catch` \e -> if isEOFError e then return () |
430 | else throwIO e | 430 | else throwIO e |
431 | 431 | ||
432 | readKeys :: TVar [(SecretKey, PublicKey)] | ||
433 | -> TVar (HashMap.HashMap Tox.NodeId Account) | ||
434 | -> STM [(SecretKey, PublicKey)] | ||
435 | readKeys userkeys roster = do | ||
436 | uks <- readTVar userkeys | ||
437 | as <- readTVar roster | ||
438 | return $ uks ++ map ((userSecret *** Tox.id2key) . swap) (HashMap.toList as) | ||
439 | |||
432 | clientSession :: Session -> t1 -> t -> ClientHandle -> IO () | 440 | clientSession :: Session -> t1 -> t -> ClientHandle -> IO () |
433 | clientSession s@Session{..} sock cnum h = do | 441 | clientSession s@Session{..} sock cnum h = do |
434 | line <- dropWhile isSpace <$> hGetClientLine h | 442 | line <- dropWhile isSpace <$> hGetClientLine h |
@@ -584,7 +592,7 @@ clientSession s@Session{..} sock cnum h = do | |||
584 | -- k secrets (list key pairs, including secret keys) | 592 | -- k secrets (list key pairs, including secret keys) |
585 | 593 | ||
586 | ("k", s) | "" <- strp s -> cmd0 $ do | 594 | ("k", s) | "" <- strp s -> cmd0 $ do |
587 | ks <- atomically $ readTVar userkeys | 595 | ks <- atomically $ readKeys userkeys (accounts roster) |
588 | let spaces k | Just sel <- selectedKey, (sel == k) = " *" | 596 | let spaces k | Just sel <- selectedKey, (sel == k) = " *" |
589 | | otherwise = " " | 597 | | otherwise = " " |
590 | hPutClient h $ unlines $ map (\(_,k) -> mappend (spaces k) . show . Tox.key2id $ k) ks | 598 | hPutClient h $ unlines $ map (\(_,k) -> mappend (spaces k) . show . Tox.key2id $ k) ks |
@@ -601,17 +609,14 @@ clientSession s@Session{..} sock cnum h = do | |||
601 | ++ [mappend " *" . show . Tox.key2id $ pubkey] | 609 | ++ [mappend " *" . show . Tox.key2id $ pubkey] |
602 | switchKey $ Just pubkey | 610 | switchKey $ Just pubkey |
603 | | "secrets" <- strp s -> cmd0 $ do | 611 | | "secrets" <- strp s -> cmd0 $ do |
604 | ks <- atomically $ do | 612 | ks <- atomically $ readKeys userkeys (accounts roster) |
605 | uks <- readTVar userkeys | ||
606 | as <- readTVar (accounts roster) | ||
607 | return $ uks ++ map ((userSecret *** Tox.id2key) . swap) (HashMap.toList as) | ||
608 | skey <- maybe (return Nothing) (atomically . dhtSecretKey) | 613 | skey <- maybe (return Nothing) (atomically . dhtSecretKey) |
609 | $ Map.lookup netname dhts | 614 | $ Map.lookup netname dhts |
610 | hPutClient h . showReport $ map mkrow ks ++ case skey >>= encodeSecret of | 615 | hPutClient h . showReport $ map mkrow ks ++ case skey >>= encodeSecret of |
611 | Just x -> [("",""),("dht-key:",B.unpack x)] | 616 | Just x -> [("",""),("dht-key:",B.unpack x)] |
612 | Nothing -> [] | 617 | Nothing -> [] |
613 | | ("sel",_:expr) <- break isSpace s -> do | 618 | | ("sel",_:expr) <- break isSpace s -> do |
614 | ks <- atomically $ map (show . Tox.key2id . snd) <$> readTVar userkeys | 619 | ks <- atomically $ map (show . Tox.key2id . snd) <$> readKeys userkeys (accounts roster) |
615 | case find (isInfixOf expr) ks of | 620 | case find (isInfixOf expr) ks of |
616 | Just k -> do | 621 | Just k -> do |
617 | hPutClient h $ "Selected key: "++k | 622 | hPutClient h $ "Selected key: "++k |
@@ -871,6 +876,12 @@ clientSession s@Session{..} sock cnum h = do | |||
871 | announceInterval) | 876 | announceInterval) |
872 | dta | 877 | dta |
873 | reportit $ show $ announceTarget dta | 878 | reportit $ show $ announceTarget dta |
879 | ptest = fromMaybe "E:NoMethod" | ||
880 | $ fmap (\DHTAnnouncable { announceParseData | ||
881 | , announceTarget } | ||
882 | -> either ("E:"++) (show . announceTarget) | ||
883 | $ announceParseData dtastr) | ||
884 | a | ||
874 | 885 | ||
875 | let aerror = unlines | 886 | let aerror = unlines |
876 | [ "announce error." | 887 | [ "announce error." |
@@ -879,6 +890,10 @@ clientSession s@Session{..} sock cnum h = do | |||
879 | , "publish = " ++ maybe "nil" (const "ok") a | 890 | , "publish = " ++ maybe "nil" (const "ok") a |
880 | -- , "chktok = " ++ maybe "nil" (const "ok") chktok -- chktok = nil | 891 | -- , "chktok = " ++ maybe "nil" (const "ok") chktok -- chktok = nil |
881 | -- , "chkni = " ++ maybe "nil" (const "ok") chkni | 892 | -- , "chkni = " ++ maybe "nil" (const "ok") chkni |
893 | , "ptest = " ++ ptest | ||
894 | , "mameth = " ++ show (fmap (const ()) mameth) | ||
895 | , "lmeth = " ++ show (fmap (const ()) lmeth) | ||
896 | , "selectedKey = " ++ show selectedKey | ||
882 | ] | 897 | ] |
883 | fromMaybe (hPutClient h aerror) $ mameth <|> lmeth | 898 | fromMaybe (hPutClient h aerror) $ mameth <|> lmeth |
884 | 899 | ||
@@ -1007,7 +1022,8 @@ readExternals nodeAddr vars = do | |||
1007 | data Options = Options | 1022 | data Options = Options |
1008 | { portbt :: String | 1023 | { portbt :: String |
1009 | , porttox :: String | 1024 | , porttox :: String |
1010 | , portxmpp :: String | 1025 | , portxmpp :: String -- client-to-server |
1026 | , portxmppS :: String -- server-to-server | ||
1011 | , ip6bt :: Bool | 1027 | , ip6bt :: Bool |
1012 | , ip6tox :: Bool | 1028 | , ip6tox :: Bool |
1013 | , dhtkey :: Maybe SecretKey | 1029 | , dhtkey :: Maybe SecretKey |
@@ -1027,6 +1043,7 @@ sensibleDefaults = Options | |||
1027 | { portbt = "6881" | 1043 | { portbt = "6881" |
1028 | , porttox = "33445" | 1044 | , porttox = "33445" |
1029 | , portxmpp = "5222" | 1045 | , portxmpp = "5222" |
1046 | , portxmppS = "5269" | ||
1030 | , ip6bt = True | 1047 | , ip6bt = True |
1031 | , ip6tox = True | 1048 | , ip6tox = True |
1032 | , dhtkey = Nothing | 1049 | , dhtkey = Nothing |
@@ -1045,9 +1062,10 @@ parseArgs ("-4":args) opts = parseArgs args opts | |||
1045 | { ip6bt = False | 1062 | { ip6bt = False |
1046 | , ip6tox = False } | 1063 | , ip6tox = False } |
1047 | parseArgs (arg:args) opts = parseArgs args opts | 1064 | parseArgs (arg:args) opts = parseArgs args opts |
1048 | { portbt = fromMaybe (portbt opts) $ Prelude.lookup "bt" ports | 1065 | { portbt = fromMaybe (portbt opts) $ Prelude.lookup "bt" ports |
1049 | , porttox = fromMaybe (porttox opts) $ Prelude.lookup "tox" ports | 1066 | , porttox = fromMaybe (porttox opts) $ Prelude.lookup "tox" ports |
1050 | , portxmpp = fromMaybe (portxmpp opts) $ Prelude.lookup "xmpp" ports } | 1067 | , portxmpp = fromMaybe (portxmpp opts) $ Prelude.lookup "xmpp" ports |
1068 | , portxmppS = fromMaybe (portxmppS opts) $ Prelude.lookup "xmpp.s2s" ports } | ||
1051 | where | 1069 | where |
1052 | ports = map ( (dropWhile (==',') *** dropWhile (=='=')) | 1070 | ports = map ( (dropWhile (==',') *** dropWhile (=='=')) |
1053 | . break (=='=') ) | 1071 | . break (=='=') ) |
@@ -1482,7 +1500,10 @@ main = runResourceT $ liftBaseWith $ \resT -> do | |||
1482 | (msv,mconns,mstate) <- case portxmpp opts of | 1500 | (msv,mconns,mstate) <- case portxmpp opts of |
1483 | "" -> return (Nothing,Nothing,Nothing) | 1501 | "" -> return (Nothing,Nothing,Nothing) |
1484 | p -> do | 1502 | p -> do |
1485 | mxmppPort <- sockAddrPort <$> getBindAddress p True{-IPv6 supported-} | 1503 | cport <- getBindAddress p True{-IPv6 supported-} |
1504 | -- TODO: Allow running without an XMPP server-to-server port. | ||
1505 | -- This should probably be default for toxmpp use. | ||
1506 | sport <- getBindAddress (portxmppS opts) True{-IPv6 supported-} | ||
1486 | 1507 | ||
1487 | -- XMPP initialization | 1508 | -- XMPP initialization |
1488 | cw <- newConsoleWriter | 1509 | cw <- newConsoleWriter |
@@ -1497,7 +1518,7 @@ main = runResourceT $ liftBaseWith $ \resT -> do | |||
1497 | ] | 1518 | ] |
1498 | state <- newPresenceState cw (toxman announcer toxbkts <$> mbtox) serverVar | 1519 | state <- newPresenceState cw (toxman announcer toxbkts <$> mbtox) serverVar |
1499 | 1520 | ||
1500 | sv <- resT $ xmppServer (presenceHooks state (verbosity opts) Nothing) | 1521 | sv <- resT $ xmppServer (presenceHooks state (verbosity opts) (Just cport) (Just sport)) |
1501 | -- We now have a server object but it's not ready to use until | 1522 | -- We now have a server object but it's not ready to use until |
1502 | -- we put it into the 'server' field of our /state/ record. | 1523 | -- we put it into the 'server' field of our /state/ record. |
1503 | conns <- xmppConnections sv | 1524 | conns <- xmppConnections sv |