From ab1aaab49ab6a4a13c4416201b261a69155f2eec Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 12 Jun 2017 21:49:13 -0400 Subject: Evacuated the Network.DHT.Mainline code. Most of it went to Network.BitTorrent.DHT.Message. Some of it went to Network.DatagramServer.Mainline. --- src/Network/DatagramServer/Mainline.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Network/DatagramServer') 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 import qualified Data.ByteString.Lazy as L import Data.Default import Data.LargeWord +import Data.Monoid import qualified Data.Serialize as S import Data.Serialize (Serialize, get, put, remaining, getBytes, putByteString) import Data.String @@ -314,3 +315,20 @@ instance WireFormat BValue KMessageOf where encodeHeaders _ kmsg = L.toStrict $ BE.encode kmsg encodePayload msg = fmap BE.toBEncode msg + +-- | KRPC 'compact list' compatible encoding: contact information for +-- nodes is encoded as a 26-byte string. Also known as "Compact node +-- info" the 20-byte Node ID in network byte order has the compact +-- IP-address/port info concatenated to the end. +instance Serialize a => Serialize (NodeInfo KMessageOf a ()) where + get = (\a b -> NodeInfo a b ()) <$> get <*> get + put NodeInfo {..} = put nodeId >> put nodeAddr + +instance Pretty ip => Pretty (NodeInfo KMessageOf ip ()) where + pPrint NodeInfo {..} = pPrint nodeId <> "@(" <> pPrint nodeAddr <> ")" + +instance Pretty ip => Pretty [NodeInfo KMessageOf ip ()] where + pPrint = PP.vcat . PP.punctuate "," . map pPrint + + + -- cgit v1.2.3