packages feed

moesocks 0.1.2.30 → 1.0.0.0

raw patch · 11 files changed

+100/−132 lines, 11 files

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+1.0.0.0+-------+* Tag a stable release, clean up types+ 0.1.2.30 -------- * Refactor internal to make a runtime independent of Config and Options
README.md view
@@ -1,4 +1,5 @@ MoeSocks+ ========  A SOCKS5 proxy using the client / server architecture.@@ -8,14 +9,14 @@ Installation ============ -* Need `GHC 7.10.2`.+* Need `GHC 7.10.2` on Linux.  Usage =====  * Download a sample [config.json] to your current path -* Edit `config.json` to fit your setup (at least the `remote` and `password`+* Edit `config.json` to fit your setup (at least the `remoteHost` and `password`   fields)  * Start a remote node outside a firewall:@@ -56,8 +57,10 @@ ==========  * UDP over SOCKS5 is not implemented.+* TCP bind over SOCKS5 is not implemented. * More then 2 times slower then the original Python implementation (measured at-  20M/s vs 43M/s on an Intel P8800, using the AES-256-CFB method).+  20M/s vs 43M/s on an Intel P8800, using the AES-256-CFB method, in software+  AES). * Currently only works on Linux.  
moesocks.cabal view
@@ -1,6 +1,6 @@ name:               moesocks category:           Network-version:            0.1.2.30+version:            1.0.0.0 license:            Apache-2.0 synopsis:           A functional firewall killer description:        A SOCKS5 proxy using the client / server architecture.@@ -13,7 +13,7 @@ copyright:          Copyright (C) 2015 Jinjing Wang tested-with:        GHC == 7.10.2 -extra-source-files:     config.json+extra-doc-files:        config.json                       , README.md                       , CHANGELOG.md 
src/Network/MoeSocks/App.hs view
@@ -16,28 +16,6 @@ import qualified Network.MoeSocks.Type.Bootstrap.Option as O  -{-runJob :: Env -> Job -> TVar JobStatus -> IO ()-}-{-runJob aEnv (RemoteRelayJob x) _ = runRemoteRelay aEnv x-}-{-runJob aEnv (LocalServiceJob x) _ = runLocalService aEnv x-}--{-runApp :: Env -> [Job] -> IO ()-}-{-runApp aEnv someJobs = do-}-  {-_jobs <- (forM someJobs - \_job -> (,) _job-}-                                      {-<$> newTVarIO initialJobStatus)-}-  {-_asyncs <- mapM (async . foreverRun . (uncurry (runJob aEnv))) _jobs-}--  {-_mainThread <- async - do-}-    {-waitAnyCancel - _asyncs-}--  {-_uiThread <- async - forever - do-}-    {-let _statuses = _jobs ^.. each . _2 :: [TVar JobStatus]-}-    {-[>forM_ _statuses - readTVarIO >=> print<]-}-    {-sleep 5-}--  {-waitAnyCancel [_mainThread, _uiThread]-}--  {-pure ()-}- runJob :: Env -> Job -> IO () runJob aEnv (RemoteRelayJob x)  = runRemoteRelay aEnv x runJob aEnv (LocalServiceJob x)  = runLocalService aEnv x@@ -55,6 +33,6 @@   let _options = someOptions   _config <- loadConfig - _options -  (_runtime, _jobs) <- initRuntime _config _options +  _runtime <- initRuntime _config _options  -  io - runApp (_runtime ^. env) _jobs+  io - runApp (_runtime ^. env) (_runtime ^. jobs)
src/Network/MoeSocks/Bootstrap.hs view
@@ -123,7 +123,7 @@     Nothing -> do       let _r =             execWriter - do-              tell "\n\n"+              tell "\n"               case _maybeFilePath of                 Just _filePath -> do                                     tell "Failed to parse configuration file: "@@ -135,6 +135,10 @@                             tell "The password argument '-k' is required.\n"                             tell "Alternatively, use '-c' to provide a "                             tell "configuration file.\n"+                            tell "\n"+                            tell "Use '-h' to show help text"++              tell "\n"        throwError - _r ^. _Text 
src/Network/MoeSocks/BuilderAndParser.hs view
@@ -22,7 +22,7 @@  _No_authentication :: Word8 _No_authentication = 0-              + _Request_Granted :: Word8 _Request_Granted = 0 @@ -46,9 +46,9 @@  sockAddr_To_Pair :: SockAddr -> (AddressType, Port) sockAddr_To_Pair aSockAddr = case aSockAddr of-  SockAddrInet _port _host -> -                                    let -                                        _r@(_a, _b, _c, _d) = +  SockAddrInet _port _host ->+                                    let+                                        _r@(_a, _b, _c, _d) =                                           decode . runPut . put - _host                                           :: (Word8, Word8, Word8, Word8)                                     in@@ -58,8 +58,8 @@                                     )    SockAddrInet6 _port _ _host _ ->-                                    let -                                        _r@(_a, _b, _c, _d, _e, _f, _g, _h) = +                                    let+                                        _r@(_a, _b, _c, _d, _e, _f, _g, _h) =                                           decode . runPut . put - _host                                           :: (Word16, Word16, Word16, Word16                                               , Word16, Word16, Word16, Word16)@@ -69,11 +69,11 @@                                     , fromIntegral _port                                     ) -  SockAddrUnix x -> +  SockAddrUnix x ->                                     let                                         _host = P.takeWhile (/= ':') x-                                        _port = x & reverse -                                                  & P.takeWhile (/= ':') +                                        _port = x & reverse+                                                  & P.takeWhile (/= ':')                                                   & reverse                                     in @@ -81,40 +81,40 @@                                     , fromMaybe 0 - _port ^? _Show                                     ) -  x -> -                                    error - "SockAddrCan not implemented: " -                                            <> show x +  x ->+                                    error - "SockAddrCan not implemented: "+                                            <> show x   portBuilder :: (Integral i) => i -> B.Builder portBuilder i =-  let _i = fromIntegral i :: Word16 +  let _i = fromIntegral i :: Word16   in   foldMapOf both B.word8 -     (decode - runPut - put _i :: (Word8, Word8))  connectionReplyBuilder :: SockAddr -> B.Builder-connectionReplyBuilder aSockAddr = +connectionReplyBuilder aSockAddr =   let _r@(__addressType, _port) = sockAddr_To_Pair aSockAddr   in       B.word8 socksVersion-  <>  B.word8 _Request_Granted +  <>  B.word8 _Request_Granted   <>  B.word8 _ReservedByte   <>  addressTypeBuilder __addressType   <>  portBuilder _port  addressTypeBuilder :: AddressType -> B.Builder-addressTypeBuilder aAddressType = +addressTypeBuilder aAddressType =   case aAddressType of-    IPv4_Address _address -> +    IPv4_Address _address ->                           B.word8 1                        <> foldMapOf each B.word8 _address-    DomainName x ->   +    DomainName x ->                           B.word8 3                        <> B.word8 (fromIntegral (S.length (review utf8 x)))                        <> B.byteString (review utf8 x) -    IPv6_Address _address ->  +    IPv6_Address _address ->                           B.word8 4                        <> foldMapOf each B.word16BE _address @@ -128,7 +128,7 @@   requestBuilder :: ClientRequest -> B.Builder-requestBuilder aClientRequest = +requestBuilder aClientRequest =       B.word8 (connectionType_To_Word8 - aClientRequest ^. connectionType)   <>  B.word8 _ReservedByte   <>  addressTypeBuilder (aClientRequest ^. addressType)@@ -169,7 +169,7 @@ requestParser = do   __connectionType <- choice       [-        TCP_IP_StreamConnection <$ word8 1 +        TCP_IP_StreamConnection <$ word8 1       {-, TCP_IP_PortBinding <$ word8 2-}       , UDP_Port <$ word8 3       ]@@ -177,13 +177,13 @@   word8 _ReservedByte   __addressType <- addressTypeParser   __portNumber <- portParser-  pure - +  pure -           ClientRequest             __connectionType-            __addressType +            __addressType             __portNumber -connectionParser :: Parser ClientRequest +connectionParser :: Parser ClientRequest connectionParser = do   socksHeader   requestParser@@ -203,16 +203,16 @@                         _a <- anyWord8                         _b <- anyWord8                         _c <- anyWord8-                        _d <- anyWord8 +                        _d <- anyWord8                         pure - (_a, _b, _c, _d)-  -  , DomainName <$>   do ++  , DomainName <$>   do                         word8 3                         _nameLength <- anyWord8                         view utf8 <$> (take - fromIntegral _nameLength)    , IPv6_Address <$>  do-                        word8 4 +                        word8 4                         _r <- count 8 anyWord16                         {-pure - trace ("parsed IPv6: " <> show _r) _r-}                         pure _r@@ -224,8 +224,8 @@   _addressType <- addressTypeParser   _portNumber <- portParser -  pure - +  pure -           ClientRequest-            _connectionType -            _addressType +            _connectionType+            _addressType             _portNumber
src/Network/MoeSocks/Common.hs view
@@ -77,7 +77,7 @@ initTarget _clientRequest = do   let       _socketType = _clientRequest ^. connectionType . re _SocketType-      _hostName   = _clientRequest ^. addressType . to show . from _Text+      _hostName   = _clientRequest ^. addressType . to show . re _Text       _port       = _clientRequest ^. portNumber       _family     = _clientRequest ^. addressType . to addressType_To_Family   
src/Network/MoeSocks/Helper.hs view
@@ -188,7 +188,7 @@  connectTunnel :: (Maybe String, IO ()) -> (Maybe String, IO ()) -> IO () connectTunnel x y = -  let _prolong _io = _io >> sleep 10+  let _prolong _io = _io >> sleep 5   in    race_ (_prolong - logWaitIO x) 
src/Network/MoeSocks/Options.hs view
@@ -18,11 +18,11 @@ import System.Log.Logger import qualified Data.Text as T import qualified Options.Applicative as O-import Data.Attoparsec.Text (Parser, takeWhile, char, decimal, skipSpace, +import Data.Attoparsec.Text (Parser, takeWhile, char, decimal, skipSpace,                               parseOnly, many', choice)  textOption :: O.Mod O.OptionFields String -> O.Parser Text-textOption x = strOption x <&> view (from _Text)+textOption x = strOption x <&> review _Text  defaultHelp :: Text -> Text -> Mod f a defaultHelp val x = help - x <> ", default: " <> val & view _Text@@ -41,18 +41,18 @@ boolParam = (fmap . fmap) toJSON . fmap bool_To_Maybe . switch  optionParser :: O.Parser Options-optionParser = +optionParser =   let _c = defaultConfig       _mode = ( textOption -                     short 'r'                 <>  long "role"                 <>  metavar "ROLE"-                <>  defaultHelp "local" +                <>  defaultHelp "local"                                 "Tell moesocks to run as local or remote"-              ) <|> pure "local" -  +              ) <|> pure "local"+       parseMode :: Text -> RunningMode-      parseMode x +      parseMode x         | x `elem` ["server", "remote"] = RemoteMode         | x `elem` ["client", "local"] = LocalMode         | x == "debug" = DebugMode@@ -63,18 +63,18 @@                       long "disable-socks5"                   <>  help ("Do not start a SOCKS5 server on local. It can be "                           <> "useful to run moesocks only as a secure tunnel")-      +       _listMethods :: O.Parser Bool       _listMethods = switch -                       long "list-methods"                   <>  help "Show supported encryption methods"-                  +       _tcpBufferSize = intParam -                               long "tcp-buffer-size"                           <>  metavar "SIZE"                           <>  defaultHelp (_c ^. C.tcpBufferSize                                             & show-                                            & view (from _Text))+                                            & review _Text)                                           ("The number of packets used as a "                                             <> "buffer. A packet can hold "                                             <> "at most 4K of data")@@ -84,22 +84,22 @@                   <>  long "config"                   <>  metavar "CONFIG"                   <>  help "Set the path of the configuration file"-                 -      _remote = textParam -++      _remoteHost = textParam -                       short 's'                   <>  metavar "REMOTE"                   <>  defaultHelp (_c ^. C.remoteHost)                                   "remote address"-  +       _remotePort = intParam -                           short 'p'                       <>  metavar "REMOTE_PORT"-                      <>  defaultHelp (_c ^. C.remotePort -                                          & show -                                          & view (from _Text))+                      <>  defaultHelp (_c ^. C.remotePort+                                          & show+                                          & review _Text)                                       "remote port" -      _local = textParam -+      _localHost = textParam -                       short 'b'                   <>  metavar "LOCAL"                   <>  defaultHelp (_c ^. C.localHost)@@ -110,7 +110,7 @@                     <>  metavar "LOCAL PORT"                     <>  defaultHelp (_c ^. C.localPort                                         & show-                                        & view (from _Text))+                                        & review _Text)                                     "local port"        _password = textParam -@@ -124,19 +124,19 @@                     <> defaultHelp (_c ^. C.method)                                     "encryption method" -      _timeout  = intParam - +      _timeout  = intParam -                         short 't'                     <>  metavar "TIMEOUT"                     <>  defaultHelp (_c ^. C.timeout                                         & show-                                        & view (from _Text))+                                        & review _Text)                                     "Timeout connection in seconds"-                        +       _fastOpen = boolParam -                         long "fast-open"                     <>  help ("Use TCP_FASTOPEN, requires Linux 3.7+")-      -      _obfuscation :: O.Parser Bool ++      _obfuscation :: O.Parser Bool       _obfuscation = switch -                           short 'o'                       <>  long "obfuscation"@@ -146,7 +146,7 @@                                <> "about 10-20% performance degradation.")  -      _verbosity :: O.Parser Priority +      _verbosity :: O.Parser Priority       _verbosity = flag INFO DEBUG -                           short 'v'                       <>  long "verbose"@@ -163,9 +163,9 @@                                 <> "(client) host is to be forwarded to the "                                 <> "given host and port on the remote side."                                 )-    +       _forwardUDP :: O.Parser (Maybe Text)       _forwardUDP = optional - textOption -                           short 'U'@@ -177,16 +177,16 @@                                 <> "(client) host is to be forwarded to the "                                 <> "given host and port on the remote side."                                 )-  +       forwardParser ::  Parser Forward       forwardParser = do         skipSpace         _forwardPort <- decimal         char ':'-        _forwardRemoteHost <- +        _forwardRemoteHost <-           choice             [-              do +              do                 char '['                 _h <- takeWhile (/= ']')                 char ']'@@ -196,7 +196,7 @@         char ':'         _forwardRemotePort <- decimal -        pure - Forward  +        pure - Forward                         _forwardPort                         _forwardRemoteHost                         _forwardRemotePort@@ -206,7 +206,7 @@        parseForwarding :: Maybe Text -> [Forward]       parseForwarding x = x ^. _Just-          & parseOnly forwardListParser +          & parseOnly forwardListParser           & toListOf (traverse . traverse)        _forbidden_IPs :: O.Parser (Maybe Text)@@ -215,18 +215,18 @@                       <>  metavar "IPLIST"                       <>  defaultHelp (defaultOptions ^. forbidden_IPs                                         & map show-                                        & map (view - from _Text)+                                        & map (review _Text)                                         & T.intercalate ", ")                                 (""                                 <> "comma seperated IP list forbidden to "                                 <> "connect"                                 )-     +       parseForbidden_IP :: Maybe Text -> [IPRange]       parseForbidden_IP = maybe (defaultOptions ^. forbidden_IPs) --                                (toListOf - each -                                          . to T.strip -                                          . _Text +                                (toListOf - each+                                          . to T.strip+                                          . _Text                                           . _Show                                 ) . T.splitOn "," @@ -236,25 +236,25 @@         _params :: O.Parser [(Text, Value)]-      _params = -        [ tag "_remoteHost"         _remote    +      _params =+        [ tag "_remoteHost"     _remoteHost         , tag "_remotePort"     _remotePort-        , tag "_localHost"          _local     -        , tag "_localPort"      _localPort +        , tag "_localHost"      _localHost+        , tag "_localPort"      _localPort         , tag "_password"       _password-        , tag "_method"         _method +        , tag "_method"         _method         , tag "_timeout"        _timeout         , tag "_tcpBufferSize"  _tcpBufferSize         , tag "_fastOpen"       _fastOpen         ]         & sequenceA         & fmap catMaybes-          +   in-         -  Options -              <$> fmap parseMode _mode ++  Options+              <$> fmap parseMode _mode               <*> _config               <*> _verbosity               <*> fmap parseForwarding _forwardTCP@@ -266,8 +266,7 @@               <*> _params  opts :: ParserInfo Options-opts = info (helper <*> optionParser) - +opts = info (helper <*> optionParser) -         fullDesc     <>  progDesc "A SOCKS5 proxy using the client / server architecture"     <>  header "A functional firewall killer"-
src/Network/MoeSocks/Runtime.hs view
@@ -109,7 +109,7 @@    pure - _env -initRuntime :: C.Config -> O.Options -> ExceptT String IO (Runtime, [Job])+initRuntime :: C.Config -> O.Options -> ExceptT String IO (Runtime) initRuntime aConfig someOptions = do   let _c = aConfig       _o = someOptions@@ -132,5 +132,5 @@    pure -  ( defaultRuntime               & env .~ _env'-          , _jobs+              & jobs .~ _jobs           )
src/Network/MoeSocks/Type/Runtime.hs view
@@ -3,8 +3,6 @@  module Network.MoeSocks.Type.Runtime where -import Control.Concurrent.Async-import Control.Concurrent.STM import Control.Lens import Control.Monad.Except import Data.ByteString (ByteString)@@ -122,24 +120,6 @@  makePrisms ''Job -type Async_ID = Async ()--data JobStatus = JobStatus-      {-        _incomingSpeed :: Double-      , _incomingTotal :: Double-      , _outgoingSpeed :: Double-      , _outgoingTotal :: Double-      , _numberOfRequests :: Int-      }-      deriving (Show, Eq)--makeLenses ''JobStatus--initialJobStatus :: JobStatus-initialJobStatus = JobStatus 0 0 0 0 0-- data Env = Env   {     _timeout :: Int@@ -160,7 +140,7 @@  data Runtime = Runtime   {-    _jobs :: [(Job, Async_ID, TVar JobStatus)]+    _jobs :: [Job]   , _env :: Env   }