summaryrefslogtreecommitdiff
path: root/src/Network/DatagramServer
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/DatagramServer')
-rw-r--r--src/Network/DatagramServer/Mainline.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Network/DatagramServer/Mainline.hs b/src/Network/DatagramServer/Mainline.hs
index 7f97739c..dd3c8bcd 100644
--- a/src/Network/DatagramServer/Mainline.hs
+++ b/src/Network/DatagramServer/Mainline.hs
@@ -68,6 +68,7 @@ import qualified Data.ByteString.Char8 as Char8
68import qualified Data.ByteString.Lazy as L 68import qualified Data.ByteString.Lazy as L
69import Data.Default 69import Data.Default
70import Data.LargeWord 70import Data.LargeWord
71import Data.Monoid
71import qualified Data.Serialize as S 72import qualified Data.Serialize as S
72import Data.Serialize (Serialize, get, put, remaining, getBytes, putByteString) 73import Data.Serialize (Serialize, get, put, remaining, getBytes, putByteString)
73import Data.String 74import Data.String
@@ -314,3 +315,20 @@ instance WireFormat BValue KMessageOf where
314 315
315 encodeHeaders _ kmsg = L.toStrict $ BE.encode kmsg 316 encodeHeaders _ kmsg = L.toStrict $ BE.encode kmsg
316 encodePayload msg = fmap BE.toBEncode msg 317 encodePayload msg = fmap BE.toBEncode msg
318
319-- | KRPC 'compact list' compatible encoding: contact information for
320-- nodes is encoded as a 26-byte string. Also known as "Compact node
321-- info" the 20-byte Node ID in network byte order has the compact
322-- IP-address/port info concatenated to the end.
323instance Serialize a => Serialize (NodeInfo KMessageOf a ()) where
324 get = (\a b -> NodeInfo a b ()) <$> get <*> get
325 put NodeInfo {..} = put nodeId >> put nodeAddr
326
327instance Pretty ip => Pretty (NodeInfo KMessageOf ip ()) where
328 pPrint NodeInfo {..} = pPrint nodeId <> "@(" <> pPrint nodeAddr <> ")"
329
330instance Pretty ip => Pretty [NodeInfo KMessageOf ip ()] where
331 pPrint = PP.vcat . PP.punctuate "," . map pPrint
332
333
334