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

Updates for 0.4 release #425

Merged
merged 2 commits into from
Sep 17, 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
4 changes: 2 additions & 2 deletions components/tags/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export const Examples = () => {
<ExampleCard
title="IceRPC + Slice"
description="Example applications that use both IceRPC and Slice."
href="https://github.com/icerpc/icerpc-csharp/tree/0.3.x/examples/slice/"
href="https://github.com/icerpc/icerpc-csharp/tree/0.4.x/examples/slice/"
/>
<ExampleCard
title="IceRPC + Protobuf"
description="Example applications that use both IceRPC and Protobuf."
href="https://github.com/icerpc/icerpc-csharp/tree/0.3.x/examples/protobuf"
href="https://github.com/icerpc/icerpc-csharp/tree/0.4.x/examples/protobuf"
/>
</div>
);
Expand Down
53 changes: 30 additions & 23 deletions content/getting-started/icerpc-protobuf-tutorial/client-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,35 @@ The main program starts by creating a connection to the server:
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
builder
.AddSimpleConsole()
.AddFilter("IceRpc", LogLevel.Debug));
.AddFilter("IceRpc", LogLevel.Information));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation doesn't match the actual templates. This was changed in icerpc/icerpc-csharp#3840


// Path to the root CA certificate.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The templates were updated to use SSL


// Create Client authentication options with custom certificate validation.
var clientAuthenticationOptions = new SslClientAuthenticationOptions
{
RemoteCertificateValidationCallback = (sender, certificate, chain, errors) =>
{
if (certificate is X509Certificate2 peerCertificate)
{
using var customChain = new X509Chain();
customChain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
customChain.ChainPolicy.DisableCertificateDownloads = true;
customChain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
customChain.ChainPolicy.CustomTrustStore.Add(rootCA);
return customChain.Build(peerCertificate);
}
else
{
return false;
}
}
};

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: null,
clientAuthenticationOptions,
logger: loggerFactory.CreateLogger<ClientConnection>());
```

Expand All @@ -77,8 +101,8 @@ This connection naturally matches our server configuration:
`icerpc` protocol to `localhost` on the default port for `icerpc` (4062)
- we don't specify a transport so we use the default multiplexed transport
(`tcp`)
- the null `clientAuthenticationOptions` means we'll establish a plain
non-secure TCP connection
- Setting the `clientAuthenticationOptions` means we'll establish a secure
SSL connection

{% callout %}

Expand Down Expand Up @@ -164,12 +188,7 @@ cd MyProtobufServer
dotnet run
```

The server is now listening for new connections from clients:

```
dbug: IceRpc.Server[11]
Listener 'icerpc://[::0]?transport=tcp' has started accepting connections
```
The server is now listening for new connections from clients.

### Start the client

Expand All @@ -181,27 +200,15 @@ dotnet run
The client sends a single `greet` request to the service hosted by our server:

```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the logger output to match that of the new log level.

dbug: IceRpc.ClientConnection[3]
Client connection from '[::1]:52308' to '[::1]:4062' connected
info: IceRpc.Logger.LoggerInterceptor[0]
Sent request Greet to icerpc:/visitor_center.Greeter over
[::1]:52308<->[::1]:4062 and received a response with status code Ok
Sent request Greet to icerpc:/visitor_center.Greeter over [::1]:59405<->[::1]:4062 and received a response with status code Ok
Hello, jose!
dbug: IceRpc.ClientConnection[6]
Client connection from '[::1]:52308' to '[::1]:4062' shutdown
dbug: IceRpc.ClientConnection[5]
Client connection from '[::1]:52308' to '[::1]:4062' disposed
```

### Shutdown the server

Press Ctrl+C on the server console to shut it down.

```
dbug: IceRpc.Server[12]
Listener 'icerpc://[::0]?transport=tcp' has stopped accepting connections
```

{% /step %}

[create the server]: server-tutorial
Expand Down
31 changes: 16 additions & 15 deletions content/getting-started/icerpc-protobuf-tutorial/server-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The main program starts by creating and configuring a [Router]:
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
builder
.AddSimpleConsole()
.AddFilter("IceRpc", LogLevel.Debug));
.AddFilter("IceRpc", LogLevel.Information));

Router router = new Router()
.UseLogger(loggerFactory)
Expand All @@ -151,9 +151,20 @@ The main program then creates a [Server] that directs all incoming requests to
`router`:

