run method
Future<void>
run({
- InternetAddress? address,
- int? port,
- int connectionCheckIntervalSeconds = 30,
- String? privateKeyPath,
- String? motdPath,
Start a server.
address
default is 0.0.0.0
port
default is 6667
If privateKeyPath
is not null, server listen with TLS enabled.
It's file contents must contains both CERTIFICATE and PRIVATE KEY.
So it's just looks like:
-----BEGIN CERTIFICATE-----
abcabc...
-----END CERTIFICATE-----
-----BEGIN PRIVATE KEY-----
xyzxyz...
-----END PRIVATE KEY-----
Implementation
Future<void> run({
InternetAddress? address,
int? port,
int connectionCheckIntervalSeconds = 30,
String? privateKeyPath,
String? motdPath,
}) async {
final addr = address ??
InternetAddress(Platform.environment['IRCD_HOSTADDR'] ?? '0.0.0.0');
final portStr = Platform.environment['IRCD_PORT'];
final portNum = port ??
(portStr != null ? int.tryParse(portStr, radix: 10) : null) ??
6667;
final certKeyPath =
privateKeyPath ?? Platform.environment['IRCD_PRIVATE_KEY'];
final ponger = Timer.periodic(
Duration(seconds: connectionCheckIntervalSeconds),
(_) => _checkClientConnection(DateTime.now()),
);
if (certKeyPath == null) {
final server = await ServerSocket.bind(addr, portNum);
_listen(server, ponger);
print(banner);
print('Listen on: ${server.address.address}:${server.port}');
} else {
final securityContext = SecurityContext()
..useCertificateChain(certKeyPath)
..usePrivateKey(certKeyPath);
final server = await SecureServerSocket.bind(
addr,
portNum,
securityContext,
);
_listen(server, ponger);
print(banner);
print('Listen on: ${server.address.address}:${server.port} with TLS');
}
}