Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PortNumber throughout #66

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions demo-client/Demo/Client/Cmdline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Data.ProtoLens
import Data.ProtoLens.Labels ()
import Data.Text (Text)
import GHC.TypeLits (Symbol)
import Network.Socket (HostName, PortNumber)
import Options.Applicative qualified as Opt

import Network.GRPC.Client qualified as Client
Expand Down Expand Up @@ -135,8 +136,8 @@ parseServer =
])
where
mkServer ::
String -- Host
-> Maybe Word -- Port
HostName -- Host
-> Maybe PortNumber -- Port
-> Maybe Client.ServerValidation -- Secure?
-> Maybe String
-> Client.Server
Expand Down
6 changes: 3 additions & 3 deletions demo-server/Demo/Server/Cmdline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Demo.Server.Cmdline (

import Data.Foldable (asum)
import Options.Applicative qualified as Opt
import Network.Socket (ServiceName, PortNumber)
import Network.Socket (PortNumber)

import Network.GRPC.Common
import Network.GRPC.Server.Run
Expand Down Expand Up @@ -57,13 +57,13 @@ parseInsecure = asum [
, Opt.help "Disable insecure server (without TLS)"
]
, cfg
<$> Opt.option Opt.str (mconcat [
<$> Opt.option Opt.auto (mconcat [
Opt.long "port-insecure"
, Opt.help "Port number for the insecure server (without TLS)"
])
]
where
cfg :: ServiceName -> Maybe InsecureConfig
cfg :: PortNumber -> Maybe InsecureConfig
cfg port = Just InsecureConfig {
insecureHost = Nothing
, insecurePort = port
Expand Down
1 change: 1 addition & 0 deletions grapesy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ executable demo-client
, contra-tracer >= 0.2 && < 0.3
, data-default >= 0.7 && < 0.8
, lens >= 5.0 && < 5.3
, network >= 3.1 && < 3.2
, optparse-applicative >= 0.16 && < 0.19
, pipes >= 4.3 && < 4.4
, pipes-safe >= 2.3 && < 2.4
Expand Down
14 changes: 9 additions & 5 deletions src/Network/GRPC/Server/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Network.ByteOrder (BufferSize)
import Network.HTTP2.Server qualified as HTTP2
import Network.HTTP2.TLS.Server qualified as HTTP2.TLS
import Network.Run.TCP (runTCPServer)
import Network.Socket (HostName, ServiceName, PortNumber)
import Network.Socket (HostName, PortNumber)
import Network.TLS qualified as TLS

import Network.GRPC.Server (mkGrpcServer, ServerParams, RpcHandler)
Expand All @@ -30,9 +30,13 @@ import Debug.Concurrent
Configuration
-------------------------------------------------------------------------------}

-- | Describes the configuration of both an insecure server and a secure server.
-- | Server configuration
--
-- Describes the configuration of both an insecure server and a secure server.
-- See the documentation of 'runServer' for a description of what servers will
-- result from various configurations.
--
-- The default configuration enables the default insecure configuration only.
data ServerConfig = ServerConfig {
-- | Configuration for insecure communication (without TLS)
--
Expand All @@ -59,14 +63,14 @@ data InsecureConfig = InsecureConfig {
insecureHost :: Maybe HostName

-- | Port number
, insecurePort :: ServiceName
, insecurePort :: PortNumber
}
deriving (Show)

instance Default InsecureConfig where
def = InsecureConfig {
insecureHost = Nothing
, insecurePort = "50051"
, insecurePort = 50051
}

-- | Offer secure connection (over TLS)
Expand Down Expand Up @@ -128,7 +132,7 @@ runServerWithHandlers config params handlers = do

runInsecure :: HTTP2.Server -> InsecureConfig -> IO ()
runInsecure server cfg =
runTCPServer (insecureHost cfg) (insecurePort cfg) $ \sock -> do
runTCPServer (insecureHost cfg) (show $ insecurePort cfg) $ \sock -> do
bracket (HTTP2.allocSimpleConfig sock writeBufferSize)
HTTP2.freeSimpleConfig $ \config ->
HTTP2.run HTTP2.defaultServerConfig config server
Expand Down
5 changes: 3 additions & 2 deletions src/Network/GRPC/Spec/PseudoHeaders.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Data.Hashable (Hashable)
import Data.Proxy
import Data.Text (Text)
import GHC.Generics qualified as GHC
import Network.Socket (HostName, PortNumber)

import Network.GRPC.Spec.PercentEncoding qualified as PercentEncoding
import Network.GRPC.Spec.RPC
Expand Down Expand Up @@ -92,10 +93,10 @@ data Scheme = Http | Https
-- [pseudo-header](https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3).
data Address = Address {
-- | Hostname
addressHost :: String
addressHost :: HostName

-- | TCP port
, addressPort :: Word
, addressPort :: PortNumber

-- | Authority
--
Expand Down
4 changes: 2 additions & 2 deletions test-common/Test/Util/ClientServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ runTestServer cfg serverTracer handlerLock serverHandlers = do
Nothing -> Server.ServerConfig {
serverInsecure = Just Server.InsecureConfig {
insecureHost = Nothing
, insecurePort = "50051"
, insecurePort = 50051
}
, serverSecure = Nothing
}
Just (TlsFail TlsFailUnsupported) -> Server.ServerConfig {
serverInsecure = Just Server.InsecureConfig {
insecureHost = Nothing
, insecurePort = "50052"
, insecurePort = 50052
}
, serverSecure = Nothing
}
Expand Down