summaryrefslogtreecommitdiff
path: root/src/Network/Tox/DHT
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-10-14 16:34:24 -0400
committerjoe <joe@jerkface.net>2017-10-14 16:34:24 -0400
commit4b7f8e625d6cab8ae25074fc3339a5403ec5fb36 (patch)
tree9da87ee15ce14f6347e40b8a9491547edc281c9f /src/Network/Tox/DHT
parentf1a79aef9799176b52efb6197aaf7c2b5a8f14ad (diff)
Partitioned friend-request transport from the onion transport.
Diffstat (limited to 'src/Network/Tox/DHT')
-rw-r--r--src/Network/Tox/DHT/Transport.hs29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/Network/Tox/DHT/Transport.hs b/src/Network/Tox/DHT/Transport.hs
index 187e23f2..16af0e3f 100644
--- a/src/Network/Tox/DHT/Transport.hs
+++ b/src/Network/Tox/DHT/Transport.hs
@@ -16,7 +16,8 @@ module Network.Tox.DHT.Transport
16 , Pong(..) 16 , Pong(..)
17 , GetNodes(..) 17 , GetNodes(..)
18 , SendNodes(..) 18 , SendNodes(..)
19 , DHTPublicKey 19 , DHTPublicKey(..)
20 , FriendRequest(..)
20 , CookieRequest 21 , CookieRequest
21 , Cookie 22 , Cookie
22 , DHTRequest 23 , DHTRequest
@@ -35,10 +36,12 @@ import Network.QueryResponse
35import Control.Arrow 36import Control.Arrow
36import Control.Monad 37import Control.Monad
37import Data.Bool 38import Data.Bool
38import qualified Data.ByteString as B 39import qualified Data.ByteString as B
39 ;import Data.ByteString (ByteString) 40 ;import Data.ByteString (ByteString)
41import Data.Functor.Contravariant
42import Data.Monoid
43import Data.Serialize as S
40import Data.Tuple 44import Data.Tuple
41import Data.Serialize as S
42import Data.Word 45import Data.Word
43import Network.Socket 46import Network.Socket
44 47
@@ -203,6 +206,13 @@ data DHTPublicKey = DHTPublicKey
203 , dhtpkNodes :: SendNodes -- other reachable nodes 206 , dhtpkNodes :: SendNodes -- other reachable nodes
204 } 207 }
205 208
209-- int8_t (0x20 sent over onion, 0x12 for sent over net_crypto)
210-- [uint32_t nospam][Message (UTF8) 1 to ONION_CLIENT_MAX_DATA_SIZE bytes]
211data FriendRequest = FriendRequest
212 { friendNoSpam :: Word32
213 , friendRequestText :: ByteString -- UTF8
214 }
215
206-- When sent as a DHT request packet (this is the data sent in the DHT request 216-- When sent as a DHT request packet (this is the data sent in the DHT request
207-- packet): 217-- packet):
208-- 218--
@@ -231,6 +241,13 @@ instance Sized DHTPublicKey where
231 ConstSize nodes -> nodes 241 ConstSize nodes -> nodes
232 VarSize sznodes -> sznodes nodes 242 VarSize sznodes -> sznodes nodes
233 243
244instance Sized Word32 where size = ConstSize 4
245
246-- FIXME: Inconsitently, this type does not include the 0x20 or 0x12 tag byte
247-- where the DHTPublicKey type does include its tag.
248instance Sized FriendRequest where
249 size = contramap friendNoSpam size <> contramap friendRequestText (VarSize B.length)
250
234instance Serialize DHTPublicKey where 251instance Serialize DHTPublicKey where
235 -- TODO: This should agree with Sized instance. 252 -- TODO: This should agree with Sized instance.
236 get = DHTPublicKey <$> get <*> getPublicKey <*> get 253 get = DHTPublicKey <$> get <*> getPublicKey <*> get
@@ -239,6 +256,10 @@ instance Serialize DHTPublicKey where
239 putPublicKey key 256 putPublicKey key
240 put nodes 257 put nodes
241 258
259instance Serialize FriendRequest where
260 get = FriendRequest <$> get <*> (remaining >>= getBytes)
261 put (FriendRequest nospam txt) = put nospam >> putByteString txt
262
242newtype GetNodes = GetNodes NodeId 263newtype GetNodes = GetNodes NodeId
243 deriving (Eq,Ord,Show,Read,S.Serialize) 264 deriving (Eq,Ord,Show,Read,S.Serialize)
244 265