diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-19 01:45:12 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-19 01:45:12 +0400 |
commit | 81b71a4a9f0a6f9fd64de08d2dd22303b169a076 (patch) | |
tree | 5e364431594649ab2376006f1174b2fddceffc3b /src | |
parent | 879074f286a602848d3edff10de36e88a9622cbc (diff) |
Return Bool instead of raising exception in checkToken
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent/DHT/Query.hs | 5 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs index dcb217d6..07fb80c2 100644 --- a/src/Network/BitTorrent/DHT/Query.hs +++ b/src/Network/BitTorrent/DHT/Query.hs | |||
@@ -71,7 +71,10 @@ getPeersH = nodeHandler $ \ naddr (GetPeers ih) -> do | |||
71 | 71 | ||
72 | announceH :: Address ip => NodeHandler ip | 72 | announceH :: Address ip => NodeHandler ip |
73 | announceH = nodeHandler $ \ naddr @ NodeAddr {..} (Announce {..}) -> do | 73 | announceH = nodeHandler $ \ naddr @ NodeAddr {..} (Announce {..}) -> do |
74 | checkToken naddr sessionToken | 74 | valid <- checkToken naddr sessionToken |
75 | unless valid $ do | ||
76 | throwIO $ InvalidParameter "token" | ||
77 | |||
75 | let annPort = if impliedPort then nodePort else port | 78 | let annPort = if impliedPort then nodePort else port |
76 | let peerAddr = PeerAddr Nothing nodeHost annPort | 79 | let peerAddr = PeerAddr Nothing nodeHost annPort |
77 | insertPeer topic peerAddr | 80 | insertPeer topic peerAddr |
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index 6f13cf78..10f3e9e4 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -349,12 +349,11 @@ grantToken addr = do | |||
349 | 349 | ||
350 | -- | Throws 'HandlerError' if the token is invalid or already | 350 | -- | Throws 'HandlerError' if the token is invalid or already |
351 | -- expired. See 'TokenMap' for details. | 351 | -- expired. See 'TokenMap' for details. |
352 | checkToken :: Hashable a => NodeAddr a -> Token -> DHT ip () | 352 | checkToken :: Hashable a => NodeAddr a -> Token -> DHT ip Bool |
353 | checkToken addr questionableToken = do | 353 | checkToken addr questionableToken = do |
354 | tryUpdateSecret | 354 | tryUpdateSecret |
355 | toks <- asks sessionTokens >>= liftIO . readTVarIO | 355 | toks <- asks sessionTokens >>= liftIO . readTVarIO |
356 | unless (T.member addr questionableToken (tokenMap toks)) $ | 356 | return $ T.member addr questionableToken (tokenMap toks) |
357 | throwIO $ InvalidParameter "token" | ||
358 | 357 | ||
359 | {----------------------------------------------------------------------- | 358 | {----------------------------------------------------------------------- |
360 | -- Routing table | 359 | -- Routing table |