diff options
author | joe <joe@jerkface.net> | 2018-05-20 00:17:35 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-05-20 00:17:35 -0400 |
commit | d1ce5a1dad8faca6cab13ca4c2612c1208d52850 (patch) | |
tree | 33d241430e50ab1b77d83a95ac84fff139767c65 | |
parent | f2016c7a77c077ec342a687a172a16bf64311709 (diff) |
Implemented "nid" command to convert hex toxid.
-rw-r--r-- | Announcer.hs | 1 | ||||
-rw-r--r-- | examples/dhtd.hs | 17 | ||||
-rwxr-xr-x | gi | 1 | ||||
-rw-r--r-- | src/Network/Tox/NodeId.hs | 3 |
4 files changed, 19 insertions, 3 deletions
diff --git a/Announcer.hs b/Announcer.hs index da1adcee..2b96c421 100644 --- a/Announcer.hs +++ b/Announcer.hs | |||
@@ -122,6 +122,7 @@ data AnnounceMethod r = forall nid ni sr addr tok a. | |||
122 | -- Kademlia. | 122 | -- Kademlia. |
123 | , aBuckets :: TVar (R.BucketList ni) | 123 | , aBuckets :: TVar (R.BucketList ni) |
124 | -- ^ Set this to the current Kademlia routing table buckets. | 124 | -- ^ Set this to the current Kademlia routing table buckets. |
125 | -- TODO: List of TVars to have separate routing tables for IPv6 and IPv4? | ||
125 | , aTarget :: nid | 126 | , aTarget :: nid |
126 | -- ^ This is the Kademlia node-id of the item being announced. | 127 | -- ^ This is the Kademlia node-id of the item being announced. |
127 | , aInterval :: POSIXTime | 128 | , aInterval :: POSIXTime |
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index b3c60015..918df327 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -449,12 +449,16 @@ clientSession s@Session{..} sock cnum h = do | |||
449 | mkrow _ = error (concat ["Assertion fail in 'mkrow' function at ", __FILE__, ":", show __LINE__]) | 449 | mkrow _ = error (concat ["Assertion fail in 'mkrow' function at ", __FILE__, ":", show __LINE__]) |
450 | sessionCommands :: [[String]] | 450 | sessionCommands :: [[String]] |
451 | sessionCommands = | 451 | sessionCommands = |
452 | [ ["stop"] | 452 | [ ["ping"] -- pinglike |
453 | , ["cookie"] -- pinglike | ||
454 | , ["stop"] | ||
455 | , ["throw"] | ||
453 | , ["quit"] | 456 | , ["quit"] |
454 | , ["pid"] | 457 | , ["pid"] |
455 | , ["external-ip"] | 458 | , ["external-ip"] |
456 | , ["threads"] | 459 | , ["threads"] |
457 | , ["mem"] | 460 | , ["mem"] |
461 | , ["nid"] | ||
458 | , ["ls"] | 462 | , ["ls"] |
459 | , ["k"] | 463 | , ["k"] |
460 | , ["roster"] | 464 | , ["roster"] |
@@ -471,7 +475,6 @@ clientSession s@Session{..} sock cnum h = do | |||
471 | , ["toxids"] | 475 | , ["toxids"] |
472 | , ["c"] | 476 | , ["c"] |
473 | , ["help"] | 477 | , ["help"] |
474 | , ["throw"] | ||
475 | ] | 478 | ] |
476 | case (map toLower c,args) of | 479 | case (map toLower c,args) of |
477 | (n, _) | n `elem` Map.keys dhts -> switchNetwork n | 480 | (n, _) | n `elem` Map.keys dhts -> switchNetwork n |
@@ -550,6 +553,16 @@ clientSession s@Session{..} sock cnum h = do | |||
550 | else hPutClient h "Run with +RTS -T to obtain live memory-usage information." | 553 | else hPutClient h "Run with +RTS -T to obtain live memory-usage information." |
551 | _ -> hPutClient h "error." | 554 | _ -> hPutClient h "error." |
552 | 555 | ||
556 | ("nid", s) | Just DHT{dhtParseId} <- Map.lookup netname dhts | ||
557 | -> cmd0 $ do | ||
558 | hPutClient h $ case dhtParseId s of | ||
559 | Left e -> | ||
560 | -- HACK: split nospam from hex toxid | ||
561 | case dhtParseId (take 64 s) of | ||
562 | Left e -> "Error: " ++ e | ||
563 | Right nid -> show nid ++ " nospam:" ++ drop 64 s | ||
564 | Right nid -> show nid | ||
565 | |||
553 | ("ls", _) | Just DHT{dhtBuckets} <- Map.lookup netname dhts | 566 | ("ls", _) | Just DHT{dhtBuckets} <- Map.lookup netname dhts |
554 | -> cmd0 $ do | 567 | -> cmd0 $ do |
555 | bkts <- atomically $ readTVar dhtBuckets | 568 | bkts <- atomically $ readTVar dhtBuckets |
@@ -17,7 +17,6 @@ ghci -fobject-code \ | |||
17 | -iPresence \ | 17 | -iPresence \ |
18 | -iArchive \ | 18 | -iArchive \ |
19 | -isrc \ | 19 | -isrc \ |
20 | -icryptonite-backport \ | ||
21 | build/b/Presence/monitortty.o \ | 20 | build/b/Presence/monitortty.o \ |
22 | build/b/cbits/cryptonite_salsa.o \ | 21 | build/b/cbits/cryptonite_salsa.o \ |
23 | build/b/cbits/cryptonite_xsalsa.o\ | 22 | build/b/cbits/cryptonite_xsalsa.o\ |
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs index fbf6702a..b12487a4 100644 --- a/src/Network/Tox/NodeId.hs +++ b/src/Network/Tox/NodeId.hs | |||
@@ -146,6 +146,9 @@ nmtoken64 _ c = c | |||
146 | 146 | ||
147 | instance Read NodeId where | 147 | instance Read NodeId where |
148 | readsPrec _ str | 148 | readsPrec _ str |
149 | | (bs,_) <- Base16.decode (C8.pack $ take 64 str) | ||
150 | , CryptoPassed pub <- publicKey bs -- B.length bs == 32 | ||
151 | = [ (key2id pub, drop (2 * B.length bs) str) ] | ||
149 | | Right bs <- fmap (BA.drop 1) $ Base64.decode $ C8.pack $ 'A':map (nmtoken64 False) (take 43 str) | 152 | | Right bs <- fmap (BA.drop 1) $ Base64.decode $ C8.pack $ 'A':map (nmtoken64 False) (take 43 str) |
150 | , CryptoPassed pub <- publicKey bs -- B.length bs == 32 | 153 | , CryptoPassed pub <- publicKey bs -- B.length bs == 32 |
151 | = [ (key2id pub, drop 43 str) ] | 154 | = [ (key2id pub, drop 43 str) ] |