Permalink
Browse files

polish code

  • Loading branch information...
1 parent 6ff23cd commit 3069c1a93156676203e253096241a0f4085a6f59 @accelas committed Jun 29, 2013
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/socks5.hs
View
11 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)
@@ -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
@@ -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)

0 comments on commit 3069c1a

Please sign in to comment.