Skip to content

Commit ea3266c

Browse files
Rename secure -> config and change its focus (C++) (#277)
1 parent d9736b7 commit ea3266c

File tree

12 files changed

+165
-95
lines changed

12 files changed

+165
-95
lines changed
File renamed without changes.

cpp/Ice/secure/Chatbot.cpp renamed to cpp/Ice/config/Chatbot.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#include <sstream>
77

88
using namespace std;
9+
using namespace ConfigServer;
910

1011
string
11-
GreeterServer::Chatbot::greet(string name, const Ice::Current&)
12+
Chatbot::greet(string name, const Ice::Current&)
1213
{
1314
cout << "Dispatching greet request { name = '" << name << "' }" << endl;
1415

cpp/Ice/secure/Chatbot.h renamed to cpp/Ice/config/Chatbot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "Greeter.h"
77

8-
namespace GreeterServer
8+
namespace ConfigServer
99
{
1010
/// A Chatbot is an Ice servant that implements Slice interface Greeter.
1111
class Chatbot : public VisitorCenter::Greeter

cpp/Ice/secure/Client.cpp renamed to cpp/Ice/config/Client.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Greeter.h"
44

5+
#include <Ice/Ice.h>
56
#include <cstdlib>
67
#include <iostream>
78

@@ -18,22 +19,21 @@ main(int argc, char* argv[])
1819
}
1920
if (name == nullptr)
2021
{
21-
name = "alice";
22+
name = "masked user";
2223
}
2324

24-
// Create an Ice communicator to initialize the Ice runtime. The new communicator gets its properties from file
25-
// "config.client".
25+
// Create an Ice communicator to initialize the Ice runtime. The communicator gets its configuration properties from
26+
// file "config.server". The communicator initialization also parses the command-line options to find and set
27+
// additional properties.
2628
const Ice::CommunicatorHolder communicatorHolder{argc, argv, "config.client"};
2729
const Ice::CommunicatorPtr& communicator = communicatorHolder.communicator();
2830

29-
// GreeterPrx is a class generated by the Slice compiler. We create a proxy from a communicator and a "stringified
30-
// proxy" with the address of the target object.
31-
// If you run the server on a different computer, replace localhost in the string below with the server's hostname
32-
// or IP address.
33-
VisitorCenter::GreeterPrx greeter{communicator, "greeter:ssl -h localhost -p 4061"};
31+
// We create a Greeter proxy using the value of the "Greeter.Proxy" property in config.client.
32+
// It's nullopt if the property is not set.
33+
std::optional<VisitorCenter::GreeterPrx> greeter =
34+
communicator->propertyToProxy<VisitorCenter::GreeterPrx>("Greeter.Proxy");
3435

35-
// Send a request to the remote object and get the response. Both the -> and . syntax can be used to make
36-
// invocations with the proxy.
36+
// Send a request to the remote object and get the response.
3737
string greeting = greeter->greet(name);
3838

3939
cout << greeting << endl;
File renamed without changes.

cpp/Ice/config/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Config
2+
3+
This demo shows how to configure your client and server applications using Ice configuration
4+
files.
5+
6+
To build the demo run:
7+
8+
```shell
9+
cmake -B build
10+
cmake --build build --config Release
11+
```
12+
13+
To run the demo, first start the server:
14+
15+
**Linux/macOS:**
16+
17+
```shell
18+
./build/server
19+
```
20+
21+
**Windows:**
22+
23+
```shell
24+
build\Release\server
25+
```
26+
27+
In a separate window, start the client:
28+
29+
**Linux/macOS:**
30+
31+
```shell
32+
./build/client
33+
```
34+
35+
**Windows:**
36+
37+
```shell
38+
build\Release\client
39+
```
40+
41+
You can pass `--Ice` command-line options to set additional properties or override the properties set in the
42+
configuration file.
43+
44+
For example:
45+
46+
**Linux/macOS:**
47+
48+
```shell
49+
./build/server --Ice.Default.Protocol=ws
50+
```
51+
52+
```shell
53+
./build/client --Ice.Default.Protocol=ws --Ice.Trace.Network=2
54+
```
55+
56+
**Windows:**
57+
58+
```shell
59+
build\Release\server --Ice.Default.Protocol=ws
60+
```
61+
62+
```shell
63+
build\Release\client --Ice.Default.Protocol=ws --Ice.Trace.Network=2
64+
```

cpp/Ice/secure/Server.cpp renamed to cpp/Ice/config/Server.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#include "Chatbot.h"
44

5+
#include <Ice/Ice.h>
56
#include <iostream>
67

78
using namespace std;
9+
using namespace ConfigServer;
810

911
int
1012
main(int argc, char* argv[])
@@ -13,21 +15,24 @@ main(int argc, char* argv[])
1315
// of the program, before creating an Ice communicator or starting any thread.
1416
Ice::CtrlCHandler ctrlCHandler;
1517

16-
// Create an Ice communicator to initialize the Ice runtime. The new communicator gets its properties from file
17-
// "config.server".
18+
// Create an Ice communicator to initialize the Ice runtime. The communicator gets its configuration properties from
19+
// file "config.server". The communicator initialization also parses the command-line options to find and set
20+
// additional properties.
1821
const Ice::CommunicatorHolder communicatorHolder{argc, argv, "config.server"};
1922
const Ice::CommunicatorPtr& communicator = communicatorHolder.communicator();
2023

21-
// Create an object adapter that listens for incoming requests and dispatches them to servants. We use the ssl
22-
// transport for secure communications.
23-
auto adapter = communicator->createObjectAdapterWithEndpoints("GreeterAdapter", "ssl -p 4061");
24+
// Create an object adapter that listens for incoming requests and dispatches them to servants.
25+
// This adapter is configured through the GreeterAdapter.* properties in config.server.
26+
auto adapter = communicator->createObjectAdapter("GreeterAdapter");
2427

2528
// Register the Chatbot servant with the adapter.
26-
adapter->add(make_shared<GreeterServer::Chatbot>(), Ice::stringToIdentity("greeter"));
29+
adapter->add(make_shared<Chatbot>(), Ice::stringToIdentity("greeter"));
2730

2831
// Start dispatching requests.
2932
adapter->activate();
3033

34+
// Ice.Trace.Network=1 or greater shows on which interface(s) and port(s) the server is listening.
35+
3136
// Wait until the user presses Ctrl+C.
3237
int signal = ctrlCHandler.wait();
3338
cout << "Caught signal " << signal << ", exiting..." << endl;

cpp/Ice/config/config.client

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Application-specific configuration
3+
#
4+
5+
# The address of the target object. `default` is replaced by the value of Ice.Default.Protocol.
6+
Greeter.Proxy=greeter:default -h localhost -p 4061
7+
8+
#
9+
# Ice configuration
10+
#
11+
12+
# The transport protocol to use for Ice communications when `default` is specified.
13+
# You can set it to tcp, ssl, ws, or wss. Leaving it unset is equivalent to setting it to tcp.
14+
# Make sure you use the same value in config.client and config.server.
15+
Ice.Default.Protocol=ssl
16+
17+
#
18+
# IceSSL configuration
19+
#
20+
21+
# The directory where the application finds certificates and other files.
22+
IceSSL.DefaultDir=../../../certs
23+
24+
# The certificate authority file.
25+
IceSSL.CAs=cacert.pem
26+
27+
# The client's certificate file.
28+
IceSSL.CertFile=client.p12
29+
30+
# The name of the keychain in which to import the client's certificate (SecureTransport only).
31+
IceSSL.Keychain=client.keychain
32+
33+
# TODO: switch to password-less certificates
34+
IceSSL.Password=password
35+
IceSSL.KeychainPassword=password
36+
37+
# Turn on security logging/tracing.
38+
# IceSSL.Trace.Security=1

cpp/Ice/config/config.server

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Object adapter configuration
3+
#
4+
5+
# Configure the GreeterAdapter adapter to listen on port 4061, on all interfaces.
6+
# `default` is replaced by the value of Ice.Default.Protocol.
7+
GreeterAdapter.Endpoints=default -p 4061
8+
9+
#
10+
# Ice configuration
11+
#
12+
13+
# The transport protocol to use for Ice communications when `default` is specified.
14+
# You can set it to tcp, ssl, ws, or wss. Leaving it unset is equivalent to setting it to tcp.
15+
# Make sure you use the same value in config.client and config.server.
16+
Ice.Default.Protocol=ssl
17+
18+
# Turn on Network and Dispatch logging/tracing.
19+
Ice.Trace.Network=1
20+
Ice.Trace.Dispatch=1
21+
22+
# The directory where the application finds certificates and other files.
23+
IceSSL.DefaultDir=../../../certs
24+
25+
# The certificate authority file.
26+
IceSSL.CAs=cacert.pem
27+
28+
# The server's certificate file.
29+
IceSSL.CertFile=server.p12
30+
31+
# The name of the keychain in which to import the server's certificate (SecureTransport only).
32+
IceSSL.Keychain=server.keychain
33+
34+
# TODO: switch to password-less certificates
35+
IceSSL.Password=password
36+
IceSSL.KeychainPassword=password
37+
38+
# Turn on security logging/tracing.
39+
IceSSL.Trace.Security=1

cpp/Ice/secure/README.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)