Skip to content

Commit 3af5c05

Browse files
tegefaulkesCMCDragonkai
authored andcommitted
WIP
1 parent 0025336 commit 3af5c05

File tree

12 files changed

+205
-163
lines changed

12 files changed

+205
-163
lines changed

src/PolykeyAgent.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,6 @@ import TaskManager from './tasks/TaskManager';
4646
import { serverManifest as clientServerManifest } from './client/handlers';
4747
import { serverManifest as agentServerManifest } from './agent/handlers';
4848

49-
type NetworkConfig = {
50-
// Agent QUICSocket config
51-
agentHost?: string;
52-
agentPort?: number;
53-
ipv6Only?: boolean;
54-
agentKeepAliveIntervalTime?: number;
55-
agentMaxIdleTimeout?: number;
56-
// RPCServer for client service
57-
clientHost?: string;
58-
clientPort?: number;
59-
// Websocket server config
60-
maxIdleTimeout?: number;
61-
pingIntervalTime?: number;
62-
pingTimeoutTimeTime?: number;
63-
// RPC config
64-
clientParserBufferByteLimit?: number;
65-
handlerTimeoutTime?: number;
66-
handlerTimeoutGraceTime?: number;
67-
};
68-
6949
interface PolykeyAgent extends CreateDestroyStartStop {}
7050
@CreateDestroyStartStop(
7151
new errors.ErrorPolykeyAgentRunning(),
@@ -123,6 +103,10 @@ class PolykeyAgent {
123103
}: {
124104
password: string;
125105
nodePath?: string;
106+
107+
// WHY IS THERE SO MANY CONFIGURATIONS???
108+
109+
126110
keyRingConfig?: {
127111
recoveryCode?: RecoveryCode;
128112
privateKey?: PrivateKey;
@@ -142,7 +126,25 @@ class PolykeyAgent {
142126
connectionHolePunchTimeoutTime?: number;
143127
connectionHolePunchIntervalTime?: number;
144128
};
145-
networkConfig?: NetworkConfig;
129+
networkConfig?: {
130+
// Agent QUICSocket config
131+
agentHost?: string;
132+
agentPort?: number;
133+
ipv6Only?: boolean;
134+
agentKeepAliveIntervalTime?: number;
135+
agentMaxIdleTimeout?: number;
136+
// RPCServer for client service
137+
clientHost?: string;
138+
clientPort?: number;
139+
// Websocket server config
140+
maxIdleTimeout?: number;
141+
pingIntervalTime?: number;
142+
pingTimeoutTimeTime?: number;
143+
// RPC config
144+
clientParserBufferByteLimit?: number;
145+
handlerTimeoutTime?: number;
146+
handlerTimeoutGraceTime?: number;
147+
};
146148
seedNodes?: SeedNodes;
147149
workers?: number;
148150
status?: Status;
@@ -192,12 +194,12 @@ class PolykeyAgent {
192194
};
193195

194196
await utils.mkdirExists(fs, nodePath);
195-
const statusPath = path.join(nodePath, config.defaults.statusBase);
196-
const statusLockPath = path.join(nodePath, config.defaults.statusLockBase);
197-
const statePath = path.join(nodePath, config.defaults.stateBase);
198-
const dbPath = path.join(statePath, config.defaults.dbBase);
199-
const keysPath = path.join(statePath, config.defaults.keysBase);
200-
const vaultsPath = path.join(statePath, config.defaults.vaultsBase);
197+
const statusPath = path.join(nodePath, config.paths.statusBase);
198+
const statusLockPath = path.join(nodePath, config.paths.statusLockBase);
199+
const statePath = path.join(nodePath, config.paths.stateBase);
200+
const dbPath = path.join(statePath, config.paths.dbBase);
201+
const keysPath = path.join(statePath, config.paths.keysBase);
202+
const vaultsPath = path.join(statePath, config.paths.vaultsBase);
201203
const events = new EventBus({
202204
captureRejections: true,
203205
});

src/PolykeyClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class PolykeyClient {
4949
throw new errors.ErrorUtilsNodePath();
5050
}
5151
await utils.mkdirExists(fs, nodePath);
52-
const sessionTokenPath = path.join(nodePath, config.defaults.tokenBase);
52+
const sessionTokenPath = path.join(nodePath, config.paths.tokenBase);
5353
session =
5454
session ??
5555
(await Session.createSession({

src/bootstrap/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ async function bootstrapState({
5656
}
5757
await mkdirExists(fs, nodePath);
5858
// Setup node path and sub paths
59-
const statusPath = path.join(nodePath, config.defaults.statusBase);
60-
const statusLockPath = path.join(nodePath, config.defaults.statusLockBase);
61-
const statePath = path.join(nodePath, config.defaults.stateBase);
62-
const dbPath = path.join(statePath, config.defaults.dbBase);
63-
const keysPath = path.join(statePath, config.defaults.keysBase);
64-
const vaultsPath = path.join(statePath, config.defaults.vaultsBase);
59+
const statusPath = path.join(nodePath, config.paths.statusBase);
60+
const statusLockPath = path.join(nodePath, config.paths.statusLockBase);
61+
const statePath = path.join(nodePath, config.paths.stateBase);
62+
const dbPath = path.join(statePath, config.paths.dbBase);
63+
const keysPath = path.join(statePath, config.paths.keysBase);
64+
const vaultsPath = path.join(statePath, config.paths.vaultsBase);
6565
const status = new Status({
6666
statusPath,
6767
statusLockPath,

src/config.ts

Lines changed: 111 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ const config = {
7373
},
7474
},
7575
/**
76-
* Default configuration
76+
* File/directory paths
7777
*/
78-
defaults: {
79-
nodePath: getDefaultNodePath(),
78+
paths: {
8079
statusBase: 'status.json',
8180
statusLockBase: 'status.lock',
8281
stateBase: 'state',
@@ -86,73 +85,116 @@ const config = {
8685
vaultsBase: 'vaults',
8786
efsBase: 'efs',
8887
tokenBase: 'token',
89-
certManagerConfig: {
90-
certDuration: 31536000,
91-
},
92-
networkConfig: {
93-
/**
94-
* Agent host defaults to `::` dual stack.
95-
* This is because the agent service is supposed to be public.
96-
*/
97-
agentHost: '::',
98-
agentPort: 0,
99-
/**
100-
* Client host defaults to `localhost`.
101-
* This will depend on the OS configuration.
102-
* Usually it will be IPv4 `127.0.0.1` or IPv6 `::1`.
103-
* This is because the client service is private most of the time.
104-
*/
105-
clientHost: 'localhost',
106-
clientPort: 0,
107-
/**
108-
* If using dual stack `::`, then this forces only IPv6 bindings.
109-
*/
110-
ipv6Only: false,
111-
112-
/**
113-
* Agent service transport keep alive interval time.
114-
* This the maxmum time between keep alive messages.
115-
* This only has effect if `agentMaxIdleTimeout` is greater than 0.
116-
* See the transport layer for further details.
117-
*/
118-
agentKeepAliveIntervalTime: 10_000, // 10 seconds
119-
120-
/**
121-
* Agent service transport max idle timeout.
122-
* This is the maximum time that a connection can be idle.
123-
* This also controls how long the transport layer will dial
124-
* for a client connection.
125-
* See the transport layer for further details.
126-
*/
127-
agentMaxIdleTimeout: 60_000, // 1 minute
128-
129-
clientMaxIdleTimeout: 120, // 2 minutes
130-
clientPingIntervalTime: 1_000, // 1 second
131-
clientPingTimeoutTimeTime: 10_000, // 10 seconds
132-
133-
/**
134-
* Controls the stream parser buffer limit.
135-
* This is the maximum number of bytes that the stream parser
136-
* will buffer before rejecting the RPC call.
137-
*/
138-
clientParserBufferByteLimit: 1_000_000, // About 1MB
139-
clientHandlerTimeoutTime: 60_000, // 1 minute
140-
clientHandlerTimeoutGraceTime: 2_000, // 2 seconds
141-
},
142-
nodeConnectionManagerConfig: {
143-
connectionConnectTime: 2000,
144-
connectionTimeoutTime: 60000,
145-
initialClosestNodes: 3,
146-
pingTimeoutTime: 2000,
147-
connectionHolePunchTimeoutTime: 4000,
148-
connectionHolePunchIntervalTime: 250,
149-
},
150-
// This is not used by the `PolykeyAgent` which defaults to `{}`
151-
network: {
152-
mainnet: mainnet,
153-
testnet: testnet,
154-
},
88+
},
89+
/**
90+
* This is not used by the `PolykeyAgent` which defaults to `{}`
91+
* In the future this will be replaced by `mainnet.polykey.com` and `testnet.polykey.com`.
92+
* Along with the domain we will have the root public key too.
93+
*
94+
* Information that is pre-configured during distribution:
95+
*
96+
* - Domain
97+
* - Root public key
98+
*
99+
* Information that is discovered over DNS (Authenticated DNS is optional):
100+
*
101+
* - IP address
102+
* - Port
103+
*
104+
* As long as the root public key is provided, it is sufficient to defeat poisoning
105+
* the network. The root public key should also be changed often to reduce the impact
106+
* of compromises. Finally the root public key can also be signed by a third party CA
107+
* providing an extra level of confidence. However this is not required.
108+
*/
109+
network: {
110+
mainnet: mainnet,
111+
testnet: testnet,
112+
},
113+
/**
114+
* Default system configuration.
115+
* These are not meant to be changed by the user.
116+
* These constants are tuned for optimal operation by the developers.
117+
*/
118+
defaultSystem: {
119+
/**
120+
* Controls the stream parser buffer limit.
121+
* This is the maximum number of bytes that the stream parser
122+
* will buffer before rejecting the RPC call.
123+
*/
124+
rpcParserBufferByteLimit: 1_000_000, // About 1MB
125+
rpcHandlerTimeoutTime: 60_000, // 1 minute
126+
rpcHandlerTimeoutGraceTime: 2_000, // 2 seconds
127+
128+
nodesInitialClosestNodes: 3,
129+
130+
nodesConnectionConnectTime: 2000,
131+
nodesConnectionTimeoutTime: 60000,
132+
133+
nodesConnectionHolePunchTimeoutTime: 4000,
134+
nodesConnectionHolePunchIntervalTime: 250,
135+
136+
nodesPingTimeoutTime: 2000,
137+
138+
clientTransportMaxIdleTimeoutTime: 120, // 2 minutes
139+
clientTransportPingIntervalTime: 1_000, // 1 second
140+
clientTransportPingTimeoutTime: 10_000, // 10 seconds
141+
142+
/**
143+
* Agent service transport keep alive interval time.
144+
* This the maxmum time between keep alive messages.
145+
* This only has effect if `agentMaxIdleTimeout` is greater than 0.
146+
* See the transport layer for further details.
147+
*/
148+
agentConnectionKeepAliveIntervalTime: 10_000, // 10 seconds
149+
/**
150+
* Agent service transport max idle timeout.
151+
* This is the maximum time that a connection can be idle.
152+
* This also controls how long the transport layer will dial
153+
* for a client connection.
154+
* See the transport layer for further details.
155+
*/
156+
agentConnectionMaxIdleTimeoutTime: 60_000, // 1 minute
157+
158+
159+
160+
161+
// Why are these done separately?
162+
// Shouldn't we have a consistent time from NCM down to agent connection?
163+
164+
// Transport layer is sort should be controlled separately?
165+
166+
},
167+
/**
168+
* Default user configuration.
169+
* These are meant to be changed by the user.
170+
* However the defaults here provide the average user experience.
171+
*/
172+
defaultsUser: {
173+
nodePath: getDefaultNodePath(),
174+
rootCertDuration: 31536000,
175+
/**
176+
* If using dual stack `::`, then this forces only IPv6 bindings.
177+
*/
178+
ipv6Only: false,
179+
/**
180+
* Agent host defaults to `::` dual stack.
181+
* This is because the agent service is supposed to be public.
182+
*/
183+
agentServiceHost: '::',
184+
agentServicePort: 0,
185+
/**
186+
* Client host defaults to `localhost`.
187+
* This will depend on the OS configuration.
188+
* Usually it will be IPv4 `127.0.0.1` or IPv6 `::1`.
189+
* This is because the client service is private most of the time.
190+
*/
191+
clientServiceHost: 'localhost',
192+
clientServicePort: 0,
155193
},
156194
};
157195

196+
type Config = typeof config;
197+
158198
export default config;
199+
200+
export type { Config };

src/nodes/NodeConnectionManager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import * as utils from '../utils';
3939
import { clientManifest as agentClientManifest } from '../agent/handlers/clientManifest';
4040
import * as keysUtils from '../keys/utils';
4141

42-
// TODO: check all locking and add cancellation for it.
43-
4442
type AgentClientManifest = typeof agentClientManifest;
4543

4644
type ConnectionAndTimer = {

src/schema/Schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Schema {
6161
this.statePath = statePath;
6262
this.stateVersionPath = path.join(
6363
statePath,
64-
config.defaults.stateVersionBase,
64+
config.paths.stateVersionBase,
6565
);
6666
this.stateVersion = stateVersion;
6767
this.fs = fs;

src/vaults/VaultManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class VaultManager {
145145
}) {
146146
this.logger = logger;
147147
this.vaultsPath = vaultsPath;
148-
this.efsPath = path.join(this.vaultsPath, config.defaults.efsBase);
148+
this.efsPath = path.join(this.vaultsPath, config.paths.efsBase);
149149
this.db = db;
150150
this.acl = acl;
151151
this.keyRing = keyRing;

0 commit comments

Comments
 (0)