Skip to content

Commit

Permalink
polish code
Browse files Browse the repository at this point in the history
  • Loading branch information
accelas committed Jun 29, 2013
1 parent 6ff23cd commit 3069c1a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/socks5.hs
@@ -1,15 +1,15 @@
import Data.ByteString as B (ByteString)
import Data.ByteString.Lazy as BL (toStrict)

import Control.Concurrent.Async
import Data.Binary as Bin (Binary, encode)
import Data.Monoid
import Debug.Trace
import Control.Concurrent.Async
import Debug.Trace

import Control.Proxy as P
import qualified Control.Proxy.Binary as P
import qualified Control.Proxy.Parse as P (wrap)
import qualified Control.Proxy.TCP as P (serve, HostPreference(..), connect, socketReadS, socketWriteD)
import Control.Proxy.TCP as P
import Control.Proxy.Trans.Either as P (EitherP, runEitherK)
import Control.Proxy.Trans.State as P (StateP, evalStateK)

Expand All @@ -25,6 +25,7 @@ handshake () = do
AuthMSG (_, _) <- P.decode
P.respond $ toStrictByteString authSuccess
CmdMSG (_, dst) <- P.decode
-- todo: send response After connection success
P.respond $ toStrictByteString $ connSuccess dst
return dst

Expand All @@ -41,8 +42,10 @@ main = P.serve (P.Host "127.0.0.1") "8000" $ \(cs, caddr) -> trace ("request fro
P.wrap . P.socketReadS 4096 cs >-> handshake >-> P.socketWriteD cs

case res of

-- todo, if decoding cmd msg fails, it should be sending authError
Left _ -> sendMsg authError
Right dst -> trace ("connecting " ++ host ++ ":" ++ port) $
Right dst -> trace ("connecting " ++ host ++ ":" ++ port) $
P.connect host port $ \(ss, _ ) -> trace ("connetion established") $ do
s1 <- async (runProxy $ P.socketReadS 4096 cs >-> P.socketWriteD ss)
s2 <- async (runProxy $ P.socketReadS 4096 ss >-> P.socketWriteD cs)
Expand Down

0 comments on commit 3069c1a

Please sign in to comment.