Skip to content

Commit

Permalink
Plumb the MaxMetadataSize parameter through to the server (#134)
Browse files Browse the repository at this point in the history
* Plumb the `maxMetadataSize` parameter through to the server

* Update `proto3-suite` dependency

* Bump proto3-wire to 1.2.2

* Re-generate Echo.hs

* Regenerate `Arithmetic.hs`

* Derp

* Fix codegen

* Update the tests for new codegen

* Patch-bump to `0.2.1`

* Bump to `0.3.0` to indicate a breaking API change...

Suggested by @intractable.
  • Loading branch information
ixmatus authored Feb 25, 2022
1 parent e1091b9 commit 1127770
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 48 deletions.
2 changes: 1 addition & 1 deletion core/grpc-haskell-core.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: grpc-haskell-core
version: 0.2.0
version: 0.3.0
synopsis: Haskell implementation of gRPC layered on shared C library.
homepage: https://github.com/awakenetworks/gRPC-haskell
license: Apache-2.0
Expand Down
13 changes: 7 additions & 6 deletions examples/echo/echo-hs/Echo.hs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions examples/tutorial/Arithmetic.hs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions grpc-haskell.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: grpc-haskell
version: 0.2.0
version: 0.3.0
synopsis: Haskell implementation of gRPC layered on shared C library.
homepage: https://github.com/awakenetworks/gRPC-haskell
license: Apache-2.0
Expand Down Expand Up @@ -29,9 +29,9 @@ library
build-depends:
base >=4.8 && <5.0
, bytestring ==0.10.*
, proto3-suite >=0.4.1
, proto3-wire >=1.2.0
, grpc-haskell-core >=0.2.0
, proto3-suite >=0.4.3
, proto3-wire >=1.2.2
, grpc-haskell-core >=0.2.1
, async >=2.1 && <2.3
, managed >= 1.0.5

Expand Down
19 changes: 10 additions & 9 deletions nix/proto3-suite.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
, base64-bytestring, binary, bytestring, cereal, containers
, contravariant, deepseq, doctest, fetchgit, filepath, foldl
, generic-arbitrary, hashable, haskell-src
, insert-ordered-containers, lens, mtl, neat-interpolation
, insert-ordered-containers, lens, lib, mtl, neat-interpolation
, optparse-applicative, optparse-generic, parsec, parsers, pretty
, pretty-show, proto3-wire, QuickCheck, quickcheck-instances
, range-set-list, safe, stdenv, swagger2, system-filepath, tasty
, tasty-hunit, tasty-quickcheck, text, transformers, turtle, vector
, range-set-list, safe, swagger2, system-filepath, tasty
, tasty-hunit, tasty-quickcheck, text, time, transformers, turtle
, vector
}:
mkDerivation {
pname = "proto3-suite";
version = "0.4.2.0";
version = "0.4.3";
src = fetchgit {
url = "https://github.com/awakesecurity/proto3-suite.git";
sha256 = "0mpy35r6qd1v5sixhy2lqcn5x81rfj4dc079g1kpa4fb1f23dbha";
rev = "0af901f9ef3b9719e08eae4fab8fd700d6c8047a";
sha256 = "0bjqczi6wddxv0n7qmfbrr19ajgq66xdkxx8vfcgbmv8ygma3vlw";
rev = "7af7d76dcf9cc71ddada3aa4a38abf46f65550ca";
fetchSubmodules = true;
};
isLibrary = true;
Expand All @@ -26,7 +27,7 @@ mkDerivation {
hashable haskell-src insert-ordered-containers lens mtl
neat-interpolation parsec parsers pretty pretty-show proto3-wire
QuickCheck quickcheck-instances safe swagger2 system-filepath text
transformers turtle vector
time transformers turtle vector
];
executableHaskellDepends = [
base containers mtl optparse-applicative optparse-generic
Expand All @@ -38,6 +39,6 @@ mkDerivation {
proto3-wire QuickCheck swagger2 tasty tasty-hunit tasty-quickcheck
text transformers turtle vector
];
description = "A low level library for writing out data in the Protocol Buffers wire format";
license = stdenv.lib.licenses.asl20;
description = "A higher-level API to the proto3-wire library";
license = lib.licenses.asl20;
}
17 changes: 6 additions & 11 deletions nix/proto3-wire.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{ mkDerivation, base, bytestring, cereal, containers, deepseq
, doctest, fetchgit, ghc-prim, hashable, parameterized, primitive
, QuickCheck, safe, stdenv, tasty, tasty-hunit, tasty-quickcheck
, text, transformers, unordered-containers, vector
, doctest, ghc-prim, hashable, lib, parameterized, primitive
, QuickCheck, safe, tasty, tasty-hunit, tasty-quickcheck, text
, transformers, unordered-containers, vector
}:
mkDerivation {
pname = "proto3-wire";
version = "1.2.0";
src = fetchgit {
url = "https://github.com/awakesecurity/proto3-wire.git";
sha256 = "062b05ab8icwjxaqrh3wmg8s26m620pigqj3dj6rdx9qas1cq6mi";
rev = "d92ec32ef0f15842b07fb226d8f2d15f36c5fb20";
fetchSubmodules = true;
};
version = "1.2.2";
sha256 = "8d409536a89a0187f0576711966d2ef45d43acab7b6a3a1c5ee12f6d01adbfb9";
libraryHaskellDepends = [
base bytestring cereal containers deepseq ghc-prim hashable
parameterized primitive QuickCheck safe text transformers
Expand All @@ -22,5 +17,5 @@ mkDerivation {
tasty-quickcheck text transformers vector
];
description = "A low-level implementation of the Protocol Buffers (version 3) wire format";
license = stdenv.lib.licenses.asl20;
license = lib.licenses.asl20;
}
5 changes: 4 additions & 1 deletion src/Network/GRPC/HighLevel/Generated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ data ServiceOptions = ServiceOptions
, logger :: String -> IO ()
-- ^ Logging function to use to log errors in handling calls.
, serverMaxReceiveMessageLength :: Maybe Natural
-- ^ Maximum length (in bytes) that the service may receive in a single message
-- ^ Maximum length (in bytes) that the service may receive in a single message.
, serverMaxMetadataSize :: Maybe Natural
-- ^ Maximum metadata size (in bytes) that the service may receive in a single request.
}

defaultServiceOptions :: ServiceOptions
Expand All @@ -95,6 +97,7 @@ defaultServiceOptions = ServiceOptions
, Network.GRPC.HighLevel.Generated.sslConfig = Nothing
, Network.GRPC.HighLevel.Generated.logger = hPutStrLn stderr
, Network.GRPC.HighLevel.Generated.serverMaxReceiveMessageLength = Nothing
, Network.GRPC.HighLevel.Generated.serverMaxMetadataSize = Nothing
}

