From 62fe171daf84ea2090501535652e1c4ac9cc6d41 Mon Sep 17 00:00:00 2001 From: Sam T Date: Wed, 17 Apr 2013 12:10:19 +0400 Subject: + Add connect to peer. --- src/Network/Torrent/PeerID.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/Network/Torrent') 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 @@ -- module Network.Torrent.PeerID ( -- ^ Peer addr - Peer(..), peerSockAddr + Peer(..) + , peerSockAddr, connectToPeer -- ^ Peer identification , PeerID (getPeerID) @@ -70,6 +71,14 @@ peerSockAddr = SockAddrInet <$> (g . peerPort) <*> (htonl . peerIP) g :: PortNumber -> PortNumber g (PortNum x) = PortNum x -- $ (x `shiftR` 8) .|. (x `shiftL` 8) +-- ipv6 extension +-- | Tries to connect to peer using reasonable default parameters. +-- +connectToPeer :: Peer -> IO Socket +connectToPeer p = do + sock <- socket AF_INET Stream Network.Socket.defaultProtocol + connect sock (peerSockAddr p) + return sock -- | Peer identifier is exactly 20 bytes long bytestring. -- cgit v1.2.3