diff options
author | joe <joe@jerkface.net> | 2017-08-27 18:59:23 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-08-27 18:59:23 -0400 |
commit | 5472805a6a8fb3c3d64cbeff5bda1d78a898c602 (patch) | |
tree | 015eed92ebbbe72d3ed07b1959dc5d15719d91b2 /ToxPacket.hs | |
parent | 396b6daf475b1769a214e0d3ee8b476ff415d2f9 (diff) |
reworking... ToxTransport and related modules.
Diffstat (limited to 'ToxPacket.hs')
-rw-r--r-- | ToxPacket.hs | 76 |
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 #-} | ||
5 | module ToxPacket where | ||
6 | |||
7 | import ToxCrypto | ||
8 | import Data.Serialize as S | ||
9 | import Data.Aeson as JSON | ||
10 | import Data.IP | ||
11 | import qualified Data.ByteString.Char8 as C8 | ||
12 | import qualified Data.ByteString as B | ||
13 | import Data.Word | ||
14 | import qualified Data.ByteString.Base16 as Base16 | ||
15 | import Network.Socket | ||
16 | import Data.ByteArray (ByteArrayAccess) | ||
17 | import qualified Data.ByteArray as BA | ||
18 | import Data.Hashable | ||
19 | import Data.Bits | ||
20 | import System.IO.Unsafe | ||
21 | import qualified Text.ParserCombinators.ReadP as RP | ||
22 | import Foreign.Storable | ||
23 | import ToxAddress -- import Network.Address hiding (nodePort,nodeInfo) | ||
24 | import Text.Read | ||
25 | import Control.Applicative | ||
26 | import Data.Char | ||
27 | import Control.Monad | ||
28 | import 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 | |||
38 | data DHTRequestPacket = DHTRequestPacket | ||
39 | { requestTarget :: PublicKey | ||
40 | , request :: Assym (Encrypted DHTRequest) | ||
41 | } | ||
42 | |||
43 | instance Serialize DHTRequestPacket where | ||
44 | get = _todo | ||
45 | put = _todo | ||
46 | |||
47 | |||
48 | data 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 | | ||
59 | data 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 | | ||
68 | data Assym a = Assym | ||
69 | { senderKey :: PublicKey | ||
70 | , assymNonce :: Nonce24 | ||
71 | , assymData :: a | ||
72 | } | ||
73 | |||
74 | newtype SendNodes = SendNodes [NodeInfo] | ||
75 | deriving (Eq,Ord,Show,Read) | ||
76 | |||