Skip to content

Commit eff406a

Browse files
committed
Complete documentation
1 parent 6142195 commit eff406a

7 files changed

Lines changed: 102 additions & 74 deletions

File tree

server/README.md

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,43 @@
99
Run it as a regular `Java` CLI app:
1010

1111
```bash
12-
$> java -jar epmd-2.0.0.jar
13-
2019-06-06 00:10:18.869 INFO : Starting server on port 4369
12+
$> java -jar epmd-2.0.0.jar server
13+
2019-03-17 01:38:09.302 INFO : EPMD server started (debug: false, port: 4369, allowed-ips: [localhost/127.0.0.1], unsafe-commands: true)
1414

1515
```
1616

1717
To get names of all registered nodes:
1818

1919
```bash
20-
$> java -jar epmd-2.0.0.jar -names
21-
popa
22-
echo
20+
$> java -jar epmd-2.0.0.jar names
21+
2019-03-17 01:45:39.310 INFO : EPMD up and running on port 4369 with the registered node(s):
22+
- node 'echo' at port 60045
2323
```
2424

2525
To see another options and commands, just type:
2626

2727
```bash
2828
$> java -jar epmd-2.0.0.jar --help
29-
usage: java -jar epmd.jar [-d|-debug] [DbgExtra...] [-address List]
30-
[-port No] [-daemon] [-relaxed_command_check]
31-
java -jar epmd.jar [-d|-debug] [-port No] [-names|-kill|-stop name]
32-
33-
Regular options
34-
-address List
35-
Let epmd listen only on the comma-separated list of IP
36-
addresses (and on the loopback interface).
37-
-port No
38-
Let epmd listen to another port than default 4369
39-
-d
40-
-debug
41-
Enable debugging. This will give a log to
42-
the standard error stream. It will shorten
43-
the number of saved used node names to 5.
44-
45-
If you give more than one debug flag you may
46-
get more debugging information.
47-
-relaxed_command_check
48-
Allow this instance of epmd to be killed with
49-
epmd -kill even if there are registered nodes.
50-
Also allows forced unregister (epmd -stop).
51-
52-
DbgExtra options
53-
-packet_timeout Seconds
54-
Set the number of seconds a connection can be
55-
inactive before epmd times out and closes the
56-
connection (default 60).
57-
58-
-delay_accept Seconds
59-
To simulate a busy server you can insert a
60-
delay between epmd gets notified about that
61-
a new connection is requested and when the
62-
connections gets accepted.
63-
64-
-delay_write Seconds
65-
Also a simulation of a busy server. Inserts
66-
a delay before a reply is sent.
67-
68-
Interactive options
69-
-names
70-
List names registered with the currently running epmd
71-
-kill
72-
Kill the currently running epmd
73-
(only allowed if -names show empty database or
74-
-relaxed_command_check was given when epmd was started).
75-
-stop Name
76-
Forcibly unregisters a name with epmd
77-
(only allowed if -relaxed_command_check was given when
78-
epmd was started).
29+
Usage: epmd [-dhV] [-p=PORT] [COMMAND]
30+
31+
Erlang port mapper daemon. This is a small name server used by Erlang programs
32+
when establishing distributed Erlang communications.
33+
34+
Options:
35+
-p, --port=PORT Let epmd listen to another port than default 4369. This can also
36+
be set using environment variable ERL_EPMD_PORT
37+
-d, --debug Enables debugging logs
38+
-h, --help Show this help message and exit.
39+
-V, --version Print version information and exit.
40+
41+
Commands:
42+
help Displays help information about the specified command
43+
names Lists names registered with the currently running epmd.
44+
server Starts the epmd server.
45+
stop Forcibly unregisters a live node from the epmd database.
46+
kill Kills the currently running epmd.
47+
48+
Run 'epmd help COMMAND' for more information on a command.
7949

8050
```
8151

@@ -104,12 +74,13 @@ compile 'io.appulse.epmd.java:server:2.0.0'
10474
To start EPMD server in your code:
10575

