diff options
-rw-r--r-- | dht-client.cabal | 13 | ||||
-rw-r--r-- | src/Data/Torrent.hs | 22 | ||||
-rw-r--r-- | src/Network/Address.hs | 34 | ||||
-rw-r--r-- | src/Network/Tox/Crypto/Transport.hs | 33 | ||||
-rw-r--r-- | src/Network/Tox/Handshake.hs | 2 |
5 files changed, 89 insertions, 15 deletions
diff --git a/dht-client.cabal b/dht-client.cabal index 796844a1..e668dccc 100644 --- a/dht-client.cabal +++ b/dht-client.cabal | |||
@@ -108,6 +108,11 @@ library | |||
108 | Network.Tox.NodeId | 108 | Network.Tox.NodeId |
109 | Network.Tox.Avahi | 109 | Network.Tox.Avahi |
110 | Network.UPNP | 110 | Network.UPNP |
111 | Network.QueryResponse.TCP | ||
112 | Network.Tox.Relay | ||
113 | Network.Tox.TCP | ||
114 | Data.Tox.Msg | ||
115 | Data.Tox.Relay | ||
111 | Control.TriadCommittee | 116 | Control.TriadCommittee |
112 | Crypto.Tox | 117 | Crypto.Tox |
113 | Text.XXD | 118 | Text.XXD |
@@ -148,6 +153,7 @@ library | |||
148 | Presence | 153 | Presence |
149 | PingMachine | 154 | PingMachine |
150 | Connection | 155 | Connection |
156 | ToxChat | ||
151 | ToxToXMPP | 157 | ToxToXMPP |
152 | ToxManager | 158 | ToxManager |
153 | XMPPToTox | 159 | XMPPToTox |
@@ -183,6 +189,7 @@ library | |||
183 | , bencoding | 189 | , bencoding |
184 | , contravariant | 190 | , contravariant |
185 | , xml-types | 191 | , xml-types |
192 | , rank2classes | ||
186 | 193 | ||
187 | , memory | 194 | , memory |
188 | , time | 195 | , time |
@@ -194,14 +201,10 @@ library | |||
194 | , http-types | 201 | , http-types |
195 | 202 | ||
196 | , process | 203 | , process |
197 | , split | ||
198 | , pretty | 204 | , pretty |
199 | , convertible | 205 | , convertible |
200 | , data-default | 206 | , data-default |
201 | 207 | ||
202 | , bifunctors | ||
203 | , lens | ||
204 | , lifted-async | ||
205 | , lifted-base | 208 | , lifted-base |
206 | , monad-control | 209 | , monad-control |
207 | , transformers-base | 210 | , transformers-base |
@@ -218,7 +221,6 @@ library | |||
218 | , blaze-builder | 221 | , blaze-builder |
219 | , exceptions | 222 | , exceptions |
220 | , hinotify | 223 | , hinotify |
221 | , reference | ||
222 | , avahi >= 0.2.0 | 224 | , avahi >= 0.2.0 |
223 | , hslogger | 225 | , hslogger |
224 | 226 | ||
@@ -241,7 +243,6 @@ library | |||
241 | cpp-options: -DBENCODE_AESON -DRENDERFLUSH | 243 | cpp-options: -DBENCODE_AESON -DRENDERFLUSH |
242 | if flag(thread-debug) | 244 | if flag(thread-debug) |
243 | exposed-modules: Control.Concurrent.Lifted.Instrument | 245 | exposed-modules: Control.Concurrent.Lifted.Instrument |
244 | Control.Concurrent.Async.Lifted.Instrument | ||
245 | cpp-options: -DTHREAD_DEBUG | 246 | cpp-options: -DTHREAD_DEBUG |
246 | 247 | ||
247 | if flag(builder) | 248 | if flag(builder) |
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index a746b54c..69461488 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -42,15 +42,19 @@ module Data.Torrent | |||
42 | , FileOffset | 42 | , FileOffset |
43 | , FileSize | 43 | , FileSize |
44 | , FileInfo (..) | 44 | , FileInfo (..) |
45 | #ifdef VERSION_lens | ||
45 | , fileLength | 46 | , fileLength |
46 | , filePath | 47 | , filePath |
47 | , fileMD5Sum | 48 | , fileMD5Sum |
49 | #endif | ||
48 | 50 | ||
49 | -- ** Layout info | 51 | -- ** Layout info |
50 | , LayoutInfo (..) | 52 | , LayoutInfo (..) |
53 | #ifdef VERSION_lens | ||
51 | , singleFile | 54 | , singleFile |
52 | , multiFile | 55 | , multiFile |
53 | , rootDirName | 56 | , rootDirName |
57 | #endif | ||
54 | , joinFilePath | 58 | , joinFilePath |
55 | , isSingleFile | 59 | , isSingleFile |
56 | , isMultiFile | 60 | , isMultiFile |
@@ -86,8 +90,10 @@ module Data.Torrent | |||
86 | -- ** Piece control | 90 | -- ** Piece control |
87 | , HashList (..) | 91 | , HashList (..) |
88 | , PieceInfo (..) | 92 | , PieceInfo (..) |
93 | #ifdef VERSION_lens | ||
89 | , pieceLength | 94 | , pieceLength |
90 | , pieceHashes | 95 | , pieceHashes |
96 | #endif | ||
91 | , pieceCount | 97 | , pieceCount |
92 | 98 | ||
93 | -- ** Validation | 99 | -- ** Validation |
@@ -96,10 +102,12 @@ module Data.Torrent | |||
96 | 102 | ||
97 | -- * Info dictionary | 103 | -- * Info dictionary |
98 | , InfoDict (..) | 104 | , InfoDict (..) |
105 | #ifdef VERSION_lens | ||
99 | , infohash | 106 | , infohash |
100 | , layoutInfo | 107 | , layoutInfo |
101 | , pieceInfo | 108 | , pieceInfo |
102 | , isPrivate | 109 | , isPrivate |
110 | #endif | ||
103 | #ifdef VERSION_bencoding | 111 | #ifdef VERSION_bencoding |
104 | , infoDictionary | 112 | , infoDictionary |
105 | #endif | 113 | #endif |
@@ -107,6 +115,7 @@ module Data.Torrent | |||
107 | -- * Torrent file | 115 | -- * Torrent file |
108 | , Torrent(..) | 116 | , Torrent(..) |
109 | 117 | ||
118 | #ifdef VERSION_lens | ||
110 | -- ** Lenses | 119 | -- ** Lenses |
111 | , announce | 120 | , announce |
112 | , announceList | 121 | , announceList |
@@ -118,6 +127,7 @@ module Data.Torrent | |||
118 | , publisher | 127 | , publisher |
119 | , publisherURL | 128 | , publisherURL |
120 | , signature | 129 | , signature |
130 | #endif | ||
121 | 131 | ||
122 | -- ** Utils | 132 | -- ** Utils |
123 | , nullTorrent | 133 | , nullTorrent |
@@ -151,7 +161,7 @@ import Prelude hiding ((<>)) | |||
151 | import Control.Applicative | 161 | import Control.Applicative |
152 | import Control.DeepSeq | 162 | import Control.DeepSeq |
153 | import Control.Exception | 163 | import Control.Exception |
154 | import Control.Lens | 164 | -- import Control.Lens |
155 | import Control.Monad | 165 | import Control.Monad |
156 | import Crypto.Hash | 166 | import Crypto.Hash |
157 | #ifdef VERSION_bencoding | 167 | #ifdef VERSION_bencoding |
@@ -368,12 +378,14 @@ data FileInfo a = FileInfo { | |||
368 | , Functor, Foldable | 378 | , Functor, Foldable |
369 | ) | 379 | ) |
370 | 380 | ||
381 | #ifdef VERSION_lens | ||
371 | makeLensesFor | 382 | makeLensesFor |
372 | [ ("fiLength", "fileLength") | 383 | [ ("fiLength", "fileLength") |
373 | , ("fiMD5Sum", "fileMD5Sum") | 384 | , ("fiMD5Sum", "fileMD5Sum") |
374 | , ("fiName" , "filePath" ) | 385 | , ("fiName" , "filePath" ) |
375 | ] | 386 | ] |
376 | ''FileInfo | 387 | ''FileInfo |
388 | #endif | ||
377 | 389 | ||
378 | instance NFData a => NFData (FileInfo a) where | 390 | instance NFData a => NFData (FileInfo a) where |
379 | rnf FileInfo {..} = rnf fiName | 391 | rnf FileInfo {..} = rnf fiName |
@@ -455,12 +467,14 @@ data LayoutInfo | |||
455 | , liDirName :: !BS.ByteString | 467 | , liDirName :: !BS.ByteString |
456 | } deriving (Show, Read, Eq, Typeable) | 468 | } deriving (Show, Read, Eq, Typeable) |
457 | 469 | ||
470 | #ifdef VERSION_lens | ||
458 | makeLensesFor | 471 | makeLensesFor |
459 | [ ("liFile" , "singleFile" ) | 472 | [ ("liFile" , "singleFile" ) |
460 | , ("liFiles" , "multiFile" ) | 473 | , ("liFiles" , "multiFile" ) |
461 | , ("liDirName", "rootDirName") | 474 | , ("liDirName", "rootDirName") |
462 | ] | 475 | ] |
463 | ''LayoutInfo | 476 | ''LayoutInfo |
477 | #endif | ||
464 | 478 | ||
465 | instance NFData LayoutInfo where | 479 | instance NFData LayoutInfo where |
466 | rnf SingleFile {..} = () | 480 | rnf SingleFile {..} = () |
@@ -681,11 +695,13 @@ data PieceInfo = PieceInfo | |||
681 | -- ^ Concatenation of all 20-byte SHA1 hash values. | 695 | -- ^ Concatenation of all 20-byte SHA1 hash values. |
682 | } deriving (Show, Read, Eq, Typeable) | 696 | } deriving (Show, Read, Eq, Typeable) |
683 | 697 | ||
698 | #ifdef VERSION_lens | ||
684 | -- | Number of bytes in each piece. | 699 | -- | Number of bytes in each piece. |
685 | makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo | 700 | makeLensesFor [("piPieceLength", "pieceLength")] ''PieceInfo |
686 | 701 | ||
687 | -- | Concatenation of all 20-byte SHA1 hash values. | 702 | -- | Concatenation of all 20-byte SHA1 hash values. |
688 | makeLensesFor [("piPieceHashes", "pieceHashes")] ''PieceInfo | 703 | makeLensesFor [("piPieceHashes", "pieceHashes")] ''PieceInfo |
704 | #endif | ||
689 | 705 | ||
690 | instance NFData PieceInfo where | 706 | instance NFData PieceInfo where |
691 | rnf (PieceInfo a (HashList b)) = rnf a `seq` rnf b | 707 | rnf (PieceInfo a (HashList b)) = rnf a `seq` rnf b |
@@ -766,6 +782,7 @@ data InfoDict = InfoDict | |||
766 | -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html> | 782 | -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html> |
767 | } deriving (Show, Read, Eq, Typeable) | 783 | } deriving (Show, Read, Eq, Typeable) |
768 | 784 | ||
785 | #ifdef VERISON_lens | ||
769 | makeLensesFor | 786 | makeLensesFor |
770 | [ ("idInfoHash" , "infohash" ) | 787 | [ ("idInfoHash" , "infohash" ) |
771 | , ("idLayoutInfo", "layoutInfo") | 788 | , ("idLayoutInfo", "layoutInfo") |
@@ -773,6 +790,7 @@ makeLensesFor | |||
773 | , ("idPrivate" , "isPrivate" ) | 790 | , ("idPrivate" , "isPrivate" ) |
774 | ] | 791 | ] |
775 | ''InfoDict | 792 | ''InfoDict |
793 | #endif | ||
776 | 794 | ||
777 | instance NFData InfoDict where | 795 | instance NFData InfoDict where |
778 | rnf InfoDict {..} = rnf idLayoutInfo | 796 | rnf InfoDict {..} = rnf idLayoutInfo |
@@ -884,6 +902,7 @@ data Torrent = Torrent | |||
884 | -- encrypted SHA-1 hash of the info dictionary). | 902 | -- encrypted SHA-1 hash of the info dictionary). |
885 | } deriving (Show, Eq, Typeable) | 903 | } deriving (Show, Eq, Typeable) |
886 | 904 | ||
905 | #ifdef VERSION_lens | ||
887 | makeLensesFor | 906 | makeLensesFor |
888 | [ ("tAnnounce" , "announce" ) | 907 | [ ("tAnnounce" , "announce" ) |
889 | , ("tAnnounceList", "announceList") | 908 | , ("tAnnounceList", "announceList") |
@@ -897,6 +916,7 @@ makeLensesFor | |||
897 | , ("tSignature" , "signature" ) | 916 | , ("tSignature" , "signature" ) |
898 | ] | 917 | ] |
899 | ''Torrent | 918 | ''Torrent |
919 | #endif | ||
900 | 920 | ||
901 | instance NFData Torrent where | 921 | instance NFData Torrent where |
902 | rnf Torrent {..} = rnf tInfoDict | 922 | rnf Torrent {..} = rnf tInfoDict |
diff --git a/src/Network/Address.hs b/src/Network/Address.hs index 246463c0..e1cec34d 100644 --- a/src/Network/Address.hs +++ b/src/Network/Address.hs | |||
@@ -84,6 +84,9 @@ module Network.Address | |||
84 | , sockAddrPort | 84 | , sockAddrPort |
85 | , setPort | 85 | , setPort |
86 | , getBindAddress | 86 | , getBindAddress |
87 | , localhost4 | ||
88 | , localhost6 | ||
89 | , linesBy | ||
87 | ) where | 90 | ) where |
88 | 91 | ||
89 | import Control.Applicative | 92 | import Control.Applicative |
@@ -109,7 +112,6 @@ import Data.IP hiding (fromSockAddr) | |||
109 | import Data.IP | 112 | import Data.IP |
110 | #endif | 113 | #endif |
111 | import Data.List as L | 114 | import Data.List as L |
112 | import Data.List.Split as L | ||
113 | import Data.Maybe (fromMaybe, catMaybes) | 115 | import Data.Maybe (fromMaybe, catMaybes) |
114 | import Data.Monoid | 116 | import Data.Monoid |
115 | import Data.Hashable | 117 | import Data.Hashable |
@@ -212,7 +214,8 @@ instance Serialize a => Serialize (NodeAddr a) where | |||
212 | -- | 214 | -- |
213 | instance IsString (NodeAddr IPv4) where | 215 | instance IsString (NodeAddr IPv4) where |
214 | fromString str | 216 | fromString str |
215 | | [hostAddrStr, portStr] <- splitWhen (== ':') str | 217 | | (hostAddrStr, portStr0) <- L.break (== ':') str |
218 | , let portStr = L.drop 1 portStr0 | ||
216 | , Just hostAddr <- readMaybe hostAddrStr | 219 | , Just hostAddr <- readMaybe hostAddrStr |
217 | , Just portNum <- toEnum <$> readMaybe portStr | 220 | , Just portNum <- toEnum <$> readMaybe portStr |
218 | = NodeAddr hostAddr portNum | 221 | = NodeAddr hostAddr portNum |
@@ -540,7 +543,8 @@ instance Default PeerAddr where | |||
540 | -- | 543 | -- |
541 | instance IsString PeerAddr where | 544 | instance IsString PeerAddr where |
542 | fromString str | 545 | fromString str |
543 | | [hostAddrStr, portStr] <- splitWhen (== ':') str | 546 | | (hostAddrStr, portStr0) <- L.break (== ':') str |
547 | , let portStr = L.drop 1 portStr0 | ||
544 | , Just hostAddr <- readMaybe hostAddrStr | 548 | , Just hostAddr <- readMaybe hostAddrStr |
545 | , Just portNum <- toEnum <$> readMaybe portStr | 549 | , Just portNum <- toEnum <$> readMaybe portStr |
546 | = PeerAddr Nothing (IPv4 hostAddr) portNum | 550 | = PeerAddr Nothing (IPv4 hostAddr) portNum |
@@ -958,6 +962,20 @@ instance Default Version where | |||
958 | def = Version [0] [] | 962 | def = Version [0] [] |
959 | {-# INLINE def #-} | 963 | {-# INLINE def #-} |
960 | 964 | ||
965 | dropLastIf :: (a -> Bool) -> [a] -> [a] | ||
966 | dropLastIf pred [] = [] | ||
967 | dropLastIf pred (x:xs) = init' x xs | ||
968 | where init' y [] | pred y = [] | ||
969 | init' y [] = [y] | ||
970 | init' y (z:zs) = y : init' z zs | ||
971 | |||
972 | linesBy :: (a -> Bool) -> [a] -> [[a]] | ||
973 | linesBy pred ys = dropLastIf L.null $ L.map dropDelim $ L.groupBy (\_ x -> not $ pred x) ys | ||
974 | where | ||
975 | dropDelim [] = [] | ||
976 | dropDelim (x:xs) | pred x = xs | ||
977 | | otherwise = x:xs | ||
978 | |||
961 | -- | For dot delimited version strings. | 979 | -- | For dot delimited version strings. |
962 | -- Example: @fromString \"0.1.0.2\" == Version [0, 1, 0, 2]@ | 980 | -- Example: @fromString \"0.1.0.2\" == Version [0, 1, 0, 2]@ |
963 | -- | 981 | -- |
@@ -966,7 +984,7 @@ instance IsString Version where | |||
966 | | Just nums <- chunkNums str = Version nums [] | 984 | | Just nums <- chunkNums str = Version nums [] |
967 | | otherwise = error $ "fromString: invalid version string " ++ str | 985 | | otherwise = error $ "fromString: invalid version string " ++ str |
968 | where | 986 | where |
969 | chunkNums = sequence . L.map readMaybe . L.linesBy ('.' ==) | 987 | chunkNums = sequence . L.map readMaybe . linesBy ('.' ==) |
970 | 988 | ||
971 | instance Pretty Version where | 989 | instance Pretty Version where |
972 | pPrint = text . showVersion | 990 | pPrint = text . showVersion |
@@ -1120,7 +1138,7 @@ fingerprint pid = either (const def) id $ runGet getCI (getPeerId pid) | |||
1120 | 1138 | ||
1121 | getMainlineVersion = do | 1139 | getMainlineVersion = do |
1122 | str <- BC.unpack <$> getByteString 7 | 1140 | str <- BC.unpack <$> getByteString 7 |
1123 | let mnums = L.filter (not . L.null) $ L.linesBy ('-' ==) str | 1141 | let mnums = L.filter (not . L.null) $ linesBy ('-' ==) str |
1124 | return $ Version (fromMaybe [] $ sequence $ L.map readMaybe mnums) [] | 1142 | return $ Version (fromMaybe [] $ sequence $ L.map readMaybe mnums) [] |
1125 | 1143 | ||
1126 | getAzureusImpl = parseSoftware <$> getByteString 2 | 1144 | getAzureusImpl = parseSoftware <$> getByteString 2 |
@@ -1227,3 +1245,9 @@ either4or6 a6@(SockAddrInet6 port _ addr _) | |||
1227 | data WantIP = Want_IP4 | Want_IP6 | Want_Both | 1245 | data WantIP = Want_IP4 | Want_IP6 | Want_Both |
1228 | deriving (Eq, Enum, Ord, Show) | 1246 | deriving (Eq, Enum, Ord, Show) |
1229 | 1247 | ||
1248 | localhost6 :: SockAddr | ||
1249 | localhost6 = SockAddrInet6 0 0 (0,0,0,1) 0 -- [::1]:0 | ||
1250 | |||
1251 | localhost4 :: SockAddr | ||
1252 | localhost4 = SockAddrInet 0 16777343 -- 127.0.0.1:0 | ||
1253 | |||
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs index 6e2ab60b..2c13e168 100644 --- a/src/Network/Tox/Crypto/Transport.hs +++ b/src/Network/Tox/Crypto/Transport.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | {-# LANGUAGE DataKinds #-} | 2 | {-# LANGUAGE DataKinds #-} |
2 | {-# LANGUAGE FlexibleInstances #-} | 3 | {-# LANGUAGE FlexibleInstances #-} |
3 | {-# LANGUAGE GADTs #-} | 4 | {-# LANGUAGE GADTs #-} |
@@ -43,8 +44,10 @@ module Network.Tox.Crypto.Transport | |||
43 | , HasMessage(..) | 44 | , HasMessage(..) |
44 | , HasMessageType(..) | 45 | , HasMessageType(..) |
45 | -- lenses | 46 | -- lenses |
47 | #ifdef VERSION_lens | ||
46 | , groupNumber, groupNumberToJoin, peerNumber, messageNumber | 48 | , groupNumber, groupNumberToJoin, peerNumber, messageNumber |
47 | , messageName, messageData, name, title, message, messageType | 49 | , messageName, messageData, name, title, message, messageType |
50 | #endif | ||
48 | -- constructor | 51 | -- constructor |
49 | -- utils | 52 | -- utils |
50 | , sizedN | 53 | , sizedN |
@@ -77,7 +80,8 @@ import Data.Monoid | |||
77 | import Data.Word | 80 | import Data.Word |
78 | import Data.Bits | 81 | import Data.Bits |
79 | import Crypto.Hash | 82 | import Crypto.Hash |
80 | import Control.Lens | 83 | import Data.Functor.Contravariant |
84 | import Data.Functor.Identity | ||
81 | import Data.Text as T | 85 | import Data.Text as T |
82 | import Data.Text.Encoding as T | 86 | import Data.Text.Encoding as T |
83 | import Data.Serialize as S | 87 | import Data.Serialize as S |
@@ -284,8 +288,10 @@ putCryptoMessage seqno (Pkt t :=> Identity x) = do | |||
284 | putPacket seqno x | 288 | putPacket seqno x |
285 | 289 | ||
286 | 290 | ||
291 | #ifdef VERSION_lens | ||
287 | erCompat :: String -> a | 292 | erCompat :: String -> a |
288 | erCompat lens = error $ "Use of '" ++ lens ++ "' lens on incompatible CryptoMessage type" | 293 | erCompat lens = error $ "Use of '" ++ lens ++ "' lens on incompatible CryptoMessage type" |
294 | #endif | ||
289 | 295 | ||
290 | 296 | ||
291 | newtype GroupChatId = GrpId ByteString -- 33 bytes | 297 | newtype GroupChatId = GrpId ByteString -- 33 bytes |
@@ -330,8 +336,10 @@ instance HasGroupChatID CryptoMessage where | |||
330 | setGroupChatID _ _= error "setGroupChatID on non-groupchat message." | 336 | setGroupChatID _ _= error "setGroupChatID on non-groupchat message." |
331 | -} | 337 | -} |
332 | 338 | ||
339 | #ifdef VERSION_lens | ||
333 | groupChatID :: (Functor f, HasGroupChatID x) => (GroupChatId -> f GroupChatId) -> (x -> f x) | 340 | groupChatID :: (Functor f, HasGroupChatID x) => (GroupChatId -> f GroupChatId) -> (x -> f x) |
334 | groupChatID = lens getGroupChatID setGroupChatID | 341 | groupChatID = lens getGroupChatID setGroupChatID |
342 | #endif | ||
335 | 343 | ||
336 | type GroupNumber = Word16 | 344 | type GroupNumber = Word16 |
337 | type PeerNumber = Word16 | 345 | type PeerNumber = Word16 |
@@ -362,8 +370,10 @@ instance HasGroupNumber CryptoMessage where | |||
362 | setGroupNumber _ _ = error "setGroupNumber on CryptoMessage without group number field." | 370 | setGroupNumber _ _ = error "setGroupNumber on CryptoMessage without group number field." |
363 | -} | 371 | -} |
364 | 372 | ||
373 | #ifdef VERSION_lens | ||
365 | groupNumber :: (Functor f, HasGroupNumber x) => (Word16 -> f Word16) -> (x -> f x) | 374 | groupNumber :: (Functor f, HasGroupNumber x) => (Word16 -> f Word16) -> (x -> f x) |
366 | groupNumber = lens getGroupNumber setGroupNumber | 375 | groupNumber = lens getGroupNumber setGroupNumber |
376 | #endif | ||
367 | 377 | ||
368 | class HasGroupNumberToJoin x where | 378 | class HasGroupNumberToJoin x where |
369 | getGroupNumberToJoin :: x -> GroupNumber | 379 | getGroupNumberToJoin :: x -> GroupNumber |
@@ -384,8 +394,10 @@ instance HasGroupNumberToJoin CryptoMessage where | |||
384 | setGroupNumberToJoin _ _ = error "setGroupNumberToJoin on CryptoMessage without group number (to join) field." | 394 | setGroupNumberToJoin _ _ = error "setGroupNumberToJoin on CryptoMessage without group number (to join) field." |
385 | -} | 395 | -} |
386 | 396 | ||
397 | #ifdef VERSION_lens | ||
387 | groupNumberToJoin :: (Functor f, HasGroupNumberToJoin x) => (GroupNumber -> f GroupNumber) -> (x -> f x) | 398 | groupNumberToJoin :: (Functor f, HasGroupNumberToJoin x) => (GroupNumber -> f GroupNumber) -> (x -> f x) |
388 | groupNumberToJoin = lens getGroupNumberToJoin setGroupNumberToJoin | 399 | groupNumberToJoin = lens getGroupNumberToJoin setGroupNumberToJoin |
400 | #endif | ||
389 | 401 | ||
390 | class HasPeerNumber x where | 402 | class HasPeerNumber x where |
391 | getPeerNumber :: x -> PeerNumber | 403 | getPeerNumber :: x -> PeerNumber |
@@ -406,8 +418,10 @@ instance HasPeerNumber CryptoMessage where | |||
406 | setPeerNumber _ _ = error "setPeerNumber on CryptoMessage without peer number field." | 418 | setPeerNumber _ _ = error "setPeerNumber on CryptoMessage without peer number field." |
407 | -} | 419 | -} |
408 | 420 | ||
421 | #ifdef VERSION_lens | ||
409 | peerNumber :: (Functor f, HasPeerNumber x) => (Word16 -> f Word16) -> (x -> f x) | 422 | peerNumber :: (Functor f, HasPeerNumber x) => (Word16 -> f Word16) -> (x -> f x) |
410 | peerNumber = lens getPeerNumber setPeerNumber | 423 | peerNumber = lens getPeerNumber setPeerNumber |
424 | #endif | ||
411 | 425 | ||
412 | class HasMessageNumber x where | 426 | class HasMessageNumber x where |
413 | getMessageNumber :: x -> MessageNumber | 427 | getMessageNumber :: x -> MessageNumber |
@@ -428,9 +442,10 @@ instance HasMessageNumber CryptoMessage where | |||
428 | setMessageNumber _ _ = error "setMessageNumber on CryptoMessage without message number field." | 442 | setMessageNumber _ _ = error "setMessageNumber on CryptoMessage without message number field." |
429 | -} | 443 | -} |
430 | 444 | ||
445 | #ifdef VERSION_lens | ||
431 | messageNumber :: (Functor f, HasMessageNumber x) => (Word32 -> f Word32) -> (x -> f x) | 446 | messageNumber :: (Functor f, HasMessageNumber x) => (Word32 -> f Word32) -> (x -> f x) |
432 | messageNumber = lens getMessageNumber setMessageNumber | 447 | messageNumber = lens getMessageNumber setMessageNumber |
433 | 448 | #endif | |
434 | 449 | ||
435 | class HasMessageName x where | 450 | class HasMessageName x where |
436 | getMessageName :: x -> MessageName | 451 | getMessageName :: x -> MessageName |
@@ -453,8 +468,10 @@ instance HasMessageName CryptoMessage where | |||
453 | setMessageName _ _ = error "setMessageName on CryptoMessage without message name field." | 468 | setMessageName _ _ = error "setMessageName on CryptoMessage without message name field." |
454 | -} | 469 | -} |
455 | 470 | ||
471 | #ifdef VERSION_lens | ||
456 | messageName :: (Functor f, HasMessageName x) => (MessageName -> f MessageName) -> (x -> f x) | 472 | messageName :: (Functor f, HasMessageName x) => (MessageName -> f MessageName) -> (x -> f x) |
457 | messageName = lens getMessageName setMessageName | 473 | messageName = lens getMessageName setMessageName |
474 | #endif | ||
458 | 475 | ||
459 | data KnownLossyness = KnownLossy | KnownLossless | 476 | data KnownLossyness = KnownLossy | KnownLossless |
460 | deriving (Eq,Ord,Show,Enum) | 477 | deriving (Eq,Ord,Show,Enum) |
@@ -497,8 +514,10 @@ instance AsWord64 MessageType where | |||
497 | fromWord64 x | x < 1024, x .|. 0x0200 == 0x0200 = GrpMsg (toEnum8 ((x - 512) `div` 256)) (toEnum8 x) | 514 | fromWord64 x | x < 1024, x .|. 0x0200 == 0x0200 = GrpMsg (toEnum8 ((x - 512) `div` 256)) (toEnum8 x) |
498 | fromWord64 x = error "Not clear how to convert Word64 to MessageType" | 515 | fromWord64 x = error "Not clear how to convert Word64 to MessageType" |
499 | 516 | ||
517 | #ifdef VERSION_lens | ||
500 | word16 :: (Functor f, AsWord16 x) => (Word16 -> f Word16) -> (x -> f x) | 518 | word16 :: (Functor f, AsWord16 x) => (Word16 -> f Word16) -> (x -> f x) |
501 | word16 = lens toWord16 (\_ x -> fromWord16 x) | 519 | word16 = lens toWord16 (\_ x -> fromWord16 x) |
520 | #endif | ||
502 | 521 | ||
503 | instance Ord MessageType where | 522 | instance Ord MessageType where |
504 | compare (Msg x) (Msg y) = compare x y | 523 | compare (Msg x) (Msg y) = compare x y |
@@ -540,9 +559,11 @@ instance HasMessageType CryptoData where | |||
540 | setMessageType cd@(CryptoData { bufferData=bd }) typ = cd { bufferData=setMessageType bd typ } | 559 | setMessageType cd@(CryptoData { bufferData=bd }) typ = cd { bufferData=setMessageType bd typ } |
541 | -} | 560 | -} |
542 | 561 | ||
562 | #ifdef VERSION_lens | ||
543 | -- | This lens should always succeed on CryptoMessage | 563 | -- | This lens should always succeed on CryptoMessage |
544 | messageType :: (Functor f, HasMessageType x) => (MessageType -> f MessageType) -> (x -> f x) | 564 | messageType :: (Functor f, HasMessageType x) => (MessageType -> f MessageType) -> (x -> f x) |
545 | messageType = lens getMessageType setMessageType | 565 | messageType = lens getMessageType setMessageType |
566 | #endif | ||
546 | 567 | ||
547 | type MessageData = B.ByteString | 568 | type MessageData = B.ByteString |
548 | 569 | ||
@@ -568,8 +589,10 @@ instance HasMessageData CryptoMessage where | |||
568 | setMessageData _ _ = error "setMessageData on CryptoMessage without message data field." | 589 | setMessageData _ _ = error "setMessageData on CryptoMessage without message data field." |
569 | -} | 590 | -} |
570 | 591 | ||
592 | #ifdef VERSION_lens | ||
571 | messageData :: (Functor f, HasMessageData x) => (MessageData -> f MessageData) -> (x -> f x) | 593 | messageData :: (Functor f, HasMessageData x) => (MessageData -> f MessageData) -> (x -> f x) |
572 | messageData = lens getMessageData setMessageData | 594 | messageData = lens getMessageData setMessageData |
595 | #endif | ||
573 | 596 | ||
574 | class HasTitle x where | 597 | class HasTitle x where |
575 | getTitle :: x -> Text | 598 | getTitle :: x -> Text |
@@ -598,8 +621,10 @@ instance HasTitle CryptoMessage where | |||
598 | setTitle _ _ = error "setTitle on CryptoMessage without title field." | 621 | setTitle _ _ = error "setTitle on CryptoMessage without title field." |
599 | -} | 622 | -} |
600 | 623 | ||
624 | #ifdef VERSION_lens | ||
601 | title :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x) | 625 | title :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x) |
602 | title = lens getTitle setTitle | 626 | title = lens getTitle setTitle |
627 | #endif | ||
603 | 628 | ||
604 | class HasMessage x where | 629 | class HasMessage x where |
605 | getMessage :: x -> Text | 630 | getMessage :: x -> Text |
@@ -628,8 +653,10 @@ instance HasMessage CryptoMessage where | |||
628 | setMessage _ _ = error "setMessage on CryptoMessage without message field." | 653 | setMessage _ _ = error "setMessage on CryptoMessage without message field." |
629 | -} | 654 | -} |
630 | 655 | ||
656 | #ifdef VERSION_lens | ||
631 | message :: (Functor f, HasMessage x) => (Text -> f Text) -> (x -> f x) | 657 | message :: (Functor f, HasMessage x) => (Text -> f Text) -> (x -> f x) |
632 | message = lens getMessage setMessage | 658 | message = lens getMessage setMessage |
659 | #endif | ||
633 | 660 | ||
634 | class HasName x where | 661 | class HasName x where |
635 | getName :: x -> Text | 662 | getName :: x -> Text |
@@ -648,8 +675,10 @@ instance HasName CryptoMessage where | |||
648 | setName _ _ = error "setName on CryptoMessage without name field." | 675 | setName _ _ = error "setName on CryptoMessage without name field." |
649 | -} | 676 | -} |
650 | 677 | ||
678 | #ifdef VERSION_lens | ||
651 | name :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x) | 679 | name :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x) |
652 | name = lens getTitle setTitle | 680 | name = lens getTitle setTitle |
681 | #endif | ||
653 | 682 | ||
654 | data PeerInfo | 683 | data PeerInfo |
655 | = PeerInfo | 684 | = PeerInfo |
diff --git a/src/Network/Tox/Handshake.hs b/src/Network/Tox/Handshake.hs index 6df9edab..c48b7415 100644 --- a/src/Network/Tox/Handshake.hs +++ b/src/Network/Tox/Handshake.hs | |||
@@ -8,10 +8,10 @@ module Network.Tox.Handshake where | |||
8 | 8 | ||
9 | import Control.Arrow | 9 | import Control.Arrow |
10 | import Control.Concurrent.STM | 10 | import Control.Concurrent.STM |
11 | import Control.Lens | ||
12 | import Control.Monad | 11 | import Control.Monad |
13 | import Crypto.Hash | 12 | import Crypto.Hash |
14 | import Crypto.Tox | 13 | import Crypto.Tox |
14 | import Data.Functor.Identity | ||
15 | import Data.Time.Clock.POSIX | 15 | import Data.Time.Clock.POSIX |
16 | import Network.Tox.Crypto.Transport | 16 | import Network.Tox.Crypto.Transport |
17 | import Network.Tox.DHT.Handlers (createCookieSTM) | 17 | import Network.Tox.DHT.Handlers (createCookieSTM) |