aboutsummaryrefslogtreecommitdiffstats
path: root/src/Network/WireGuard/Internal/State.hs
diff options
context:
space:
mode:
authorBin Jin <bjin@ctrl-d.org>2017-03-14 21:18:00 +0800
committerBin Jin <bjin@ctrl-d.org>2017-03-14 21:18:00 +0800
commita60988db82aed029b71531e8a4bc5698fa247c02 (patch)
treebcf9432ac5b0ee14c8e89fb0a4c7e0eece013616 /src/Network/WireGuard/Internal/State.hs
parentRemove unused language extension pragma (diff)
downloadwireguard-hs-a60988db82aed029b71531e8a4bc5698fa247c02.tar.xz
wireguard-hs-a60988db82aed029b71531e8a4bc5698fa247c02.zip
Tun: add timestamp for incoming packets
Diffstat (limited to 'src/Network/WireGuard/Internal/State.hs')
-rw-r--r--src/Network/WireGuard/Internal/State.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Network/WireGuard/Internal/State.hs b/src/Network/WireGuard/Internal/State.hs
index 38866e8..f7b1ca0 100644
--- a/src/Network/WireGuard/Internal/State.hs
+++ b/src/Network/WireGuard/Internal/State.hs
@@ -193,12 +193,18 @@ getSession peer = do
[] -> return Nothing
(s:_) -> return (Just s)
-waitForSession :: Peer -> STM Session
-waitForSession peer = do
- sessions' <- readTVar (sessions peer)
- case sessions' of
- [] -> retry
- (s:_) -> return s
+waitForSession :: Int -> Peer -> IO (Maybe Session)
+waitForSession timelimit peer = do
+ getTimeout <- registerDelay timelimit
+ atomically $ do
+ sessions' <- readTVar (sessions peer)
+ case sessions' of
+ [] -> do
+ timeout <- readTVar getTimeout
+ if timeout
+ then return Nothing
+ else retry
+ (s:_) -> return (Just s)
findSession :: Peer -> Index -> STM (Maybe (Either ResponderWait Session))
findSession peer index = do