summaryrefslogtreecommitdiff
path: root/ToxPacket.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-08-27 18:59:23 -0400
committerjoe <joe@jerkface.net>2017-08-27 18:59:23 -0400
commit5472805a6a8fb3c3d64cbeff5bda1d78a898c602 (patch)
tree015eed92ebbbe72d3ed07b1959dc5d15719d91b2 /ToxPacket.hs
parent396b6daf475b1769a214e0d3ee8b476ff415d2f9 (diff)
reworking... ToxTransport and related modules.
Diffstat (limited to 'ToxPacket.hs')
-rw-r--r--ToxPacket.hs76
1 files changed, 76 insertions, 0 deletions
diff --git a/ToxPacket.hs b/ToxPacket.hs
new file mode 100644
index 00000000..d10a7597
--- /dev/null
+++ b/ToxPacket.hs
@@ -0,0 +1,76 @@
1{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE CPP #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE TupleSections #-}
5module ToxPacket where
6
7import ToxCrypto
8import Data.Serialize as S
9import Data.Aeson as JSON
10import Data.IP
11import qualified Data.ByteString.Char8 as C8
12import qualified Data.ByteString as B
13import Data.Word
14import qualified Data.ByteString.Base16 as Base16
15import Network.Socket
16import Data.ByteArray (ByteArrayAccess)
17import qualified Data.ByteArray as BA
18import Data.Hashable
19import Data.Bits
20import System.IO.Unsafe
21import qualified Text.ParserCombinators.ReadP as RP
22import Foreign.Storable
23import ToxAddress -- import Network.Address hiding (nodePort,nodeInfo)
24import Text.Read
25import Control.Applicative
26import Data.Char
27import Control.Monad
28import Crypto.Error.Types (throwCryptoError)
29
30-- ## DHT Request packets
31--
32-- | Length | Contents |
33-- |:-------|:--------------------------|
34-- | `1` | `uint8_t` (0x20) |
35-- | `32` | receiver's DHT public key |
36-- ... ...
37
38data DHTRequestPacket = DHTRequestPacket
39 { requestTarget :: PublicKey
40 , request :: Assym (Encrypted DHTRequest)
41 }
42
43instance Serialize DHTRequestPacket where
44 get = _todo
45 put = _todo
46
47
48data DHTRequest
49 = NATPing Nonce8
50 | NATPong Nonce8
51 | DHTPK DHTPublicKey
52
53-- | Length | Contents |
54-- |:------------|:------------------------------------|
55-- | `1` | `uint8_t` (0x9c) |
56-- | `8` | `uint64_t` `no_replay` |
57-- | `32` | Our DHT public key |
58-- | `[39, 204]` | Maximum of 4 nodes in packed format |
59data DHTPublicKey = DHTPublicKey
60 { dhtpkNonce :: Nonce8
61 , dhtpk :: PublicKey
62 , dhtpkNodes :: SendNodes
63 }
64
65-- | `32` | sender's DHT public key |
66-- | `24` | nonce |
67-- | `?` | encrypted message |
68data Assym a = Assym
69 { senderKey :: PublicKey
70 , assymNonce :: Nonce24
71 , assymData :: a
72 }
73
74newtype SendNodes = SendNodes [NodeInfo]
75 deriving (Eq,Ord,Show,Read)
76