summaryrefslogtreecommitdiff
path: root/src/Network/DatagramServer
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-06-12 21:49:13 -0400
committerjoe <joe@jerkface.net>2017-06-12 21:49:13 -0400
commitab1aaab49ab6a4a13c4416201b261a69155f2eec (patch)
treea12a93b606ec0fb779b7b776b88485470ee95023 /src/Network/DatagramServer
parentdb2e00b691058cade0af2588e82a8f1c1dc857ac (diff)
Evacuated the Network.DHT.Mainline code.
Most of it went to Network.BitTorrent.DHT.Message. Some of it went to Network.DatagramServer.Mainline.
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