```csharp

var sslServerAuthenticationOptions = new SslServerAuthenticationOptions
{
ServerCertificateContext = SslStreamCertificateContext.Create(
X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable),
additionalCertificates: null)
};

await using var server = new Server(
dispatcher: router,
serverAuthenticationOptions: null,
serverAuthenticationOptions,
logger: loggerFactory.CreateLogger<Server>());
```

Expand All @@ -163,8 +174,8 @@ will listen for connections on all network interfaces with the default port for
`icerpc` (4062).

We don't specify a transport either so we use the default multiplexed transport
(`tcp`). The null `serverAuthenticationOptions` means this server will accept
plain TCP connections—it's a simple, non-secure server.
(`tcp`). Setting the `serverAuthenticationOptions` means this server will only accept
secure SSL connections.

At this point, the server is created but is not doing anything yet. A client
attempting to connect would get a "connection refused" error.
Expand Down Expand Up @@ -212,22 +223,12 @@ cd MyProtobufServer
dotnet run
```

The server is now listening for new connections from clients:

```
dbug: IceRpc.Server[11]
Listener 'icerpc://[::0]?transport=tcp' has started accepting connections
```
The server is now listening for new connections from clients.

### Shutdown the server

Press Ctrl+C on the server console to shut it down.

```
dbug: IceRpc.Server[12]
Listener 'icerpc://[::0]?transport=tcp' has stopped accepting connections
```

{% /step %}

[create the client]: client-tutorial
Expand Down
55 changes: 31 additions & 24 deletions content/getting-started/icerpc-slice-tutorial/client-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,35 @@ The main program starts by creating a connection to the server:
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
builder
.AddSimpleConsole()
.AddFilter("IceRpc", LogLevel.Debug));
.AddFilter("IceRpc", LogLevel.Information));

// Path to the root CA certificate.
using var rootCA = X509CertificateLoader.LoadCertificateFromFile("certs/cacert.der");

// Create Client authentication options with custom certificate validation.
var clientAuthenticationOptions = new SslClientAuthenticationOptions
{
RemoteCertificateValidationCallback = (sender, certificate, chain, errors) =>
{
if (certificate is X509Certificate2 peerCertificate)
{
using var customChain = new X509Chain();
customChain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
customChain.ChainPolicy.DisableCertificateDownloads = true;
customChain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
customChain.ChainPolicy.CustomTrustStore.Add(rootCA);
return customChain.Build(peerCertificate);
}
else
{
return false;
}
}
};

await using var connection = new ClientConnection(
new Uri("icerpc://localhost"),
clientAuthenticationOptions: null,
clientAuthenticationOptions,
logger: loggerFactory.CreateLogger<ClientConnection>());
```

Expand All @@ -67,8 +91,8 @@ This connection naturally matches our server configuration:
`icerpc` protocol to `localhost` on the default port for `icerpc` (4062)
- we don't specify a transport so we use the default multiplexed transport
(`tcp`)
- the null `clientAuthenticationOptions` means we'll establish a plain
non-secure TCP connection
- Setting the `clientAuthenticationOptions` means we'll establish a secure
SSL connection

{% callout %}

Expand Down Expand Up @@ -154,12 +178,7 @@ cd MySliceServer
dotnet run
```

The server is now listening for new connections from clients:

```
dbug: IceRpc.Server[11]
Listener 'icerpc://[::0]?transport=tcp' has started accepting connections
```
The server is now listening for new connections from clients.

### Start the client

Expand All @@ -171,27 +190,15 @@ dotnet run
The client sends a single `greet` request to the service hosted by our server:

```
dbug: IceRpc.ClientConnection[3]
Client connection from '[::1]:61582' to '[::1]:4062' connected
info: IceRpc.Logger.LoggerInterceptor[0]
Sent request greet to icerpc:/VisitorCenter.Greeter over
[::1]:61582<->[::1]:4062 and received a response with status code Ok
Hello, Reece!
dbug: IceRpc.ClientConnection[6]
Client connection from '[::1]:61582' to '[::1]:4062' shutdown
dbug: IceRpc.ClientConnection[5]
Client connection from '[::1]:61582' to '[::1]:4062' disposed
Sent request greet to icerpc:/VisitorCenter.Greeter over [::1]:59522<->[::1]:4062 and received a response with status code Ok
Hello, jose!
```

### Shutdown the server

Press Ctrl+C on the server console to shut it down.

```
dbug: IceRpc.Server[12]
Listener 'icerpc://[::0]?transport=tcp' has stopped accepting connections
```

{% /step %}

[create the server]: server-tutorial
Expand Down
30 changes: 15 additions & 15 deletions content/getting-started/icerpc-slice-tutorial/server-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The main program starts by creating and configuring a [Router]:
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
builder
.AddSimpleConsole()
.AddFilter("IceRpc", LogLevel.Debug));
.AddFilter("IceRpc", LogLevel.Information));

Router router = new Router()
.UseLogger(loggerFactory)
Expand All @@ -140,9 +140,19 @@ The main program then creates a [Server] that directs all incoming requests to
`router`:

```csharp
var sslServerAuthenticationOptions = new SslServerAuthenticationOptions
{
ServerCertificateContext = SslStreamCertificateContext.Create(
X509CertificateLoader.LoadPkcs12FromFile(
"certs/server.p12",
password: null,
keyStorageFlags: X509KeyStorageFlags.Exportable),
additionalCertificates: null)
};

