summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/Util.hs2
-rw-r--r--examples/dhtd.hs9
-rw-r--r--src/Network/Tox/NodeId.hs15
3 files changed, 22 insertions, 4 deletions
diff --git a/Presence/Util.hs b/Presence/Util.hs
index 8d9a9494..a934cad7 100644
--- a/Presence/Util.hs
+++ b/Presence/Util.hs
@@ -30,7 +30,7 @@ splitJID bjid =
30 server = head ys 30 server = head ys
31 name = case xs of 31 name = case xs of
32 (n:s:_) -> Just n 32 (n:s:_) -> Just n
33 (s:_) -> Nothing 33 _ -> Nothing
34 rsrc = case ys of 34 rsrc = case ys of
35 (s:_:_) -> Just $ last ys 35 (s:_:_) -> Just $ last ys
36 _ -> Nothing 36 _ -> Nothing
diff --git a/examples/dhtd.hs b/examples/dhtd.hs
index ea94b7ce..58a69c6a 100644
--- a/examples/dhtd.hs
+++ b/examples/dhtd.hs
@@ -505,8 +505,13 @@ clientSession s@Session{..} sock cnum h = do
505 Left ej -> if elem '@' s 505 Left ej -> if elem '@' s
506 then "Error: " ++ ej 506 then "Error: " ++ ej
507 else "Error: " ++ e 507 else "Error: " ++ e
508 Right jid -> show jid 508 Right jid -> unlines [ show jid
509 Right nid -> show nid ++ " nospam:" ++ drop 64 s 509 , Tox.noSpamIdToHex jid ]
510 Right nid -> let nspam = drop 64 s
511 jid :: Maybe Tox.NoSpamId
512 jid = readMaybe $ '0':'x':nspam ++ "@" ++ show nid ++ ".tox"
513 in unlines [ maybe "" show jid
514 , show nid ++ " nospam:" ++ nspam ]
510 Right nid -> show nid 515 Right nid -> show nid
511 516
512 ("lan", _) -> cmd0 $ do 517 ("lan", _) -> cmd0 $ do
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs
index dab1b14a..f3013142 100644
--- a/src/Network/Tox/NodeId.hs
+++ b/src/Network/Tox/NodeId.hs
@@ -29,6 +29,7 @@ module Network.Tox.NodeId
29 , sampleNodeId 29 , sampleNodeId
30 , NoSpam(..) 30 , NoSpam(..)
31 , NoSpamId(..) 31 , NoSpamId(..)
32 , noSpamIdToHex
32 , parseNoSpamId 33 , parseNoSpamId
33 , nospam64 34 , nospam64
34 , verifyChecksum) where 35 , verifyChecksum) where
@@ -520,6 +521,16 @@ verifyChecksum _ _ = return () -- TODO
520data NoSpamId = NoSpamId NoSpam PublicKey 521data NoSpamId = NoSpamId NoSpam PublicKey
521 deriving (Eq,Ord) 522 deriving (Eq,Ord)
522 523
524noSpamIdToHex :: NoSpamId -> String
525noSpamIdToHex (NoSpamId nspam pub) = C8.unpack (Base16.encode $ BA.convert pub)
526 ++ nospam16 nspam
527
528nospam16 :: NoSpam -> String
529nospam16 (NoSpam w32 Nothing) = n ++ "????"
530 where n = take 8 $ nospam16 (NoSpam w32 (Just 0))
531nospam16 (NoSpam w32 (Just w16)) = C8.unpack $ Base16.encode $ runPut $ do
532 put w32
533 put w16
523 534
524nospam64 :: NoSpam -> String 535nospam64 :: NoSpam -> String
525nospam64 (NoSpam w32 Nothing) = n ++ "???" 536nospam64 (NoSpam w32 Nothing) = n ++ "???"
@@ -549,7 +560,9 @@ parseNoSpamId spec | Text.length spec == 76
549 560
550parseNoSpamJID :: Text -> Either String NoSpamId 561parseNoSpamJID :: Text -> Either String NoSpamId
551parseNoSpamJID jid = do 562parseNoSpamJID jid = do
552 (Just u,h,_) <- Right $ splitJID jid 563 (u,h) <- maybe (Left "Invalid JID.") Right
564 $ let (mu,h,_) = splitJID jid
565 in fmap (, h) mu
553 base64 <- case splitAt 43 $ Text.unpack h of 566 base64 <- case splitAt 43 $ Text.unpack h of
554 (base64,".tox") -> Right base64 567 (base64,".tox") -> Right base64
555 _ -> Left "Hostname should be 43 base64 digits followed by .tox." 568 _ -> Left "Hostname should be 43 base64 digits followed by .tox."