diff options
author | Joe Crayne <joe@jerkface.net> | 2018-12-16 20:54:30 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-12-16 20:54:36 -0500 |
commit | 7dcd6ce16ce480791e4207e2c6d554a76fe75d6e (patch) | |
tree | 92710c3b822c47896df2bfb94fafbba1ef48c55c /src/Data | |
parent | 688450c2d9998db7b4389dc9642d219774c23857 (diff) |
tcp: Avoid ponging on new non-pinged connections.
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Tox/Relay.hs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/Data/Tox/Relay.hs b/src/Data/Tox/Relay.hs index d1e9fb99..c563db8d 100644 --- a/src/Data/Tox/Relay.hs +++ b/src/Data/Tox/Relay.hs | |||
@@ -4,6 +4,7 @@ | |||
4 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} | 4 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} |
5 | {-# LANGUAGE KindSignatures #-} | 5 | {-# LANGUAGE KindSignatures #-} |
6 | {-# LANGUAGE MultiParamTypeClasses #-} | 6 | {-# LANGUAGE MultiParamTypeClasses #-} |
7 | {-# LANGUAGE PatternSynonyms #-} | ||
7 | {-# LANGUAGE StandaloneDeriving #-} | 8 | {-# LANGUAGE StandaloneDeriving #-} |
8 | {-# LANGUAGE UndecidableInstances #-} | 9 | {-# LANGUAGE UndecidableInstances #-} |
9 | module Data.Tox.Relay where | 10 | module Data.Tox.Relay where |
@@ -61,9 +62,15 @@ data RelayPacket | |||
61 | | RelayData ByteString ConId | 62 | | RelayData ByteString ConId |
62 | deriving (Eq,Ord,Show,Data) | 63 | deriving (Eq,Ord,Show,Data) |
63 | 64 | ||
64 | packetNumber :: RelayPacket -> Word8 | 65 | newtype PacketNumber = PacketNumber { packetNumberToWord8 :: Word8 } |
65 | packetNumber (RelayData _ (ConId conid)) = conid -- 0 to 15 not allowed. | 66 | deriving (Eq,Ord,Show) |
66 | packetNumber rp = fromIntegral $ pred $ constrIndex $ toConstr rp | 67 | |
68 | pattern PingPacket = PacketNumber 4 | ||
69 | pattern OnionPacketID = PacketNumber 8 | ||
70 | |||
71 | packetNumber :: RelayPacket -> PacketNumber | ||
72 | packetNumber (RelayData _ (ConId conid)) = PacketNumber $ conid -- 0 to 15 not allowed. | ||
73 | packetNumber rp = PacketNumber $ fromIntegral $ pred $ constrIndex $ toConstr rp | ||
67 | 74 | ||
68 | instance Sized RelayPacket where | 75 | instance Sized RelayPacket where |
69 | size = mappend (ConstSize 1) $ VarSize $ \x -> case x of | 76 | size = mappend (ConstSize 1) $ VarSize $ \x -> case x of |
@@ -101,7 +108,7 @@ instance Serialize RelayPacket where | |||
101 | conid -> (`RelayData` ConId conid) <$> (remaining >>= getBytes) | 108 | conid -> (`RelayData` ConId conid) <$> (remaining >>= getBytes) |
102 | 109 | ||
103 | put rp = do | 110 | put rp = do |
104 | putWord8 $ packetNumber rp | 111 | putWord8 $ packetNumberToWord8 $ packetNumber rp |
105 | case rp of | 112 | case rp of |
106 | RoutingRequest k -> putPublicKey k | 113 | RoutingRequest k -> putPublicKey k |
107 | RoutingResponse rpid k -> put rpid >> putPublicKey k | 114 | RoutingResponse rpid k -> put rpid >> putPublicKey k |