summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Core/PeerAddr.hs17
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs7
2 files changed, 11 insertions, 13 deletions
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs
index 5570bfc1..b145c0d9 100644
--- a/src/Network/BitTorrent/Core/PeerAddr.hs
+++ b/src/Network/BitTorrent/Core/PeerAddr.hs
@@ -19,7 +19,6 @@ module Network.BitTorrent.Core.PeerAddr
19 , defaultPorts 19 , defaultPorts
20 , peerSockAddr 20 , peerSockAddr
21 , connectToPeer 21 , connectToPeer
22 , ppPeer
23 ) where 22 ) where
24 23
25import Control.Applicative 24import Control.Applicative
@@ -34,6 +33,7 @@ import Data.Typeable
34import Data.Word 33import Data.Word
35import Network.Socket 34import Network.Socket
36import Text.PrettyPrint 35import Text.PrettyPrint
36import Text.PrettyPrint.Class
37 37
38import Data.Torrent.Client 38import Data.Torrent.Client
39import Network.BitTorrent.Core.PeerId 39import Network.BitTorrent.Core.PeerId
@@ -89,6 +89,13 @@ instance Serialize PeerAddr where
89 get = PeerAddr Nothing <$> get <*> get 89 get = PeerAddr Nothing <$> get <*> get
90 {-# INLINE get #-} 90 {-# INLINE get #-}
91 91
92instance Pretty PeerAddr where
93 pretty p @ PeerAddr {..}
94 | Just pid <- peerID = pretty (clientInfo pid) <+> "at" <+> paddr
95 | otherwise = paddr
96 where
97 paddr = text (show (peerSockAddr p))
98
92-- | Ports typically reserved for bittorrent P2P listener. 99-- | Ports typically reserved for bittorrent P2P listener.
93defaultPorts :: [PortNumber] 100defaultPorts :: [PortNumber]
94defaultPorts = [6881..6889] 101defaultPorts = [6881..6889]
@@ -117,11 +124,3 @@ connectToPeer p = do
117 sock <- socket AF_INET Stream Network.Socket.defaultProtocol 124 sock <- socket AF_INET Stream Network.Socket.defaultProtocol
118 connect sock (peerSockAddr p) 125 connect sock (peerSockAddr p)
119 return sock 126 return sock
120
121-- | Pretty print peer address in human readable form.
122ppPeer :: PeerAddr -> Doc
123ppPeer p @ PeerAddr {..}
124 | Just pid <- peerID = ppClientInfo (clientInfo pid) <+> "at" <+> paddr
125 | otherwise = paddr
126 where
127 paddr = text (show (peerSockAddr p))
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs
index a212df3d..6aebe8d4 100644
--- a/src/Network/BitTorrent/Core/PeerId.hs
+++ b/src/Network/BitTorrent/Core/PeerId.hs
@@ -16,7 +16,6 @@
16module Network.BitTorrent.Core.PeerId 16module Network.BitTorrent.Core.PeerId
17 ( -- * PeerId 17 ( -- * PeerId
18 PeerId (getPeerId) 18 PeerId (getPeerId)
19 , ppPeerId
20 19
21 -- * Generation 20 -- * Generation
22 , genPeerId 21 , genPeerId
@@ -57,6 +56,7 @@ import Data.Version (Version(Version), versionBranch)
57import System.Entropy (getEntropy) 56import System.Entropy (getEntropy)
58import System.Locale (defaultTimeLocale) 57import System.Locale (defaultTimeLocale)
59import Text.PrettyPrint hiding ((<>)) 58import Text.PrettyPrint hiding ((<>))
59import Text.PrettyPrint.Class
60import Text.Read (readMaybe) 60import Text.Read (readMaybe)
61import Paths_bittorrent (version) 61import Paths_bittorrent (version)
62 62
@@ -83,9 +83,8 @@ instance IsString PeerId where
83 where 83 where
84 bs = fromString str 84 bs = fromString str
85 85
86-- | Format peer id in human readable form. 86instance Pretty PeerId where
87ppPeerId :: PeerId -> Doc 87 pretty = text . BC.unpack . getPeerId
88ppPeerId = text . BC.unpack . getPeerId
89 88
90{----------------------------------------------------------------------- 89{-----------------------------------------------------------------------
91-- Encoding 90-- Encoding