diff options
Diffstat (limited to 'dht/HandshakeCache.hs')
-rw-r--r-- | dht/HandshakeCache.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/dht/HandshakeCache.hs b/dht/HandshakeCache.hs index d9ffacab..00836fc8 100644 --- a/dht/HandshakeCache.hs +++ b/dht/HandshakeCache.hs | |||
@@ -27,13 +27,15 @@ data HandshakeCache = HandshakeCache | |||
27 | { -- Note that currently we are storing sent handshakes keyed by the | 27 | { -- Note that currently we are storing sent handshakes keyed by the |
28 | -- locally issued cookie nonce. | 28 | -- locally issued cookie nonce. |
29 | hscTable :: TVar (MinMaxPSQ' Nonce24 POSIXTime (SecretKey,HandshakeData)) | 29 | hscTable :: TVar (MinMaxPSQ' Nonce24 POSIXTime (SecretKey,HandshakeData)) |
30 | , hscSend :: Multi.SessionAddress -> Handshake Encrypted -> IO () | 30 | , hscSend :: Multi.SessionAddress -> Handshake Encrypted -> IO Multi.SessionAddress |
31 | , hscCrypto :: TransportCrypto | 31 | , hscCrypto :: TransportCrypto |
32 | , hscPendingCookies :: TVar (Map (PublicKey,PublicKey) ()) | 32 | , hscPendingCookies :: TVar (Map (PublicKey,PublicKey) ()) |
33 | } | 33 | } |
34 | 34 | ||
35 | 35 | ||
36 | newHandshakeCache :: TransportCrypto -> (Multi.SessionAddress -> Handshake Encrypted -> IO ()) -> IO HandshakeCache | 36 | newHandshakeCache :: TransportCrypto |
37 | -> (Multi.SessionAddress -> Handshake Encrypted -> IO Multi.SessionAddress) | ||
38 | -> IO HandshakeCache | ||
37 | newHandshakeCache crypto send = atomically $ do | 39 | newHandshakeCache crypto send = atomically $ do |
38 | tbl <- newTVar MM.empty | 40 | tbl <- newTVar MM.empty |
39 | pcs <- newTVar Map.empty | 41 | pcs <- newTVar Map.empty |
@@ -49,13 +51,13 @@ getSentHandshake :: HandshakeCache | |||
49 | -> Multi.SessionAddress | 51 | -> Multi.SessionAddress |
50 | -> Cookie Identity -- locally issued | 52 | -> Cookie Identity -- locally issued |
51 | -> Cookie Encrypted -- remotely issued | 53 | -> Cookie Encrypted -- remotely issued |
52 | -> IO (Maybe (SecretKey, HandshakeData)) | 54 | -> IO (Maybe (Multi.SessionAddress, (SecretKey, HandshakeData))) |
53 | getSentHandshake hscache me their_addr (Cookie n24 (Identity cd)) ecookie = do | 55 | getSentHandshake hscache me their_addr (Cookie n24 (Identity cd)) ecookie = do |
54 | now <- getPOSIXTime | 56 | now <- getPOSIXTime |
55 | io <- atomically $ do | 57 | io <- atomically $ do |
56 | m <- checkExpiry now . MM.lookup' n24 <$> readTVar (hscTable hscache) | 58 | m <- checkExpiry now . MM.lookup' n24 <$> readTVar (hscTable hscache) |
57 | case m of | 59 | case m of |
58 | Just s -> return $ return $ Just s | 60 | Just s -> return $ return $ Just (their_addr, s) |
59 | Nothing -> do | 61 | Nothing -> do |
60 | let them = longTermKey cd | 62 | let them = longTermKey cd |
61 | case Multi.nodeInfo (key2id $ dhtKey cd) their_addr of | 63 | case Multi.nodeInfo (key2id $ dhtKey cd) their_addr of |
@@ -64,8 +66,8 @@ getSentHandshake hscache me their_addr (Cookie n24 (Identity cd)) ecookie = do | |||
64 | (s,hs) <- cacheHandshakeSTM hscache me them their_node ecookie now | 66 | (s,hs) <- cacheHandshakeSTM hscache me them their_node ecookie now |
65 | return $ do | 67 | return $ do |
66 | dput XNetCrypto $ "getSentHandshake sending new handshake." | 68 | dput XNetCrypto $ "getSentHandshake sending new handshake." |
67 | hscSend hscache their_addr hs | 69 | addr' <- hscSend hscache their_addr hs |
68 | return $ Just s | 70 | return $ Just (addr', s) |
69 | r <- io | 71 | r <- io |
70 | dput XNetCrypto $ "getSentHandshake me="++show (key2id $ toPublic me)++" their_addr="++show their_addr++" --> " ++ show r | 72 | dput XNetCrypto $ "getSentHandshake me="++show (key2id $ toPublic me)++" their_addr="++show their_addr++" --> " ++ show r |
71 | return r | 73 | return r |