diff options
author | joe <joe@jerkface.net> | 2017-01-23 23:11:40 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-01-23 23:11:40 -0500 |
commit | 2ced7fa5b110d19f0e6cc21968822f4ccf880c13 (patch) | |
tree | 9c6b15986b4599ff5e29253cfd848ac1cdb357e3 /src/Network | |
parent | 058ccb22f43e9053fa37ed719d31c72dd6dac27c (diff) |
Fixed table inadvertent "retry" in table insertion.
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/DHT/Routing.hs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/DHT/Routing.hs b/src/Network/BitTorrent/DHT/Routing.hs index 8a6849a1..d64e415e 100644 --- a/src/Network/BitTorrent/DHT/Routing.hs +++ b/src/Network/BitTorrent/DHT/Routing.hs | |||
@@ -529,11 +529,11 @@ splitTip nid n i bucket | |||
529 | -- k nodes in them. Which subtrees I mean is illustrated in Fig 1. of Kademlia | 529 | -- k nodes in them. Which subtrees I mean is illustrated in Fig 1. of Kademlia |
530 | -- paper. The rule requiring additional splits is in section 2.4. | 530 | -- paper. The rule requiring additional splits is in section 2.4. |
531 | modifyBucket | 531 | modifyBucket |
532 | :: forall f ip xs. (Alternative f, Eq ip) => | 532 | :: forall ip xs. (Eq ip) => |
533 | NodeId -> (Bucket ip -> f (xs, Bucket ip)) -> Table ip -> f (xs,Table ip) | 533 | NodeId -> (Bucket ip -> Maybe (xs, Bucket ip)) -> Table ip -> Maybe (xs,Table ip) |
534 | modifyBucket nodeId f = go (0 :: BitIx) | 534 | modifyBucket nodeId f = go (0 :: BitIx) |
535 | where | 535 | where |
536 | go :: BitIx -> Table ip -> f (xs, Table ip) | 536 | go :: BitIx -> Table ip -> Maybe (xs, Table ip) |
537 | go i (Zero table bucket) | 537 | go i (Zero table bucket) |
538 | | testIdBit nodeId i = second (Zero table) <$> f bucket | 538 | | testIdBit nodeId i = second (Zero table) <$> f bucket |
539 | | otherwise = second (`Zero` bucket) <$> go (succ i) table | 539 | | otherwise = second (`Zero` bucket) <$> go (succ i) table |
@@ -562,8 +562,8 @@ data CheckPing ip = CheckPing [NodeInfo ip] | |||
562 | 562 | ||
563 | 563 | ||
564 | -- | Atomic 'Table' update | 564 | -- | Atomic 'Table' update |
565 | insert :: (Alternative m, Eq ip) => Timestamp -> Event ip -> Table ip -> m ([CheckPing ip], Table ip) | 565 | insert :: (Eq ip, Applicative m) => Timestamp -> Event ip -> Table ip -> m ([CheckPing ip], Table ip) |
566 | insert tm event = modifyBucket (eventId event) (insertBucket tm event) | 566 | insert tm event tbl = pure $ fromMaybe ([],tbl) $ modifyBucket (eventId event) (insertBucket tm event) tbl |
567 | 567 | ||
568 | 568 | ||
569 | {----------------------------------------------------------------------- | 569 | {----------------------------------------------------------------------- |