withGRPCClient :: ClientConfig -> (Client -> IO a) -> IO a
Expand Down
4 changes: 4 additions & 0 deletions src/Network/GRPC/HighLevel/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ data ServerOptions = ServerOptions
, optLogger :: String -> IO ()
-- ^ Logging function to use to log errors in handling calls.
, optMaxReceiveMessageLength :: Maybe Natural
-- ^ Maximum length (in bytes) that the service may receive in a single message.
, optMaxMetadataSize :: Maybe Natural
-- ^ Maximum metadata size (in bytes) that the service may receive in a single request.
}

defaultOptions :: ServerOptions
Expand All @@ -244,6 +247,7 @@ defaultOptions = ServerOptions
, optSSLConfig = Nothing
, optLogger = hPutStrLn stderr
, optMaxReceiveMessageLength = Nothing
, optMaxMetadataSize = Nothing
}

serverLoop :: ServerOptions -> IO ()
Expand Down
2 changes: 2 additions & 0 deletions src/Network/GRPC/HighLevel/Server/Unregistered.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,7 @@ serverLoop ServerOptions{..} =
]
++
foldMap (pure . MaxReceiveMessageLength) optMaxReceiveMessageLength
++
foldMap (pure . MaxMetadataSize) optMaxMetadataSize
, sslConfig = optSSLConfig
}
10 changes: 5 additions & 5 deletions tests/TestClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Test.Tasty.HUnit ((@?=), assertFailure, testCase)
testNormalCall client = testCase "Normal call" $
do randoms <- fromList <$> replicateM 1000 (randomRIO (1, 1000))
let req = SimpleServiceRequest "NormalRequest" randoms
res <- simpleServiceNormalCall client
res <- simpleServicenormalCall client
(ClientNormalRequest req 10 mempty)
case res of
ClientErrorResponse err -> assertFailure ("ClientErrorResponse: " <> show err)
Expand All @@ -48,7 +48,7 @@ testNormalCall client = testCase "Normal call" $
testClientStreamingCall client = testCase "Client-streaming call" $
do iterationCount <- randomRIO (5, 50)
v <- newEmptyMVar
res <- simpleServiceClientStreamingCall client . ClientWriterRequest 10 mempty $ \send ->
res <- simpleServiceclientStreamingCall client . ClientWriterRequest 10 mempty $ \send ->
do (finalName, totalSum) <-
fmap ((mconcat *** (sum . mconcat)) . unzip) .
replicateM iterationCount $
Expand Down Expand Up @@ -86,7 +86,7 @@ testServerStreamingCall client = testCase "Server-streaming call" $
do response @?= "Test"
num @?= expNum
checkResults nums recv
res <- simpleServiceServerStreamingCall client $
res <- simpleServiceserverStreamingCall client $
ClientReaderRequest (SimpleServiceRequest "Test" (fromList nums)) 10 mempty
(\_ _ -> checkResults nums)
case res of
Expand All @@ -113,7 +113,7 @@ testBiDiStreamingCall client = testCase "Bidi-streaming call" $

iterations <- randomRIO (50, 500)

res <- simpleServiceBiDiStreamingCall client $
res <- simpleServicebiDiStreamingCall client $
ClientBiDiRequest 10 mempty (\_ _ -> handleRequests iterations)
case res of
ClientErrorResponse err -> assertFailure ("ClientErrorResponse: " <> show err)
Expand All @@ -132,4 +132,4 @@ main = do
, testClientStreamingCall service
, testServerStreamingCall service
, testBiDiStreamingCall service ]) `finally`
(simpleServiceDone service (ClientNormalRequest SimpleServiceDone 10 mempty))
(simpleServicedone service (ClientNormalRequest SimpleServiceDone 10 mempty))
10 changes: 5 additions & 5 deletions tests/TestServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ main :: IO ()
main = do exitVar <- newEmptyMVar

forkIO $ simpleServiceServer (SimpleService
{ simpleServiceDone = handleDone exitVar
, simpleServiceNormalCall = handleNormalCall
, simpleServiceClientStreamingCall = handleClientStreamingCall
, simpleServiceServerStreamingCall = handleServerStreamingCall
, simpleServiceBiDiStreamingCall = handleBiDiStreamingCall })
{ simpleServicedone = handleDone exitVar
, simpleServicenormalCall = handleNormalCall
, simpleServiceclientStreamingCall = handleClientStreamingCall
, simpleServiceserverStreamingCall = handleServerStreamingCall
, simpleServicebiDiStreamingCall = handleBiDiStreamingCall })
defaultServiceOptions

takeMVar exitVar

0 comments on commit 1127770

Please sign in to comment.