diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-30 22:37:30 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-12-16 14:08:26 -0500 |
commit | da35152c9a0da38f815798c5f6b6b9a0362fd330 (patch) | |
tree | aa11ed3965c997fbe4d5fde69160bd87a68093ec /src/Data | |
parent | 59aa0062c15610015a6bce077be5da1d3ed34019 (diff) |
Onion: Support for forwarding from a TCP-relay.
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Tox/Relay.hs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/Data/Tox/Relay.hs b/src/Data/Tox/Relay.hs index f801d1cd..82fef126 100644 --- a/src/Data/Tox/Relay.hs +++ b/src/Data/Tox/Relay.hs | |||
@@ -48,11 +48,11 @@ data RelayPacket | |||
48 | | OnionPacket (OnionRequest N0) | 48 | | OnionPacket (OnionRequest N0) |
49 | | OnionPacketResponse (OnionResponse N1) | 49 | | OnionPacketResponse (OnionResponse N1) |
50 | -- 0x0A through 0x0F reserved for future use. | 50 | -- 0x0A through 0x0F reserved for future use. |
51 | | RelayData ConId ByteString -- Word8 is a connection id. Encoded as number 16 to 255. | 51 | | RelayData ByteString ConId -- Word8 is a connection id. Encoded as number 16 to 255. |
52 | deriving (Eq,Ord,Show,Data) | 52 | deriving (Eq,Ord,Show,Data) |
53 | 53 | ||
54 | packetNumber :: RelayPacket -> Word8 | 54 | packetNumber :: RelayPacket -> Word8 |
55 | packetNumber (RelayData (ConId conid) _) = conid -- 0 to 15 not allowed. | 55 | packetNumber (RelayData _ (ConId conid)) = conid -- 0 to 15 not allowed. |
56 | packetNumber rp = fromIntegral $ pred $ constrIndex $ toConstr rp | 56 | packetNumber rp = fromIntegral $ pred $ constrIndex $ toConstr rp |
57 | 57 | ||
58 | instance Sized RelayPacket where | 58 | instance Sized RelayPacket where |
@@ -71,7 +71,7 @@ instance Sized RelayPacket where | |||
71 | OnionPacketResponse answer -> case contramap (`asTypeOf` answer) size of | 71 | OnionPacketResponse answer -> case contramap (`asTypeOf` answer) size of |
72 | ConstSize n -> n | 72 | ConstSize n -> n |
73 | VarSize f -> f answer | 73 | VarSize f -> f answer |
74 | RelayData _ bs -> B.length bs | 74 | RelayData bs _ -> B.length bs |
75 | 75 | ||
76 | instance Serialize RelayPacket where | 76 | instance Serialize RelayPacket where |
77 | 77 | ||
@@ -88,7 +88,7 @@ instance Serialize RelayPacket where | |||
88 | 7 -> OOBRecv <$> getPublicKey <*> (remaining >>= getBytes) | 88 | 7 -> OOBRecv <$> getPublicKey <*> (remaining >>= getBytes) |
89 | 8 -> OnionPacket <$> get | 89 | 8 -> OnionPacket <$> get |
90 | 9 -> OnionPacketResponse <$> get | 90 | 9 -> OnionPacketResponse <$> get |
91 | conid -> RelayData (ConId conid) <$> (remaining >>= getBytes) | 91 | conid -> (`RelayData` ConId conid) <$> (remaining >>= getBytes) |
92 | 92 | ||
93 | put rp = do | 93 | put rp = do |
94 | putWord8 $ packetNumber rp | 94 | putWord8 $ packetNumber rp |
@@ -103,7 +103,7 @@ instance Serialize RelayPacket where | |||
103 | OOBRecv k bs -> putPublicKey k >> putByteString bs | 103 | OOBRecv k bs -> putPublicKey k >> putByteString bs |
104 | OnionPacket query -> put query | 104 | OnionPacket query -> put query |
105 | OnionPacketResponse answer -> put answer | 105 | OnionPacketResponse answer -> put answer |
106 | RelayData _ bs -> putByteString bs | 106 | RelayData bs _ -> putByteString bs |
107 | 107 | ||
108 | -- | Initial client-to-server handshake message. | 108 | -- | Initial client-to-server handshake message. |
109 | newtype Hello (f :: * -> *) = Hello (Asymm (f HelloData)) | 109 | newtype Hello (f :: * -> *) = Hello (Asymm (f HelloData)) |