Skip to content

Commit

Permalink
chore: update tailscalemanager
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyanio committed Dec 5, 2024
1 parent 9660a20 commit 46b0bc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Create a configuration file in either JSON or YAML format. Here’s an example:
"hostRoutes": [
"github.com",
"private-app.example.com"
],̌
],
"awsManagedPrefixLists": [
"pl-02761f4a40454a3c9"
]
Expand Down
15 changes: 11 additions & 4 deletions src/TailscaleManager.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE QuasiQuotes #-}
-- | Tailscale Routes Manager

module TailscaleManager where

Expand All @@ -14,6 +14,7 @@ import Prettyprinter (Doc)
import System.Log.Logger
import System.Process (callProcess, showCommandForUser)
import Text.RawString.QQ (r)

import TailscaleManager.Config
import TailscaleManager.Discovery.AWSManagedPrefixList (resolveAllPrefixLists)
import TailscaleManager.Discovery.DNS (resolveHostnamesToRoutes)
Expand Down Expand Up @@ -119,7 +120,7 @@ runOnce options prevRoutes = do
logL logger DEBUG ("Sleeping for " ++ show (interval options) ++ " seconds")
threadDelay (interval options * 1000000) -- microseconds

config <- TailscaleManager.Config.loadConfig (configFile options)
config <- loadConfig (configFile options)
newRoutes <- generateRoutes config

logDiff prevRoutes newRoutes
Expand Down Expand Up @@ -153,8 +154,14 @@ logDiff prevRoutes newRoutes = do
routesToRemove = S.difference prevRoutes newRoutes
routesUnchanged = S.intersection prevRoutes newRoutes

-- | Compute how much smaller the new set is vs old.
shrinkRatio :: Foldable t => t a -> t a -> Double
-- |Compute how much the smaller the new set is vs old.
--
-- >>> shrinkRatio ["1.1.1.1/32", "2.2.2.2/32"] ["1.1.1.1/32"]
-- 0.5
shrinkRatio :: Foldable t
=> t a -- ^ Old set
-> t a -- ^ New set
-> Double -- ^ Shrink ratio
shrinkRatio old new = 1 - (1 / (fromIntegral (length old) / fromIntegral (length new)))

-- | Generate routes based on config, resolving hostnames and AWS-managed prefix lists.
Expand Down

0 comments on commit 46b0bc6

Please sign in to comment.