summaryrefslogtreecommitdiff
path: root/src/Network/DHT
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-16 18:57:28 -0400
committerjoe <joe@jerkface.net>2017-07-16 18:57:28 -0400
commit30b27a0216bd85d4480463450e6f7fa60ed1ed60 (patch)
tree0ad84d9f0e83af519ff99623d7bdfd28545bbcb3 /src/Network/DHT
parent22b6b27c52b5848ed79789b5d5a948b841daaa83 (diff)
Refactoring.
Diffstat (limited to 'src/Network/DHT')
-rw-r--r--src/Network/DHT/Routing.hs42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/Network/DHT/Routing.hs b/src/Network/DHT/Routing.hs
index 7f0e1c94..e2bc5aa9 100644
--- a/src/Network/DHT/Routing.hs
+++ b/src/Network/DHT/Routing.hs
@@ -638,33 +638,33 @@ deriving instance ( Show ip
638-- [ /tbl'/ ] The updated routing 'Table'. 638-- [ /tbl'/ ] The updated routing 'Table'.
639-- 639--
640updateForInbound :: Ord ni => 640updateForInbound :: Ord ni =>
641 (nid -> Word -> Bool) 641 KademliaSpace nid ni
642 -> (ni -> nid)
643 -> Timestamp -> ni -> Table ni nid -> (Bool, [ni], Table ni nid) 642 -> Timestamp -> ni -> Table ni nid -> (Bool, [ni], Table ni nid)
644updateForInbound testIdBit nodeId tm ni tbl = 643updateForInbound space tm ni tbl =
645 maybe (False, [],tbl) (\(ps,tbl') -> (True, ps, tbl')) 644 maybe (False, [],tbl) (\(ps,tbl') -> (True, ps, tbl'))
646 $ modifyBucket testIdBit (\ni -> testIdBit $ nodeId ni) 645 $ modifyBucket (kademliaTestBit space)
647 (nodeId ni) 646 (\ni -> kademliaTestBit space $ kademliaLocation space ni)
648 (updateBucketForInbound tm ni) 647 (kademliaLocation space ni)
649 tbl 648 (updateBucketForInbound tm ni)
649 tbl
650 650
651-- | Update the routing table with the results of a ping. 651-- | Update the routing table with the results of a ping.
652-- 652--
653-- Each (a,(tm,b)) in the returned list indicates that the node /a/ was deleted from the 653-- Each (a,(tm,b)) in the returned list indicates that the node /a/ was deleted from the
654-- routing table and the node /b/, with timestamp /tm/, has taken its place. 654-- routing table and the node /b/, with timestamp /tm/, has taken its place.
655updateForPingResult :: Ord ni => 655updateForPingResult :: Ord ni =>
656 (nid -> Word -> Bool) 656 KademliaSpace nid ni
657 -> (ni -> nid)
658 -> ni -- ^ The pinged node. 657 -> ni -- ^ The pinged node.
659 -> Bool -- ^ True if we got a reply, False if it timed out. 658 -> Bool -- ^ True if we got a reply, False if it timed out.
660 -> Table ni nid -- ^ The routing table. 659 -> Table ni nid -- ^ The routing table.
661 -> ( [(ni,(Timestamp, ni))], Table ni nid ) 660 -> ( [(ni,(Timestamp, ni))], Table ni nid )
662updateForPingResult testIdBit nodeId ni got_reply tbl = 661updateForPingResult space ni got_reply tbl =
663 fromMaybe ([],tbl) 662 fromMaybe ([],tbl)
664 $ modifyBucket testIdBit (\ni -> testIdBit $ nodeId ni) 663 $ modifyBucket (kademliaTestBit space)
665 (nodeId ni) 664 (\ni -> kademliaTestBit space $ kademliaLocation space ni)
666 (updateBucketForPingResult ni got_reply) 665 (kademliaLocation space ni)
667 tbl 666 (updateBucketForPingResult ni got_reply)
667 tbl
668 668
669 669
670{----------------------------------------------------------------------- 670{-----------------------------------------------------------------------
@@ -685,3 +685,17 @@ toBucketList (One b t) = b : toBucketList t
685toList :: Table ni nid -> [[TableEntry ni]] 685toList :: Table ni nid -> [[TableEntry ni]]
686toList = L.map (L.map tableEntry . PSQ.toList . bktNodes) . toBucketList 686toList = L.map (L.map tableEntry . PSQ.toList . bktNodes) . toBucketList
687 687
688data KademliaSpace nid ni = KademliaSpace
689 { -- | Given a node record (probably including IP address), yields a
690 -- kademlia xor-metric location.
691 kademliaLocation :: ni -> nid
692 -- | Used when comparing locations. This is similar to
693 -- 'Data.Bits.testBit' except that the ordering of bits is reversed, so
694 -- that 0 is the most significant bit.
695 , kademliaTestBit :: nid -> Word -> Bool
696 }
697
698contramapKS f ks = ks
699 { kademliaLocation = kademliaLocation ks . f
700 }
701