summaryrefslogtreecommitdiff
path: root/SybilLimit.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-08-10 20:31:57 -0400
committerjoe <joe@jerkface.net>2014-08-10 20:31:57 -0400
commitc1dc1da953d360e0a3182722591ef9acb069ab01 (patch)
treeb051c94451aed14969e6da1cacf6696b17819904 /SybilLimit.hs
parent251204cbf876106dcc67bd2c2ca9bd11450f63fe (diff)
made reactToMessage robust against unsolicited responses.
Diffstat (limited to 'SybilLimit.hs')
-rw-r--r--SybilLimit.hs24
1 files changed, 16 insertions, 8 deletions
diff --git a/SybilLimit.hs b/SybilLimit.hs
index 8d053f9..9befb31 100644
--- a/SybilLimit.hs
+++ b/SybilLimit.hs
@@ -161,16 +161,24 @@ reactToMessage w (srcId, msg@(RegistrationResponse {})) me =
161 where goodTail = Map.insert tail indexes 161 where goodTail = Map.insert tail indexes
162 $ sybVerifiedTails p 162 $ sybVerifiedTails p
163 indexes = fromMaybe [] $ Map.lookup tail $ sybPendingTails p 163 indexes = fromMaybe [] $ Map.lookup tail $ sybPendingTails p
164 icheck = pendingChecks me0 Map.! rrSuspect msg 164 (me',sybils) =
165 (me',sybils) = if Map.null (sybPendingTails icheck) then bcheck else (me0, []) 165 case Map.lookup (rrSuspect msg) $ pendingChecks me0 of
166 where bcheck = if Map.null (sybVerifiedTails icheck) 166 Nothing -> (me0,[])
167 Just icheck -> if Map.null (sybPendingTails icheck)
168 then bcheck icheck
169 else (me0, [])
170 where bcheck icheck
171 = if Map.null (sybVerifiedTails icheck)
167 then (me0, dishonest) 172 then (me0, dishonest)
168 else balanceCheck 173 else balanceCheck
169 dishonest = [SybilCheck (rrSuspect msg) False] 174 where
170 indexes = fromMaybe [] $ Map.lookup tail $ sybVerifiedTails icheck 175 dishonest = [SybilCheck (rrSuspect msg) False]
171 balanceCheck = second chk $ balanceCondition tail indexes me0 176 balanceCheck = second chk $ balanceCondition tail indexes me0
172 where chk = (:[]) . SybilCheck (rrSuspect msg) 177 where chk = (:[]) . SybilCheck (rrSuspect msg)
173 second f (x,y) = (x,f y) 178 second f (x,y) = (x,f y)
179 indexes = fromMaybe []
180 . Map.lookup tail
181 $ sybVerifiedTails icheck
174 182
175reactToMessage w (srcId, msg@(RegistrationQuery {})) me = 183reactToMessage w (srcId, msg@(RegistrationQuery {})) me =
176 MessageReaction me [(srcId,resp)] [] 184 MessageReaction me [(srcId,resp)] []