summaryrefslogtreecommitdiff
path: root/src/Network/Torrent
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-17 12:10:19 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-17 12:10:19 +0400
commit62fe171daf84ea2090501535652e1c4ac9cc6d41 (patch)
treecd94b4470b1964e1cee93ecfd14f734e59a8f8c4 /src/Network/Torrent
parenta6041430c5bc3c57e3eddcfb3f44f90db679d0bf (diff)
+ Add connect to peer.
Diffstat (limited to 'src/Network/Torrent')
-rw-r--r--src/Network/Torrent/PeerID.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Network/Torrent/PeerID.hs b/src/Network/Torrent/PeerID.hs
index a3394b36..3f41b99a 100644
--- a/src/Network/Torrent/PeerID.hs
+++ b/src/Network/Torrent/PeerID.hs
@@ -5,7 +5,8 @@
5-- 5--
6module Network.Torrent.PeerID 6module Network.Torrent.PeerID
7 ( -- ^ Peer addr 7 ( -- ^ Peer addr
8 Peer(..), peerSockAddr 8 Peer(..)
9 , peerSockAddr, connectToPeer
9 10
10 -- ^ Peer identification 11 -- ^ Peer identification
11 , PeerID (getPeerID) 12 , PeerID (getPeerID)
@@ -70,6 +71,14 @@ peerSockAddr = SockAddrInet <$> (g . peerPort) <*> (htonl . peerIP)
70 g :: PortNumber -> PortNumber 71 g :: PortNumber -> PortNumber
71 g (PortNum x) = PortNum x -- $ (x `shiftR` 8) .|. (x `shiftL` 8) 72 g (PortNum x) = PortNum x -- $ (x `shiftR` 8) .|. (x `shiftL` 8)
72 73
74-- ipv6 extension
75-- | Tries to connect to peer using reasonable default parameters.
76--
77connectToPeer :: Peer -> IO Socket
78connectToPeer p = do
79 sock <- socket AF_INET Stream Network.Socket.defaultProtocol
80 connect sock (peerSockAddr p)
81 return sock
73 82
74 83
75-- | Peer identifier is exactly 20 bytes long bytestring. 84-- | Peer identifier is exactly 20 bytes long bytestring.