aboutsummaryrefslogtreecommitdiffstats
path: root/src/Network/WireGuard
diff options
context:
space:
mode:
authorBaylac-Jacqué Félix <felix@alternativebit.fr>2017-08-10 16:51:07 +0200
committerBaylac-Jacqué Félix <felix@alternativebit.fr>2017-09-16 17:08:52 +0200
commit4441702b47ddfb0e862ccc3fa5caa00c5acc8aaf (patch)
treecc56a63e7365eb3e349a59f91d0bf8446052e549 /src/Network/WireGuard
parentRefactor project structure to exec + lib. (diff)
downloadwireguard-hs-4441702b47ddfb0e862ccc3fa5caa00c5acc8aaf.tar.xz
wireguard-hs-4441702b47ddfb0e862ccc3fa5caa00c5acc8aaf.zip
Setup travis CI.
Diffstat (limited to 'src/Network/WireGuard')
-rw-r--r--src/Network/WireGuard/RPC.hs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/Network/WireGuard/RPC.hs b/src/Network/WireGuard/RPC.hs
index 7ecb8de..3aa4e44 100644
--- a/src/Network/WireGuard/RPC.hs
+++ b/src/Network/WireGuard/RPC.hs
@@ -1,7 +1,8 @@
{-# LANGUAGE RecordWildCards #-}
module Network.WireGuard.RPC
- ( runRPC
+ ( runRPC,
+ serveConduit
) where
import Control.Concurrent.STM (STM, atomically,
@@ -31,16 +32,20 @@ import Network.WireGuard.Foreign.UAPI
import Network.WireGuard.Internal.Constant
import Network.WireGuard.Internal.State
import Network.WireGuard.Internal.Types
-import Network.WireGuard.Internal.Util
+import Network.WireGuard.Internal.Util (catchIOExceptionAnd,
+ catchSomeExceptionAnd)
+import Debug.Trace
-- | Run RPC service over a unix socket
runRPC :: FilePath -> Device -> IO ()
runRPC sockPath device = runUnixServer (serverSettings sockPath) $ \app ->
- catchIOExceptionAnd (return ()) $ runConduit (appSource app =$= serveConduit =$= appSink app)
- where
- -- TODO: ensure that all bytestring over sockets will be erased
- serveConduit = do
+ catchIOExceptionAnd (return ()) $ runConduit (appSource app .| serveConduit device .| appSink app)
+
+-- TODO: ensure that all bytestring over sockets will be erased
+serveConduit :: Device -> ConduitM BS.ByteString BS.ByteString IO ()
+serveConduit device = do
h <- CB.head
+ traceM $ "Received " ++ show h
case h of
Just 0 -> showDevice device
Just byte -> do
@@ -50,7 +55,7 @@ runRPC sockPath device = runUnixServer (serverSettings sockPath) $ \app ->
Just wgdev -> catchSomeExceptionAnd returnError (updateDevice wgdev)
Nothing -> mempty
Nothing -> mempty
-
+ where
returnError = yield $ writeConfig (-invalidValueError)
showDevice Device{..} = do