summaryrefslogtreecommitdiff
path: root/Mainline.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-28 20:51:55 -0400
committerjoe <joe@jerkface.net>2017-07-28 20:51:55 -0400
commite4ecff0ba5ad4b392a419ab7723c5df49513d1fa (patch)
tree08c67c495b5848702f920dfc4e404e51c8ee7a7c /Mainline.hs
parent23fd54d69e88568109b4e8588451b1790b9e9248 (diff)
Code to enable detailed packet printouts (disabled via comment).
Diffstat (limited to 'Mainline.hs')
-rw-r--r--Mainline.hs24
1 files changed, 21 insertions, 3 deletions
diff --git a/Mainline.hs b/Mainline.hs
index ab74eebf..deb75079 100644
--- a/Mainline.hs
+++ b/Mainline.hs
@@ -411,14 +411,31 @@ encodeAny tid key val aux = toDict $
411 .: "y" .=! key 411 .: "y" .=! key
412 .: endDict 412 .: endDict
413 413
414showParseError bs addr err = L8.unpack $ L8.unlines es 414
415showPacket f addr flow bs = L8.unpack $ L8.unlines es
415 where 416 where
416 es = map (L8.append prefix) (L8.pack err : L8.lines pp) 417 es = map (L8.append prefix) (f $ L8.lines pp)
417 418
418 prefix = L8.pack (either show show $ either4or6 addr) <> " --> " 419 prefix = L8.pack (either show show $ either4or6 addr) <> flow
419 420
420 pp = either L8.pack showBEncode $ BE.decode bs 421 pp = either L8.pack showBEncode $ BE.decode bs
421 422
423-- Add detailed printouts for every packet.
424addVerbosity tr =
425 tr { awaitMessage = do
426 m <- awaitMessage tr
427 forM_ m $ mapM_ $ \(msg,addr) -> do
428 hPutStrLn stderr (showPacket id addr " --> " msg)
429 return m
430 , sendMessage = \addr msg -> do
431 hPutStrLn stderr (showPacket id addr " <-- " msg)
432 sendMessage tr addr msg
433 }
434
435
436
437showParseError bs addr err = showPacket (L8.pack err :) addr " --> " bs
438
422parsePacket :: ByteString -> SockAddr -> Either String (Message BValue, NodeInfo) 439parsePacket :: ByteString -> SockAddr -> Either String (Message BValue, NodeInfo)
423parsePacket bs addr = left (showParseError bs addr) $ do 440parsePacket bs addr = left (showParseError bs addr) $ do
424 pkt <- BE.decode bs 441 pkt <- BE.decode bs
@@ -540,6 +557,7 @@ newClient addr = do
540 map_var <- atomically $ newTVar (0, mempty) 557 map_var <- atomically $ newTVar (0, mempty)
541 let net = onInbound (updateRouting outgoingClient routing) 558 let net = onInbound (updateRouting outgoingClient routing)
542 $ layerTransport parsePacket encodePacket 559 $ layerTransport parsePacket encodePacket
560 -- $ addVerbosity
543 $ udp 561 $ udp
544 562
545 -- Paranoid: It's safe to define /net/ and /client/ to be mutually 563 -- Paranoid: It's safe to define /net/ and /client/ to be mutually