summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-12-10 09:35:31 -0500
committerJoe Crayne <joe@jerkface.net>2018-12-16 14:08:26 -0500
commit84a594d1f4c5d0d2b276da7063b7888363008e86 (patch)
tree7b32909b62ba31d02dd58fa565dbefdeb275edc4 /src/Network
parent0dd2f5e5d078b735760e097df4204f9778bb193d (diff)
tox: Allow hexadecimal key in NodeId read instance.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox/NodeId.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs
index 1c68249e..9a9c893a 100644
--- a/src/Network/Tox/NodeId.hs
+++ b/src/Network/Tox/NodeId.hs
@@ -321,12 +321,18 @@ instance Read NodeInfo where
321 let n = 43 -- characters in node id. 321 let n = 43 -- characters in node id.
322 parseAddr = RP.between (RP.char '(') (RP.char ')') (RP.munch (/=')')) 322 parseAddr = RP.between (RP.char '(') (RP.char ')') (RP.munch (/=')'))
323 RP.+++ RP.munch (\c -> not (isSpace c) && not (c `elem` ("{}()"::[Char]))) 323 RP.+++ RP.munch (\c -> not (isSpace c) && not (c `elem` ("{}()"::[Char])))
324 nodeidAt = do hexhash <- sequence $ replicate n (RP.satisfy b64digit) 324 nodeidAt = do (is64,hexhash) <-
325 fmap (True,) (sequence $ replicate n (RP.satisfy b64digit))
326 RP.+++ fmap (False,) (sequence $ replicate 64 (RP.satisfy isHexDigit))
325 RP.char '@' RP.+++ RP.satisfy isSpace 327 RP.char '@' RP.+++ RP.satisfy isSpace
326 addrstr <- parseAddr 328 addrstr <- parseAddr
327 nid <- case Base64.decode $ C8.pack $ 'A' : map (nmtoken64 False) hexhash of 329 nid <- if is64
328 Right bs | B.length bs - 1==32 -> return (bs2id $ BA.drop 1 bs) 330 then case Base64.decode $ C8.pack $ 'A' : map (nmtoken64 False) hexhash of
329 _ -> fail "Bad node id." 331 Right bs | B.length bs - 1==32 -> return (bs2id $ BA.drop 1 bs)
332 _ -> fail "Bad node id."
333 else case Base16.decode $ C8.pack hexhash of
334 (bs,rem) | B.length bs == 32 && B.null rem -> return (bs2id bs)
335 _ -> fail "Bad node id."
330 return (nid,addrstr) 336 return (nid,addrstr)
331 (nid,addrstr) <- ( nodeidAt RP.+++ ( (zeroID,) <$> parseAddr) ) 337 (nid,addrstr) <- ( nodeidAt RP.+++ ( (zeroID,) <$> parseAddr) )
332 (ip,port) <- case RP.readP_to_S (ip_w_port i) addrstr of 338 (ip,port) <- case RP.readP_to_S (ip_w_port i) addrstr of