runClientServer clientProto serverProto testFiles = runResourceT $ do

  liftIO $ updateGlobalLogger logger  (setLevel DEBUG)
  liftIO $ updateGlobalLogger Tracker.logger  (setLevel DEBUG)

  liftIO $ debugM logger "running integration test"

  let [serverCache, serverUTClientPath] = makePaths "server"
  let [clientCache, clientUTClientPath] = makePaths "client"

  contacts <- forM testFiles $ \testFile -> liftIO $ makeContactFile (metadata testFile)
  (serverDesc, serverSk)
    <- liftIO $ makeServerDescriptor contacts localhostIP

  -- launch the tracker
  trackEvents <- liftIO $ newTChanIO
  tracker <- allocAsync $ async $ Tracker.runTracker
                      $ Tracker.Config { Tracker.listenPort = 6666
                                         , Tracker.events = Just trackEvents}
  liftIO $ waitFor (== Tracker.Booting) trackEvents

  serverDone <- liftIO $ newGate
  clientDone <- liftIO $ newGate

  allocAsync $ async $ runServer (\c -> serverProto c
                                        `finally` (atomically $ openGate serverDone))
                                 serverUTClientPath serverCache contacts
                                       (serverDesc, serverSk)

  liftIO $ debugM logger "booted server.."

--  liftIO $ threadDelay $ 10 ^ 9

  liftIO $ waitFor (\(Tracker.AnnounceEv a) -> True) trackEvents
  liftIO $ debugM logger "tracker got announce from the server"

  liftIO $ debugM logger "running client now"

  allocAsync $ async $ runClient (\ c -> clientProto c
                                         `finally` (atomically $ openGate clientDone))
                                 clientUTClientPath clientCache serverDesc

  liftIO $ atomically $ goThroughGate clientDone
  liftIO $ atomically $ goThroughGate serverDone
  -- liftIO $ threadDelay $ 10 ^ 9

  liftIO $ debugM logger "finished running integration test" 
  return ()


 -- UTORRENT based client and server 
runClientServer clientProto serverProto testFiles = runResourceT $ do

  liftIO $ updateGlobalLogger logger  (setLevel DEBUG)
  liftIO $ updateGlobalLogger Tracker.logger  (setLevel DEBUG)

  liftIO $ debugM logger "running integration test"

  let [serverCache, serverUTClientPath] = makePaths "server"
  let [clientCache, clientUTClientPath] = makePaths "client"

  contacts <- forM testFiles $ \testFile -> liftIO $ makeContactFile (metadata testFile)
  (serverDesc, serverSk)
    <- liftIO $ makeServerDescriptor contacts localhostIP

  -- launch the tracker
  trackEvents <- liftIO $ newTChanIO
  tracker <- allocAsync $ async $ Tracker.runTracker
                      $ Tracker.Config { Tracker.listenPort = 6666
                                         , Tracker.events = Just trackEvents}
  liftIO $ waitFor (== Tracker.Booting) trackEvents

  serverDone <- liftIO $ newGate
  clientDone <- liftIO $ newGate

  allocAsync $ async $ runServer (\c -> serverProto c
                                        `finally` (atomically $ openGate serverDone))
                                 serverUTClientPath serverCache contacts
                                       (serverDesc, serverSk)

  liftIO $ debugM logger "booted server.."

--  liftIO $ threadDelay $ 10 ^ 9

  liftIO $ waitFor (\(Tracker.AnnounceEv a) -> True) trackEvents
  liftIO $ debugM logger "tracker got announce from the server"

  liftIO $ debugM logger "running client now"

  allocAsync $ async $ runClient (\ c -> clientProto c
                                         `finally` (atomically $ openGate clientDone))
                                 clientUTClientPath clientCache serverDesc

  liftIO $ atomically $ goThroughGate clientDone
  liftIO $ atomically $ goThroughGate serverDone
  -- liftIO $ threadDelay $ 10 ^ 9

  liftIO $ debugM logger "finished running integration test" 
  return ()


 -- UTORRENT based client and server 
runClientServer clientProto serverProto testFiles = runResourceT $ do

  liftIO $ updateGlobalLogger logger  (setLevel DEBUG)
  liftIO $ updateGlobalLogger Tracker.logger  (setLevel DEBUG)

  liftIO $ debugM logger "running integration test"

  let [serverCache, serverUTClientPath] = makePaths "server"
  let [clientCache, clientUTClientPath] = makePaths "client"

  contacts <- forM testFiles $ \testFile -> liftIO $ makeContactFile (metadata testFile)
  (serverDesc, serverSk)
    <- liftIO $ makeServerDescriptor contacts localhostIP

  -- launch the tracker
  trackEvents <- liftIO $ newTChanIO
  tracker <- allocAsync $ async $ Tracker.runTracker
                      $ Tracker.Config { Tracker.listenPort = 6666
                                         , Tracker.events = Just trackEvents}
  liftIO $ waitFor (== Tracker.Booting) trackEvents

  serverDone <- liftIO $ newGate
  clientDone <- liftIO $ newGate

  allocAsync $ async $ runServer (\c -> serverProto c
                                        `finally` (atomically $ openGate serverDone))
                                 serverUTClientPath serverCache contacts
                                       (serverDesc, serverSk)

  liftIO $ debugM logger "booted server.."

--  liftIO $ threadDelay $ 10 ^ 9

  liftIO $ waitFor (\(Tracker.AnnounceEv a) -> True) trackEvents
  liftIO $ debugM logger "tracker got announce from the server"

  liftIO $ debugM logger "running client now"

  allocAsync $ async $ runClient (\ c -> clientProto c
                                         `finally` (atomically $ openGate clientDone))
                                 clientUTClientPath clientCache serverDesc

  liftIO $ atomically $ goThroughGate clientDone
  liftIO $ atomically $ goThroughGate serverDone
  -- liftIO $ threadDelay $ 10 ^ 9

  liftIO $ debugM logger "finished running integration test" 
  return ()


 -- UTORRENT based client and server 