await using var server = new Server(
dispatcher: router,
serverAuthenticationOptions: null,
serverAuthenticationOptions,
logger: loggerFactory.CreateLogger<Server>());
```

Expand All @@ -152,8 +162,8 @@ will listen for connections on all network interfaces with the default port for
`icerpc` (4062).

We don't specify a transport either so we use the default multiplexed transport
(`tcp`). The null `serverAuthenticationOptions` means this server will accept
plain TCP connections—it's a simple, non-secure server.
(`tcp`). Setting the `serverAuthenticationOptions` means this server will only accept
secure SSL connections.

At this point, the server is created but is not doing anything yet. A client
attempting to connect would get a "connection refused" error.
Expand Down Expand Up @@ -201,22 +211,12 @@ cd MySliceServer
dotnet run
```

The server is now listening for new connections from clients:

```
dbug: IceRpc.Server[11]
Listener 'icerpc://[::0]?transport=tcp' has started accepting connections
```
The server is now listening for new connections from clients.

### Shutdown the server

Press Ctrl+C on the server console to shut it down.

```
dbug: IceRpc.Server[12]
Listener 'icerpc://[::0]?transport=tcp' has stopped accepting connections
```

{% /step %}

[create the client]: client-tutorial
Expand Down
18 changes: 3 additions & 15 deletions content/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ cd MyServer
dotnet run
```

The server is now listening for new connections from clients:

```
dbug: IceRpc.Server[11]
Listener 'icerpc://[::0]?transport=tcp' has started accepting connections
```
The server is now listening for new connections from clients.

### Start the client

Expand All @@ -80,16 +75,9 @@ dotnet run
The client sends a single `greet` request to the service hosted by our server:

```
dbug: IceRpc.ClientConnection[3]
Client connection from '[::1]:61582' to '[::1]:4062' connected
info: IceRpc.Logger.LoggerInterceptor[0]
Sent request greet to icerpc:/VisitorCenter.Greeter over
[::1]:61582<->[::1]:4062 and received a response with status code Ok
Hello, Reece!
dbug: IceRpc.ClientConnection[6]
Client connection from '[::1]:61582' to '[::1]:4062' shutdown
dbug: IceRpc.ClientConnection[5]
Client connection from '[::1]:61582' to '[::1]:4062' disposed
Sent request greet to icerpc:/VisitorCenter.Greeter over [::1]:59739<->[::1]:4062 and received a response with status code Ok
Hello, jose!
```

{% /step %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal partial class Chatbot : IGreeterService

[IServiceCollection]: https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection
[IServiceProvider]: https://learn.microsoft.com/en-us/dotnet/api/system.iserviceprovider
[IceRpc.Extensions.DependencyInjection]: https://github.com/icerpc/icerpc-csharp/tree/0.3.x/src/IceRpc.Extensions.DependencyInjection
[IceRpc.Extensions.DependencyInjection]: https://github.com/icerpc/icerpc-csharp/tree/0.4.x/src/IceRpc.Extensions.DependencyInjection

[Router]: csharp:IceRpc.Router
[IDispatcherBuilder]: csharp:IceRpc.Extensions.DependencyInjection.IDispatcherBuilder
Expand Down