diff options
author | joe <joe@jerkface.net> | 2017-08-11 01:35:09 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-08-11 01:35:09 -0400 |
commit | d5e16955b8264642aae093b345ba356974a60c5f (patch) | |
tree | f6bdcc06b4e5f5639a67842ccb04b38d6a94287f | |
parent | cd5091c4a3ab1c05b48ff3ad2fea666d77b8e39c (diff) |
Store return paths for announced keys.
-rw-r--r-- | Tox.hs | 32 | ||||
-rw-r--r-- | ToxMessage.hs | 2 |
2 files changed, 18 insertions, 16 deletions
@@ -703,7 +703,9 @@ newClient addr = do | |||
703 | , tableMethods = tbl | 703 | , tableMethods = tbl |
704 | } | 704 | } |
705 | 705 | ||
706 | handler typ f = Just $ MethodHandler (S.decode . msgData) (encodePayload typ) f | 706 | handler typ f = Just $ MethodHandler (S.decode . msgData) (encodePayload typ) (f . (\(ToxPath ni _)->ni)) |
707 | |||
708 | handler' typ f = Just $ MethodHandler (S.decode . msgData) (encodePayload typ) f | ||
707 | 709 | ||
708 | -- (decryptAssymetric secret) (encryptAssymetric secret . cryptoNonce) f | 710 | -- (decryptAssymetric secret) (encryptAssymetric secret . cryptoNonce) f |
709 | 711 | ||
@@ -713,7 +715,7 @@ newClient addr = do | |||
713 | handlers :: Tox.PacketKind -> Maybe Handler | 715 | handlers :: Tox.PacketKind -> Maybe Handler |
714 | handlers PingType = handler PongType pingH | 716 | handlers PingType = handler PongType pingH |
715 | handlers GetNodesType = handler SendNodesType $ getNodesH routing | 717 | handlers GetNodesType = handler SendNodesType $ getNodesH routing |
716 | handlers AnnounceType = handler AnnounceResponseType $ announceH routing toks keydb | 718 | handlers AnnounceType = handler' AnnounceResponseType $ announceH routing toks keydb |
717 | {- | 719 | {- |
718 | handlers var OnionRequest0 = noreply OnionRequest0 | 720 | handlers var OnionRequest0 = noreply OnionRequest0 |
719 | $ onionSend0H (symmetricCipher (return symkey) | 721 | $ onionSend0H (symmetricCipher (return symkey) |
@@ -750,7 +752,7 @@ newClient addr = do | |||
750 | -> ToxClient | 752 | -> ToxClient |
751 | mkclient (tbl,var) handlers = Client | 753 | mkclient (tbl,var) handlers = Client |
752 | { clientNet = net | 754 | { clientNet = net |
753 | , clientDispatcher = dispatch tbl var (fmap (contramapAddr (\(ToxPath ni _) -> ni)) . handlers) | 755 | , clientDispatcher = dispatch tbl var handlers -- (fmap (contramapAddr (\(ToxPath ni _) -> ni)) . handlers) |
754 | , clientErrorReporter = (printErrors stderr) { reportTimeout = reportTimeout ignoreErrors } | 756 | , clientErrorReporter = (printErrors stderr) { reportTimeout = reportTimeout ignoreErrors } |
755 | , clientPending = var | 757 | , clientPending = var |
756 | , clientAddress = \maddr -> atomically $ do | 758 | , clientAddress = \maddr -> atomically $ do |
@@ -875,7 +877,7 @@ decodePayload :: S.Serialize a => Message ByteString -> Either String a | |||
875 | decodePayload msg = S.decode $ dropEnd8 $ msgPayload msg | 877 | decodePayload msg = S.decode $ dropEnd8 $ msgPayload msg |
876 | -} | 878 | -} |
877 | 879 | ||
878 | type Handler = MethodHandler String TransactionId NodeInfo Msg | 880 | type Handler = MethodHandler String TransactionId ToxPath Msg |
879 | 881 | ||
880 | {- | 882 | {- |
881 | noreply :: Tox.PacketKind | 883 | noreply :: Tox.PacketKind |
@@ -1160,8 +1162,8 @@ getNodesH routing addr (GetNodes nid) = do | |||
1160 | -- The reason for this 20 second timeout in toxcore is that it gives a reasonable | 1162 | -- The reason for this 20 second timeout in toxcore is that it gives a reasonable |
1161 | -- time (20 to 40 seconds) for a peer to announce himself while taking in count | 1163 | -- time (20 to 40 seconds) for a peer to announce himself while taking in count |
1162 | -- all the possible delays with some extra seconds. | 1164 | -- all the possible delays with some extra seconds. |
1163 | announceH :: Routing -> TVar SessionTokens -> TVar AnnouncedKeys -> NodeInfo -> AnnounceRequest -> IO AnnounceResponse | 1165 | announceH :: Routing -> TVar SessionTokens -> TVar AnnouncedKeys -> ToxPath -> AnnounceRequest -> IO AnnounceResponse |
1164 | announceH routing toks keydb naddr req = do | 1166 | announceH routing toks keydb (ToxPath naddr retpath) req = do |
1165 | case () of | 1167 | case () of |
1166 | _ | announcePingId req == zeros32 | 1168 | _ | announcePingId req == zeros32 |
1167 | -> go False | 1169 | -> go False |
@@ -1177,22 +1179,22 @@ announceH routing toks keydb naddr req = do | |||
1177 | let storing = (nodeId naddr == announceSeeking req) | 1179 | let storing = (nodeId naddr == announceSeeking req) |
1178 | record <- atomically $ do | 1180 | record <- atomically $ do |
1179 | when (withTok && storing) $ do | 1181 | when (withTok && storing) $ do |
1180 | let ni = Tox.Aliased (naddr { nodeId = announceKey req }) | 1182 | let toxpath = ToxPath naddr{ nodeId = announceKey req } retpath |
1181 | -- Note: The following distance calculation assumes that | 1183 | -- Note: The following distance calculation assumes that |
1182 | -- our nodeid doesn't change and is the same for both | 1184 | -- our nodeid doesn't change and is the same for both |
1183 | -- routing4 and routing6. | 1185 | -- routing4 and routing6. |
1184 | d = xor (nodeId (tentativeId routing)) | 1186 | d = xor (nodeId (tentativeId routing)) |
1185 | (announceSeeking req) | 1187 | (announceSeeking req) |
1186 | modifyTVar' keydb (insertKey tm (announceSeeking req) ni d) | 1188 | modifyTVar' keydb (insertKey tm (announceSeeking req) toxpath d) |
1187 | ks <- readTVar keydb | 1189 | ks <- readTVar keydb |
1188 | return $ snd <$> MinMaxPSQ.lookup' (announceSeeking req) (keyAssoc ks) | 1190 | return $ snd <$> MinMaxPSQ.lookup' (announceSeeking req) (keyAssoc ks) |
1189 | newtok <- if storing | 1191 | newtok <- if storing |
1190 | then Nonce32 . toPaddedByteString 32 <$> grantToken toks naddr | 1192 | then Nonce32 . toPaddedByteString 32 <$> grantToken toks naddr |
1191 | else return $ zeros32 | 1193 | else return $ zeros32 |
1192 | let k = case record of | 1194 | let k = case record of |
1193 | Nothing -> NotStored newtok | 1195 | Nothing -> NotStored newtok |
1194 | Just (Tox.Aliased ni) | storing -> Acknowledged newtok | 1196 | Just (ToxPath {}) | storing -> Acknowledged newtok |
1195 | Just (Tox.Aliased ni) -> SendBackKey (nodeId ni) | 1197 | Just (ToxPath ni _) -> SendBackKey (nodeId ni) |
1196 | return $ AnnounceResponse k ns | 1198 | return $ AnnounceResponse k ns |
1197 | 1199 | ||
1198 | {- | 1200 | {- |
@@ -1330,11 +1332,11 @@ type NodeDistance = Tox.PubKey | |||
1330 | 1332 | ||
1331 | data AnnouncedKeys = AnnouncedKeys | 1333 | data AnnouncedKeys = AnnouncedKeys |
1332 | { keyByAge :: PSQ NodeId (Down POSIXTime) -- timeout of 300 seconds | 1334 | { keyByAge :: PSQ NodeId (Down POSIXTime) -- timeout of 300 seconds |
1333 | , keyAssoc :: MinMaxPSQ' Tox.PubKey NodeDistance (Tox.Aliased NodeInfo) | 1335 | , keyAssoc :: MinMaxPSQ' Tox.PubKey NodeDistance ToxPath |
1334 | } | 1336 | } |
1335 | 1337 | ||
1336 | insertKey :: POSIXTime -> Tox.PubKey -> Tox.Aliased NodeInfo -> NodeDistance -> AnnouncedKeys -> AnnouncedKeys | 1338 | insertKey :: POSIXTime -> Tox.PubKey -> ToxPath -> NodeDistance -> AnnouncedKeys -> AnnouncedKeys |
1337 | insertKey tm pub ni d keydb = AnnouncedKeys | 1339 | insertKey tm pub toxpath d keydb = AnnouncedKeys |
1338 | { keyByAge = PSQ.insert pub (Down tm) (keyByAge keydb) | 1340 | { keyByAge = PSQ.insert pub (Down tm) (keyByAge keydb) |
1339 | , keyAssoc = MinMaxPSQ.insert' pub ni d (keyAssoc keydb) | 1341 | , keyAssoc = MinMaxPSQ.insert' pub toxpath d (keyAssoc keydb) |
1340 | } | 1342 | } |
diff --git a/ToxMessage.hs b/ToxMessage.hs index 06026b49..56758e48 100644 --- a/ToxMessage.hs +++ b/ToxMessage.hs | |||
@@ -210,7 +210,7 @@ data Packet where | |||
210 | 210 | ||
211 | DHTRequest :: PubKey -> Assymetric -> Packet -- 0x20 -- Sometimes Assymetric query | 211 | DHTRequest :: PubKey -> Assymetric -> Packet -- 0x20 -- Sometimes Assymetric query |
212 | 212 | ||
213 | DataToRoute :: PubKey -> Aliased Assymetric -> Packet | 213 | DataToRoute :: PubKey -> Aliased Assymetric -> ReturnPath 3 -> Packet |
214 | DataToRouteResponse :: Aliased Assymetric -> Packet | 214 | DataToRouteResponse :: Aliased Assymetric -> Packet |
215 | 215 | ||
216 | LanDiscovery :: PubKey -> Packet -- 0x21 | 216 | LanDiscovery :: PubKey -> Packet -- 0x21 |