diff options
-rw-r--r-- | examples/dhtd.hs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 74e08073..4b79b132 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -861,10 +861,32 @@ clientSession s@Session{..} sock cnum h = do | |||
861 | Just mypubkey -> do | 861 | Just mypubkey -> do |
862 | let nidstr = strp s | 862 | let nidstr = strp s |
863 | goParse = either | 863 | goParse = either |
864 | (hPutClient h . ("Bad netcrypto target: "++)) | 864 | (\_ -> either (hPutClient h . ("Bad netcrypto target: "++)) |
865 | (goTarget . Tox.id2key) | 865 | (goTarget . Left) |
866 | (readEither nidstr)) | ||
867 | (goTarget . Right . Tox.id2key) | ||
866 | $ readEither nidstr | 868 | $ readEither nidstr |
867 | goTarget nid = do | 869 | goTarget (Left nodeinfo) = do |
870 | msec <- atomically $ do | ||
871 | ks <- map swap <$> readKeys userkeys (accounts roster) | ||
872 | return $ Data.List.lookup mypubkey ks | ||
873 | case mbTox of | ||
874 | Nothing -> hPutClient h "Requires Tox enabled." | ||
875 | Just tox-> do | ||
876 | case msec of | ||
877 | Nothing -> hPutClient h "Error getting secret key" | ||
878 | Just sec -> do | ||
879 | let nid = Tox.nodeId nodeinfo | ||
880 | naddr = Tox.nodeAddr nodeinfo | ||
881 | let acsVar = accounts (Tox.toxContactInfo tox) | ||
882 | acsmap <- atomically $ readTVar acsVar | ||
883 | case HashMap.lookup (Tox.key2id mypubkey) acsmap of | ||
884 | Nothing -> hPutClient h "Unable to find account for selected key" | ||
885 | Just account -> do | ||
886 | atomically $ setContactAddr (Tox.id2key nid) naddr account | ||
887 | Tox.netCrypto tox sec (Tox.id2key nid) | ||
888 | hPutClient h "Handshake sent" | ||
889 | goTarget (Right nid) = do | ||
868 | msec <- atomically $ do | 890 | msec <- atomically $ do |
869 | ks <- map swap <$> readKeys userkeys (accounts roster) | 891 | ks <- map swap <$> readKeys userkeys (accounts roster) |
870 | return $ Data.List.lookup mypubkey ks | 892 | return $ Data.List.lookup mypubkey ks |