diff options
author | joe <joe@jerkface.net> | 2017-09-15 04:32:05 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-09-15 04:32:05 -0400 |
commit | 0f0ccf566b6df2a1b1ad08f2781f7fd29926dde6 (patch) | |
tree | 1c4576c8389cac3bf98fdad0abebbf0b516a4ac9 /src/Network/Tox/Transport.hs | |
parent | 8b59a7a567d50dc996a3b98f223df45f3e6739ef (diff) |
Moved ToxTransport to its hierarchical location.
Diffstat (limited to 'src/Network/Tox/Transport.hs')
-rw-r--r-- | src/Network/Tox/Transport.hs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/Network/Tox/Transport.hs b/src/Network/Tox/Transport.hs new file mode 100644 index 00000000..24bd60b7 --- /dev/null +++ b/src/Network/Tox/Transport.hs | |||
@@ -0,0 +1,71 @@ | |||
1 | {-# LANGUAGE DataKinds #-} | ||
2 | {-# LANGUAGE GADTs #-} | ||
3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
4 | {-# LANGUAGE KindSignatures #-} | ||
5 | {-# LANGUAGE LambdaCase #-} | ||
6 | {-# LANGUAGE ScopedTypeVariables #-} | ||
7 | {-# LANGUAGE TupleSections #-} | ||
8 | {-# LANGUAGE TypeOperators #-} | ||
9 | module Network.Tox.Transport (toxTransport) where | ||
10 | |||
11 | import Network.QueryResponse | ||
12 | import Crypto.Tox | ||
13 | import Network.Tox.DHT.Transport | ||
14 | import Network.Tox.Onion.Transport | ||
15 | import Network.Tox.Crypto.Transport | ||
16 | |||
17 | import Network.Socket | ||
18 | |||
19 | toxTransport :: | ||
20 | TransportCrypto | ||
21 | -> (PublicKey -> IO (Maybe NodeInfo)) | ||
22 | -> UDPTransport | ||
23 | -> IO ( Transport String NodeInfo (DHTMessage Encrypted8) | ||
24 | , Transport String OnionToOwner (OnionMessage Encrypted) | ||
25 | , Transport String SockAddr NetCrypto ) | ||
26 | toxTransport crypto closeLookup udp = do | ||
27 | (dht,udp1) <- partitionTransport parseDHTAddr encodeDHTAddr id $ forwardOnions crypto udp | ||
28 | (onion,udp2) <- partitionTransport parseOnionAddr encodeOnionAddr id udp1 | ||
29 | let netcrypto = layerTransport parseNetCrypto encodeNetCrypto udp2 | ||
30 | return ( forwardDHTRequests crypto closeLookup dht | ||
31 | , onion | ||
32 | , netcrypto | ||
33 | ) | ||
34 | |||
35 | |||
36 | -- instance (Sized a, Sized b) => Sized (a,b) where size = _todo | ||
37 | |||
38 | |||
39 | -- Byte value Packet Kind Return address | ||
40 | -- :----------- :-------------------- | ||
41 | -- `0x00` Ping Request DHTNode | ||
42 | -- `0x01` Ping Response - | ||
43 | -- `0x02` Nodes Request DHTNode | ||
44 | -- `0x04` Nodes Response - | ||
45 | -- `0x18` Cookie Request DHTNode, but without sending pubkey in response | ||
46 | -- `0x19` Cookie Response - (no pubkey) | ||
47 | -- | ||
48 | -- `0x21` LAN Discovery DHTNode (No reply, port 33445, trigger Nodes Request/Response) | ||
49 | -- | ||
50 | -- `0x20` DHT Request DHTNode/-forward | ||
51 | -- | ||
52 | -- `0x1a` Crypto Handshake CookieAddress | ||
53 | -- | ||
54 | -- `0x1b` Crypto Data SessionAddress | ||
55 | -- | ||
56 | -- `0x83` Announce Request OnionToOwner | ||
57 | -- `0x84` Announce Response - | ||
58 | -- `0x85` Onion Data Request OnionToOwner | ||
59 | -- `0x86` Onion Data Response - | ||
60 | -- | ||
61 | -- `0xf0` Bootstrap Info SockAddr? | ||
62 | -- | ||
63 | -- `0x80` Onion Request 0 -forward | ||
64 | -- `0x81` Onion Request 1 -forward | ||
65 | -- `0x82` Onion Request 2 -forward | ||
66 | -- `0x8c` Onion Response 3 -return | ||
67 | -- `0x8d` Onion Response 2 -return | ||
68 | -- `0x8e` Onion Response 1 -return | ||
69 | |||
70 | |||
71 | |||