summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-07 04:52:17 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-07 04:52:17 +0400
commit7420a5738bf2c06f7da3fc8114242e76ffecfb43 (patch)
tree11da84e31b3161b44eddedb53672af0eb60d0d4d
parent7520e893fb5e4141be53ce35b80be73d1d43ae58 (diff)
Fix port number in DHT announce handler
-rw-r--r--src/Network/BitTorrent/DHT.hs14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs
index 6ce4c515..45cde70f 100644
--- a/src/Network/BitTorrent/DHT.hs
+++ b/src/Network/BitTorrent/DHT.hs
@@ -28,14 +28,12 @@ module Network.BitTorrent.DHT
28 ) where 28 ) where
29 29
30import Control.Applicative 30import Control.Applicative
31import Control.Concurrent.Lifted hiding (yield)
32import Control.Exception.Lifted 31import Control.Exception.Lifted
33import Control.Monad as M 32import Control.Monad as M
34import Control.Monad.Logger 33import Control.Monad.Logger
35import Control.Monad.Trans 34import Control.Monad.Trans
36import Data.Conduit as C 35import Data.Conduit as C
37import Data.Conduit.List as C 36import Data.Conduit.List as C
38import Data.List as L
39import Data.Monoid 37import Data.Monoid
40import Data.Text as T 38import Data.Text as T
41import Network.Socket (PortNumber) 39import Network.Socket (PortNumber)
@@ -47,7 +45,6 @@ import Network.BitTorrent.Core
47import Network.BitTorrent.DHT.Message 45import Network.BitTorrent.DHT.Message
48import Network.BitTorrent.DHT.Routing 46import Network.BitTorrent.DHT.Routing
49import Network.BitTorrent.DHT.Session 47import Network.BitTorrent.DHT.Session
50import Network.KRPC
51 48
52 49
53{----------------------------------------------------------------------- 50{-----------------------------------------------------------------------
@@ -67,13 +64,12 @@ getPeersH = nodeHandler $ \ naddr (GetPeers ih) -> do
67 GotPeers <$> getPeerList ih <*> grantToken naddr 64 GotPeers <$> getPeerList ih <*> grantToken naddr
68 65
69announceH :: Address ip => NodeHandler ip 66announceH :: Address ip => NodeHandler ip
70announceH = nodeHandler $ \ naddr (Announce {..}) -> do 67announceH = nodeHandler $ \ naddr @ NodeAddr {..} (Announce {..}) -> do
71 checkToken naddr sessionToken 68 checkToken naddr sessionToken
72 case fromAddr naddr of 69 let annPort = if impliedPort then nodePort else port
73 Nothing -> throw $ KError ProtocolError "bad address" "" 70 let peerAddr = PeerAddr Nothing nodeHost annPort
74 Just paddr -> do 71 insertPeer topic peerAddr
75 insertPeer topic paddr 72 return Announced
76 return Announced
77 73
78handlers :: Address ip => [NodeHandler ip] 74handlers :: Address ip => [NodeHandler ip]
79handlers = [pingH, findNodeH, getPeersH, announceH] 75handlers = [pingH, findNodeH, getPeersH, announceH]