10676
```java
77+
import io.appulse.epmd.java.server.SubcommandServer;
10778
// ...
108-
CommonOptions commonOptions = new CommonOptions();
109-
commonOptions.setPort(4369);
110-
111-
ServerCommandExecutor server = new ServerCommandExecutor(commonOptions, new ServerCommandOptions());
79+
val server = SubcommandServer.builder()
80+
.port(6666) // if not set, default is 4369
81+
.ip(SubcommandServer.ANY_ADDRESS) // if not set, default is LOOPBACK
82+
.build();
11283

113-
server.execute(); // it starts Netty server and blocks current thread
84+
server.run(); // it starts the server and blocks the current thread
11485
// ...
11586
```

server/src/main/java/io/appulse/epmd/java/server/Epmd.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
import lombok.AllArgsConstructor;
2020
import lombok.Builder;
2121
import lombok.NoArgsConstructor;
22+
import lombok.Setter;
2223
import lombok.extern.slf4j.Slf4j;
2324
import picocli.CommandLine.Command;
25+
import picocli.CommandLine.HelpCommand;
2426
import picocli.CommandLine.Option;
2527

2628
@Slf4j
29+
@Setter
2730
@Builder
2831
@NoArgsConstructor
2932
@AllArgsConstructor
@@ -39,8 +42,10 @@
3942
"used by Erlang programs when establishing distributed " +
4043
"Erlang communications.",
4144
mixinStandardHelpOptions = true,
45+
footer = "%nRun 'epmd help COMMAND' for more information on a command.",
4246
version = "epmd version \"2.0.0\" 2019-03-17",
4347
subcommands = {
48+
HelpCommand.class,
4449
SubcommandNames.class,
4550
SubcommandServer.class,
4651
SubcommandStop.class,

server/src/main/java/io/appulse/epmd/java/server/SubcommandKill.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@
3030
import picocli.CommandLine.ParentCommand;
3131

3232
@Slf4j
33-
@Command(name = "kill")
33+
@Command(
34+
name = "kill",
35+
sortOptions = false,
36+
descriptionHeading = "%n",
37+
parameterListHeading = "%nParameters:%n",
38+
optionListHeading = "%nOptions:%n",
39+
commandListHeading = "%nCommands:%n",
40+
description = "Kills the currently running epmd."
41+
)
3442
class SubcommandKill implements Runnable {
3543

3644
@ParentCommand

server/src/main/java/io/appulse/epmd/java/server/SubcommandNames.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@
3232
import picocli.CommandLine.ParentCommand;
3333

3434
@Slf4j
35-
@Command(name = "names")
35+
@Command(
36+
name = "names",
37+
sortOptions = false,
38+
descriptionHeading = "%n",
39+
parameterListHeading = "%nParameters:%n",
40+
optionListHeading = "%nOptions:%n",
41+
commandListHeading = "%nCommands:%n",
42+
description = "Lists names registered with the currently running epmd."
43+
)
3644
class SubcommandNames implements Runnable {
3745

3846
@ParentCommand

server/src/main/java/io/appulse/epmd/java/server/SubcommandServer.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,28 @@
8585

8686
@Slf4j
8787
@NoArgsConstructor
88-
@Command(name = "server")
89-
class SubcommandServer implements Runnable {
88+
@Command(
89+
name = "server",
90+
sortOptions = false,
91+
descriptionHeading = "%n",
92+
parameterListHeading = "%nParameters:%n",
93+
optionListHeading = "%nOptions:%n",
94+
commandListHeading = "%nCommands:%n",
95+
description = "Starts the epmd server."
96+
)
97+
public class SubcommandServer implements Runnable {
9098

9199
static final InetAddress ANY_ADDRESS;
92100

93101
static final InetAddress LOOPBACK_ADDRESS;
94102

103+
static final InetAddress LOCALHOST;
104+
95105
static {
96106
try {
97107
ANY_ADDRESS = InetAddress.getByName("0.0.0.0");
98108
LOOPBACK_ADDRESS = InetAddress.getLoopbackAddress();
109+
LOCALHOST = InetAddress.getLocalHost();
99110
} catch (UnknownHostException ex) {
100111
throw new IllegalStateException(ex);
101112
}
@@ -104,22 +115,38 @@ class SubcommandServer implements Runnable {
104115
@ParentCommand
105116
Epmd options;
106117

107-
@Option(names = { "-a", "--allowed-ips" })
118+
@Option(
119+
names = { "-a", "--allowed-ips" },
120+
description =
121+
"Lets this instance of epmd listen only on the comma-separated list of IP addresses" +
122+
"and on the loopback address (which is implicitly added to the list if it has not been " +
123+
"specified). This can also be set using environment variable ERL_EPMD_ADDRESS"
124+
)
108125
Set<InetAddress> ips = new HashSet<>(asList(LOOPBACK_ADDRESS));
109126

110-
@Option(names = { "-u", "--unsafe-commands" })
127+
@Option(
128+
names = { "-u", "--unsafe-commands" },
129+
description = {
130+
"Start the epmd program with relaxed command checking. This affects the following:",
131+
"With relaxed command checking, the epmd daemon can be killed from the localhost with i.e. epmd -kill even if there are active nodes registered. Normally only daemons with an empty node database can be killed with the epmd \"kill\" command.",
132+
"With relaxed command checking enabled, you can forcibly unregister live nodes by \"stop\" command."
133+
}
134+
)
111135
boolean unsafe;
112136

113137
Map<String, Node> nodes;
114138

115139
ExecutorService executor;
116140

117141
@Builder
118-
SubcommandServer (@NonNull Epmd options,
142+
SubcommandServer (Integer port,
119143
@Singular Set<InetAddress> ips,
120144
boolean unsafe
121145
) {
122-
this.options = options;
146+
options = new Epmd();
147+
ofNullable(port)
148+
.ifPresent(options::setPort);
149+
123150
this.unsafe = unsafe;
124151

125152
ofNullable(ips)
@@ -199,7 +226,7 @@ public void run () {
199226
if (remoteAddress == null) {
200227
log.warn("uh?");
201228
continue;
202-
} else if (!ips.contains(ANY_ADDRESS) && !ips.contains(remoteAddress)) {
229+
} else if (!ips.contains(ANY_ADDRESS) && !ips.contains(remoteAddress) && !LOCALHOST.equals(remoteAddress)) {
203230
clientSocket.close();
204231
log.warn("unacceptable remote client's address {}", remoteAddress);
205232
continue;

server/src/main/java/io/appulse/epmd/java/server/SubcommandStop.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@
3131
import picocli.CommandLine.ParentCommand;
3232

3333
@Slf4j
34-
@Command(name = "stop")
34+
@Command(
35+
name = "stop",
36+
sortOptions = false,
37+
descriptionHeading = "%n",
38+
parameterListHeading = "%nParameters:%n",
39+
optionListHeading = "%nOptions:%n",
40+
commandListHeading = "%nCommands:%n",
41+
description = "Forcibly unregisters a live node from the epmd database."
42+
)
3543
class SubcommandStop implements Runnable {
3644

3745
@ParentCommand
3846
Epmd options;
3947

40-
@Parameters
48+
@Parameters(
49+
paramLabel = "NAME",
50+
description = "A node's name for stopping"
51+
)
4152
String name;
4253

4354
@Override

server/src/test/java/io/appulse/epmd/java/server/SubcommandServerTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ class SubcommandServerTests {
5858
@BeforeEach
5959
void before () throws Exception {
6060
val server = SubcommandServer.builder()
61-
.options(Epmd.builder()
62-
.port(SocketUtils.findFreePort().orElseThrow(RuntimeException::new))
63-
.build())
61+
.port(SocketUtils.findFreePort().orElseThrow(RuntimeException::new))
6462
.ip(SubcommandServer.ANY_ADDRESS)
6563
.build();
6664

0 commit comments

Comments
 (0)