summaryrefslogtreecommitdiff
path: root/src/Network/Tox
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/Crypto/Transport.hs28
-rw-r--r--src/Network/Tox/DHT/Handlers.hs5
-rw-r--r--src/Network/Tox/Onion/Handlers.hs2
-rw-r--r--src/Network/Tox/TCP.hs8
4 files changed, 25 insertions, 18 deletions
diff --git a/src/Network/Tox/Crypto/Transport.hs b/src/Network/Tox/Crypto/Transport.hs
index 2c13e168..a18b550d 100644
--- a/src/Network/Tox/Crypto/Transport.hs
+++ b/src/Network/Tox/Crypto/Transport.hs
@@ -44,7 +44,7 @@ module Network.Tox.Crypto.Transport
44 , HasMessage(..) 44 , HasMessage(..)
45 , HasMessageType(..) 45 , HasMessageType(..)
46 -- lenses 46 -- lenses
47#ifdef VERSION_lens 47#ifdef USE_lens
48 , groupNumber, groupNumberToJoin, peerNumber, messageNumber 48 , groupNumber, groupNumberToJoin, peerNumber, messageNumber
49 , messageName, messageData, name, title, message, messageType 49 , messageName, messageData, name, title, message, messageType
50#endif 50#endif
@@ -288,7 +288,7 @@ putCryptoMessage seqno (Pkt t :=> Identity x) = do
288 putPacket seqno x 288 putPacket seqno x
289 289
290 290
291#ifdef VERSION_lens 291#ifdef USE_lens
292erCompat :: String -> a 292erCompat :: String -> a
293erCompat lens = error $ "Use of '" ++ lens ++ "' lens on incompatible CryptoMessage type" 293erCompat lens = error $ "Use of '" ++ lens ++ "' lens on incompatible CryptoMessage type"
294#endif 294#endif
@@ -336,7 +336,7 @@ instance HasGroupChatID CryptoMessage where
336 setGroupChatID _ _= error "setGroupChatID on non-groupchat message." 336 setGroupChatID _ _= error "setGroupChatID on non-groupchat message."
337-} 337-}
338 338
339#ifdef VERSION_lens 339#ifdef USE_lens
340groupChatID :: (Functor f, HasGroupChatID x) => (GroupChatId -> f GroupChatId) -> (x -> f x) 340groupChatID :: (Functor f, HasGroupChatID x) => (GroupChatId -> f GroupChatId) -> (x -> f x)
341groupChatID = lens getGroupChatID setGroupChatID 341groupChatID = lens getGroupChatID setGroupChatID
342#endif 342#endif
@@ -370,7 +370,7 @@ instance HasGroupNumber CryptoMessage where
370 setGroupNumber _ _ = error "setGroupNumber on CryptoMessage without group number field." 370 setGroupNumber _ _ = error "setGroupNumber on CryptoMessage without group number field."
371-} 371-}
372 372
373#ifdef VERSION_lens 373#ifdef USE_lens
374groupNumber :: (Functor f, HasGroupNumber x) => (Word16 -> f Word16) -> (x -> f x) 374groupNumber :: (Functor f, HasGroupNumber x) => (Word16 -> f Word16) -> (x -> f x)
375groupNumber = lens getGroupNumber setGroupNumber 375groupNumber = lens getGroupNumber setGroupNumber
376#endif 376#endif
@@ -394,7 +394,7 @@ instance HasGroupNumberToJoin CryptoMessage where
394 setGroupNumberToJoin _ _ = error "setGroupNumberToJoin on CryptoMessage without group number (to join) field." 394 setGroupNumberToJoin _ _ = error "setGroupNumberToJoin on CryptoMessage without group number (to join) field."
395-} 395-}
396 396
397#ifdef VERSION_lens 397#ifdef USE_lens
398groupNumberToJoin :: (Functor f, HasGroupNumberToJoin x) => (GroupNumber -> f GroupNumber) -> (x -> f x) 398groupNumberToJoin :: (Functor f, HasGroupNumberToJoin x) => (GroupNumber -> f GroupNumber) -> (x -> f x)
399groupNumberToJoin = lens getGroupNumberToJoin setGroupNumberToJoin 399groupNumberToJoin = lens getGroupNumberToJoin setGroupNumberToJoin
400#endif 400#endif
@@ -418,7 +418,7 @@ instance HasPeerNumber CryptoMessage where
418 setPeerNumber _ _ = error "setPeerNumber on CryptoMessage without peer number field." 418 setPeerNumber _ _ = error "setPeerNumber on CryptoMessage without peer number field."
419-} 419-}
420 420
421#ifdef VERSION_lens 421#ifdef USE_lens
422peerNumber :: (Functor f, HasPeerNumber x) => (Word16 -> f Word16) -> (x -> f x) 422peerNumber :: (Functor f, HasPeerNumber x) => (Word16 -> f Word16) -> (x -> f x)
423peerNumber = lens getPeerNumber setPeerNumber 423peerNumber = lens getPeerNumber setPeerNumber
424#endif 424#endif
@@ -442,7 +442,7 @@ instance HasMessageNumber CryptoMessage where
442 setMessageNumber _ _ = error "setMessageNumber on CryptoMessage without message number field." 442 setMessageNumber _ _ = error "setMessageNumber on CryptoMessage without message number field."
443-} 443-}
444 444
445#ifdef VERSION_lens 445#ifdef USE_lens
446messageNumber :: (Functor f, HasMessageNumber x) => (Word32 -> f Word32) -> (x -> f x) 446messageNumber :: (Functor f, HasMessageNumber x) => (Word32 -> f Word32) -> (x -> f x)
447messageNumber = lens getMessageNumber setMessageNumber 447messageNumber = lens getMessageNumber setMessageNumber
448#endif 448#endif
@@ -468,7 +468,7 @@ instance HasMessageName CryptoMessage where
468 setMessageName _ _ = error "setMessageName on CryptoMessage without message name field." 468 setMessageName _ _ = error "setMessageName on CryptoMessage without message name field."
469-} 469-}
470 470
471#ifdef VERSION_lens 471#ifdef USE_lens
472messageName :: (Functor f, HasMessageName x) => (MessageName -> f MessageName) -> (x -> f x) 472messageName :: (Functor f, HasMessageName x) => (MessageName -> f MessageName) -> (x -> f x)
473messageName = lens getMessageName setMessageName 473messageName = lens getMessageName setMessageName
474#endif 474#endif
@@ -514,7 +514,7 @@ instance AsWord64 MessageType where
514 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)
515 fromWord64 x = error "Not clear how to convert Word64 to MessageType" 515 fromWord64 x = error "Not clear how to convert Word64 to MessageType"
516 516
517#ifdef VERSION_lens 517#ifdef USE_lens
518word16 :: (Functor f, AsWord16 x) => (Word16 -> f Word16) -> (x -> f x) 518word16 :: (Functor f, AsWord16 x) => (Word16 -> f Word16) -> (x -> f x)
519word16 = lens toWord16 (\_ x -> fromWord16 x) 519word16 = lens toWord16 (\_ x -> fromWord16 x)
520#endif 520#endif
@@ -559,7 +559,7 @@ instance HasMessageType CryptoData where
559 setMessageType cd@(CryptoData { bufferData=bd }) typ = cd { bufferData=setMessageType bd typ } 559 setMessageType cd@(CryptoData { bufferData=bd }) typ = cd { bufferData=setMessageType bd typ }
560-} 560-}
561 561
562#ifdef VERSION_lens 562#ifdef USE_lens
563-- | This lens should always succeed on CryptoMessage 563-- | This lens should always succeed on CryptoMessage
564messageType :: (Functor f, HasMessageType x) => (MessageType -> f MessageType) -> (x -> f x) 564messageType :: (Functor f, HasMessageType x) => (MessageType -> f MessageType) -> (x -> f x)
565messageType = lens getMessageType setMessageType 565messageType = lens getMessageType setMessageType
@@ -589,7 +589,7 @@ instance HasMessageData CryptoMessage where
589 setMessageData _ _ = error "setMessageData on CryptoMessage without message data field." 589 setMessageData _ _ = error "setMessageData on CryptoMessage without message data field."
590-} 590-}
591 591
592#ifdef VERSION_lens 592#ifdef USE_lens
593messageData :: (Functor f, HasMessageData x) => (MessageData -> f MessageData) -> (x -> f x) 593messageData :: (Functor f, HasMessageData x) => (MessageData -> f MessageData) -> (x -> f x)
594messageData = lens getMessageData setMessageData 594messageData = lens getMessageData setMessageData
595#endif 595#endif
@@ -621,7 +621,7 @@ instance HasTitle CryptoMessage where
621 setTitle _ _ = error "setTitle on CryptoMessage without title field." 621 setTitle _ _ = error "setTitle on CryptoMessage without title field."
622-} 622-}
623 623
624#ifdef VERSION_lens 624#ifdef USE_lens
625title :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x) 625title :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x)
626title = lens getTitle setTitle 626title = lens getTitle setTitle
627#endif 627#endif
@@ -653,7 +653,7 @@ instance HasMessage CryptoMessage where
653 setMessage _ _ = error "setMessage on CryptoMessage without message field." 653 setMessage _ _ = error "setMessage on CryptoMessage without message field."
654-} 654-}
655 655
656#ifdef VERSION_lens 656#ifdef USE_lens
657message :: (Functor f, HasMessage x) => (Text -> f Text) -> (x -> f x) 657message :: (Functor f, HasMessage x) => (Text -> f Text) -> (x -> f x)
658message = lens getMessage setMessage 658message = lens getMessage setMessage
659#endif 659#endif
@@ -675,7 +675,7 @@ instance HasName CryptoMessage where
675 setName _ _ = error "setName on CryptoMessage without name field." 675 setName _ _ = error "setName on CryptoMessage without name field."
676-} 676-}
677 677
678#ifdef VERSION_lens 678#ifdef USE_lens
679name :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x) 679name :: (Functor f, HasTitle x) => (Text -> f Text) -> (x -> f x)
680name = lens getTitle setTitle 680name = lens getTitle setTitle
681#endif 681#endif
diff --git a/src/Network/Tox/DHT/Handlers.hs b/src/Network/Tox/DHT/Handlers.hs
index 2fbac5d3..afdf2cc3 100644
--- a/src/Network/Tox/DHT/Handlers.hs
+++ b/src/Network/Tox/DHT/Handlers.hs
@@ -195,6 +195,8 @@ newRouting addr crypto update4 update6 = do
195 { searchSpace = toxSpace 195 { searchSpace = toxSpace
196 , searchNodeAddress = nodeIP &&& nodePort 196 , searchNodeAddress = nodeIP &&& nodePort
197 , searchQuery = \_ _ -> return Nothing 197 , searchQuery = \_ _ -> return Nothing
198 , searchAlpha = 1
199 , searchK = 2
198 } 200 }
199 tbl4 <- newTVar $ R.nullTable (comparing nodeId) (\s -> hashWithSalt s . nodeId) tentative_info4 R.defaultBucketCount 201 tbl4 <- newTVar $ R.nullTable (comparing nodeId) (\s -> hashWithSalt s . nodeId) tentative_info4 R.defaultBucketCount
200 tbl6 <- newTVar $ R.nullTable (comparing nodeId) (\s -> hashWithSalt s . nodeId) tentative_info6 R.defaultBucketCount 202 tbl6 <- newTVar $ R.nullTable (comparing nodeId) (\s -> hashWithSalt s . nodeId) tentative_info6 R.defaultBucketCount
@@ -524,4 +526,7 @@ nodeSearch client cbvar = Search
524 { searchSpace = toxSpace 526 { searchSpace = toxSpace
525 , searchNodeAddress = nodeIP &&& nodePort 527 , searchNodeAddress = nodeIP &&& nodePort
526 , searchQuery = getNodes client cbvar 528 , searchQuery = getNodes client cbvar
529 , searchAlpha = 8
530 , searchK = 16
531
527 } 532 }
diff --git a/src/Network/Tox/Onion/Handlers.hs b/src/Network/Tox/Onion/Handlers.hs
index a16508cd..52cc298d 100644
--- a/src/Network/Tox/Onion/Handlers.hs
+++ b/src/Network/Tox/Onion/Handlers.hs
@@ -219,6 +219,8 @@ toxidSearch getTimeout crypto client = Search
219 { searchSpace = toxSpace 219 { searchSpace = toxSpace
220 , searchNodeAddress = nodeIP &&& nodePort 220 , searchNodeAddress = nodeIP &&& nodePort
221 , searchQuery = getRendezvous getTimeout crypto client 221 , searchQuery = getRendezvous getTimeout crypto client
222 , searchAlpha = 3
223 , searchK = 6
222 } 224 }
223 225
224announceSerializer :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int)) 226announceSerializer :: (TransactionId -> OnionDestination r -> STM (OnionDestination r, Int))
diff --git a/src/Network/Tox/TCP.hs b/src/Network/Tox/TCP.hs
index 1111d3b8..a7881c24 100644
--- a/src/Network/Tox/TCP.hs
+++ b/src/Network/Tox/TCP.hs
@@ -191,15 +191,15 @@ getUDPNodes' tcp seeking dst0 = do
191 n24 <- transportNewNonce (tcpCrypto tcp) 191 n24 <- transportNewNonce (tcpCrypto tcp)
192 return (b,c,n24) 192 return (b,c,n24)
193 let (dst,gateway') = if UDP.nodeId dst0 == nodeId gateway 193 let (dst,gateway') = if UDP.nodeId dst0 == nodeId gateway
194 then ( dst0 { UDP.nodeIP = fromJust $ fromSockAddr localhost4 } 194 then ( dst0 { UDP.nodeIP = fromJust $ Network.Address.fromSockAddr localhost4 }
195 , gateway { udpNodeInfo = (udpNodeInfo gateway) 195 , gateway { udpNodeInfo = (udpNodeInfo gateway)
196 { UDP.nodeIP = fromJust $ fromSockAddr localhost4 }}) 196 { UDP.nodeIP = fromJust $ Network.Address.fromSockAddr localhost4 }})
197 else (dst0,gateway) 197 else (dst0,gateway)
198 wrap2 <- lookupNonceFunction (tcpCrypto tcp) b (UDP.id2key $ UDP.nodeId dst) 198 wrap2 <- lookupNonceFunction (tcpCrypto tcp) b (UDP.id2key $ UDP.nodeId dst)
199 wrap1 <- lookupNonceFunction (tcpCrypto tcp) c (UDP.id2key $ nodeId gateway) 199 wrap1 <- lookupNonceFunction (tcpCrypto tcp) c (UDP.id2key $ nodeId gateway)
200 wrap0 <- lookupNonceFunction (tcpCrypto tcp) (transportSecret $ tcpCrypto tcp) (UDP.id2key $ UDP.nodeId dst) 200 wrap0 <- lookupNonceFunction (tcpCrypto tcp) (transportSecret $ tcpCrypto tcp) (UDP.id2key $ UDP.nodeId dst)
201 let meth = MethodSerializer -- MethodSerializer Nonce8 NodeInfo RelayPacket meth AnnounceRequest (Either String AnnounceResponse) 201 let meth = MethodSerializer -- MethodSerializer Nonce8 NodeInfo RelayPacket meth AnnounceRequest (Either String AnnounceResponse)
202 { methodTimeout = \tid addr -> return (addr,8000000) -- 8 second timeout 202 { methodTimeout = \tid addr -> return (addr,12000000) -- 12 second timeout
203 , method = () -- meth 203 , method = () -- meth
204 , wrapQuery = \n8 src gateway x -> 204 , wrapQuery = \n8 src gateway x ->
205 OnionPacket n24 $ Addressed (UDP.nodeAddr dst) 205 OnionPacket n24 $ Addressed (UDP.nodeAddr dst)
@@ -274,7 +274,7 @@ newClient crypto store load = do
274 , tableMethods = transactionMethods' store load (contramap (\(Nonce8 w64) -> w64) w64MapMethods) 274 , tableMethods = transactionMethods' store load (contramap (\(Nonce8 w64) -> w64) w64MapMethods)
275 $ first (either error Nonce8 . decode) . randomBytesGenerate 8 275 $ first (either error Nonce8 . decode) . randomBytesGenerate 8
276 } 276 }
277 , clientErrorReporter = logErrors 277 , clientErrorReporter = logErrors { reportTimeout = reportTimeout ignoreErrors }
278 , clientPending = map_var 278 , clientPending = map_var
279 , clientAddress = \_ -> return $ NodeInfo 279 , clientAddress = \_ -> return $ NodeInfo
280 { udpNodeInfo = either error id $ UDP.nodeInfo (UDP.key2id $ transportPublic crypto) (SockAddrInet 0 0) 280 { udpNodeInfo = either error id $ UDP.nodeInfo (UDP.key2id $ transportPublic crypto) (SockAddrInet 0 0)