From 8d094413e88b57dc71f60fb48631fe43174dc696 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Wed, 26 Feb 2014 21:09:46 +0400 Subject: Check udp tracker manager options --- src/Network/BitTorrent/Tracker/RPC/UDP.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/Network/BitTorrent/Tracker/RPC/UDP.hs b/src/Network/BitTorrent/Tracker/RPC/UDP.hs index b0f44ec6..a2099ef0 100644 --- a/src/Network/BitTorrent/Tracker/RPC/UDP.hs +++ b/src/Network/BitTorrent/Tracker/RPC/UDP.hs @@ -118,6 +118,20 @@ instance Default Options where , optMultiplier = defMultiplier } +checkOptions :: Options -> IO () +checkOptions Options {..} = do + unless (optMaxPacketSize > 0) $ do + throwIO $ userError "optMaxPacketSize must be positive" + + unless (optMinTimeout > 0) $ do + throwIO $ userError "optMinTimeout must be positive" + + unless (optMaxTimeout > 0) $ do + throwIO $ userError "optMaxTimeout must be greater than optMinTimeout" + + unless (optMinTimeout > 0) $ do + throwIO $ userError "optMinTimeout must be positive" + {----------------------------------------------------------------------- -- Manager state -----------------------------------------------------------------------} @@ -162,8 +176,10 @@ resetState Manager {..} = do where err = error "UDP tracker manager closed" +-- | This function will throw 'IOException' if or newManager :: Options -> IO Manager newManager opts = do + checkOptions opts mgr <- initManager opts tid <- forkIO (listen mgr `finally` resetState mgr) putMVar (listenerThread mgr) tid -- cgit v1.2.3