summaryrefslogtreecommitdiff
path: root/Mainline.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-27 03:40:27 -0400
committerjoe <joe@jerkface.net>2017-07-27 03:40:27 -0400
commit7d0a9f4e021dd15463659a115610df6d60f973a0 (patch)
tree9f1fe6d9e2b4aada9b9401cb5739fddc542be3ed /Mainline.hs
parentf176bb207880abd6fbe3fb361fab40fdfd946be8 (diff)
More verbose reporting of parse errors.
Diffstat (limited to 'Mainline.hs')
-rw-r--r--Mainline.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/Mainline.hs b/Mainline.hs
index 921bea0f..93393c40 100644
--- a/Mainline.hs
+++ b/Mainline.hs
@@ -389,12 +389,21 @@ encodeAny tid key val aux = toDict $
389 .: "y" .=! key 389 .: "y" .=! key
390 .: endDict 390 .: endDict
391 391
392showParseError bs addr err = L8.unpack $ L8.unlines es
393 where
394 es = map (L8.append prefix) (L8.pack err : L8.lines pp)
395
396 prefix = L8.pack (show addr) <> " --> "
397
398 pp = either L8.pack showBEncode $ BE.decode bs
399
392parsePacket :: ByteString -> SockAddr -> Either String (Message BValue, NodeInfo) 400parsePacket :: ByteString -> SockAddr -> Either String (Message BValue, NodeInfo)
393parsePacket bs addr = do pkt <- BE.decode bs 401parsePacket bs addr = left (showParseError bs addr) $ do
394 -- TODO: Error packets do not inclucde a valid msgOrigin. 402 pkt <- BE.decode bs
395 -- The BE.decode method is using 'zeroID' as a placeholder. 403 -- TODO: Error packets do not inclucde a valid msgOrigin.
396 ni <- nodeInfo (msgOrigin pkt) addr 404 -- The BE.decode method is using 'zeroID' as a placeholder.
397 return (pkt, ni) 405 ni <- nodeInfo (msgOrigin pkt) addr
406 return (pkt, ni)
398 407
399encodePacket :: Message BValue -> NodeInfo -> (ByteString, SockAddr) 408encodePacket :: Message BValue -> NodeInfo -> (ByteString, SockAddr)
400encodePacket msg ni = ( toStrict $ BE.encode msg 409encodePacket msg ni = ( toStrict $ BE.encode msg
@@ -623,8 +632,7 @@ mainlineKademlia client committee var sched
623 return $ do 632 return $ do
624 io1 >> io2 633 io1 >> io2
625 hPutStrLn stderr $ unwords 634 hPutStrLn stderr $ unwords
626 [ "Buckets: " 635 [ show (transitionedTo tr)
627 , show (transitionedTo tr)
628 , show (transitioningNode tr) 636 , show (transitioningNode tr)
629 ] 637 ]
630 } 638 }