diff options
Diffstat (limited to 'src/Network/DatagramServer')
-rw-r--r-- | src/Network/DatagramServer/Mainline.hs | 18 |
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 | |||
68 | import qualified Data.ByteString.Lazy as L | 68 | import qualified Data.ByteString.Lazy as L |
69 | import Data.Default | 69 | import Data.Default |
70 | import Data.LargeWord | 70 | import Data.LargeWord |
71 | import Data.Monoid | ||
71 | import qualified Data.Serialize as S | 72 | import qualified Data.Serialize as S |
72 | import Data.Serialize (Serialize, get, put, remaining, getBytes, putByteString) | 73 | import Data.Serialize (Serialize, get, put, remaining, getBytes, putByteString) |
73 | import Data.String | 74 | import 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. | ||
323 | instance Serialize a => Serialize (NodeInfo KMessageOf a ()) where | ||
324 | get = (\a b -> NodeInfo a b ()) <$> get <*> get | ||
325 | put NodeInfo {..} = put nodeId >> put nodeAddr | ||
326 | |||
327 | instance Pretty ip => Pretty (NodeInfo KMessageOf ip ()) where | ||
328 | pPrint NodeInfo {..} = pPrint nodeId <> "@(" <> pPrint nodeAddr <> ")" | ||
329 | |||
330 | instance Pretty ip => Pretty [NodeInfo KMessageOf ip ()] where | ||
331 | pPrint = PP.vcat . PP.punctuate "," . map pPrint | ||
332 | |||
333 | |||
334 | |||