diff options
author | Joe Crayne <joe@jerkface.net> | 2019-11-29 16:34:27 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 22:57:44 -0500 |
commit | 0d75b2bd2f6002629bbeb9d6e43a19c0fcb6ac5f (patch) | |
tree | 275869d864b09b6d031da1c9578306ac3df0d71d /dht/examples | |
parent | ae914e1189a4f601388ad4b83be35e45bbc68d83 (diff) |
Refactoring.
Diffstat (limited to 'dht/examples')
-rw-r--r-- | dht/examples/dhtd.hs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index 3e9f8ff5..adfe0d69 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs | |||
@@ -63,6 +63,7 @@ import System.Posix.Signals | |||
63 | import Announcer | 63 | import Announcer |
64 | import Announcer.Tox | 64 | import Announcer.Tox |
65 | import ToxManager | 65 | import ToxManager |
66 | import Codec.AsciiKey256 | ||
66 | import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) | 67 | import Crypto.Tox -- (zeros32,SecretKey,PublicKey, generateSecretKey, toPublic, encodeSecret, decodeSecret, userKeys) |
67 | import DebugUtil | 68 | import DebugUtil |
68 | import Network.UPNP as UPNP | 69 | import Network.UPNP as UPNP |
@@ -1302,27 +1303,19 @@ onNewToxSession sv ssvar invc ContactInfo{accounts} addrTox netcrypto = do | |||
1302 | return () | 1303 | return () |
1303 | 1304 | ||
1304 | selectManager :: Maybe (t -> ToxManager clientAddress) -> Manager Tcp.TCPStatus T.Text -> T.Text -> Manager Pending T.Text | 1305 | selectManager :: Maybe (t -> ToxManager clientAddress) -> Manager Tcp.TCPStatus T.Text -> T.Text -> Manager Pending T.Text |
1305 | selectManager mtman tcp profile = case T.splitAt (T.length profile - 4) profile of | 1306 | selectManager mtman tcp profile = case stripSuffix ".tox" profile of |
1306 | (k,".tox") | Just tman <- mtman | 1307 | Just k | Just tman <- mtman |
1307 | -> let -- The following error call is safe because the toxConnections field | 1308 | -> let -- The following error call is safe because the toxConnections field |
1308 | -- does not make use of the PresenceState passed to tman. | 1309 | -- does not make use of the PresenceState passed to tman. |
1309 | tox = toxConnections $ tman $ error "PresenseState" | 1310 | tox = toxConnections $ tman $ error "PresenseState" |
1310 | tkey them = do | 1311 | tkey them0 = do |
1311 | me <- readMaybe (T.unpack k) | 1312 | me <- readMaybe (T.unpack k) |
1312 | them <- case T.splitAt 52 them of | 1313 | them <- stripSuffix ".tox" them0 >>= readMaybe . T.unpack |
1313 | (them0,".tox") -> readMaybe (T.unpack them0) | ||
1314 | _ -> case T.splitAt 43 them of | ||
1315 | (them0,".tox") -> readMaybe (T.unpack them0) | ||
1316 | _ -> Nothing | ||
1317 | return (Tox.ToxContact me them) | 1314 | return (Tox.ToxContact me them) |
1318 | in Manager | 1315 | in Manager |
1319 | { resolvePeer = \themhost -> do | 1316 | { resolvePeer = \themhost -> do |
1320 | r <- fromMaybe (return []) $ do | 1317 | r <- fromMaybe (return []) $ do |
1321 | themT <- case T.splitAt 52 themhost of | 1318 | themT <- stripSuffix ".tox" themhost |
1322 | (ts,".tox") -> Just ts | ||
1323 | _ -> case T.splitAt 43 themhost of | ||
1324 | (ts,".tox") -> Just ts | ||
1325 | _ -> Nothing | ||
1326 | them <- readMaybe $ T.unpack themT | 1319 | them <- readMaybe $ T.unpack themT |
1327 | me <- readMaybe $ T.unpack k | 1320 | me <- readMaybe $ T.unpack k |
1328 | let contact = Tox.ToxContact me them | 1321 | let contact = Tox.ToxContact me them |