|
@@ -61,7 +61,9 @@ exports.rpcToRpcinfo = (rpc, owner) => {
|
61
|
61
|
};
|
62
|
62
|
}
|
63
|
63
|
};
|
64
|
|
-exports.rpcHooker = (socket, owner, RPCs, makeUnique = true) => {
|
|
64
|
+function rpcHooker(socket, exporter, makeUnique = true) {
|
|
65
|
+ const owner = exporter.name;
|
|
66
|
+ const RPCs = [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()];
|
65
|
67
|
const suffix = makeUnique ? "-" + uuid().substr(0, 4) : "";
|
66
|
68
|
return RPCs.map(rpc => exports.rpcToRpcinfo(rpc, owner))
|
67
|
69
|
.map(info => {
|
|
@@ -77,7 +79,7 @@ exports.rpcHooker = (socket, owner, RPCs, makeUnique = true) => {
|
77
|
79
|
socket.on('close', () => socket.unhook(info.name));
|
78
|
80
|
return ret;
|
79
|
81
|
});
|
80
|
|
-};
|
|
82
|
+}
|
81
|
83
|
const hookGenerator = (rpc) => {
|
82
|
84
|
const argsArr = extractArgs(rpc.func);
|
83
|
85
|
argsArr.pop();
|
|
@@ -124,9 +126,9 @@ class RPCSocketServer {
|
124
|
126
|
socket.on('error', this.conf.errorHandler(socket));
|
125
|
127
|
socket.on('close', this.conf.closeHandler(socket));
|
126
|
128
|
if (this.visibility === "127.0.0.1")
|
127
|
|
- this.initApis(socket);
|
|
129
|
+ this.initRPCs(socket);
|
128
|
130
|
else
|
129
|
|
- this.initPublicApis(socket);
|
|
131
|
+ this.initPublicRPCs(socket);
|
130
|
132
|
});
|
131
|
133
|
this.wsServer.listen(this.port, this.visibility);
|
132
|
134
|
}
|
|
@@ -135,30 +137,16 @@ class RPCSocketServer {
|
135
|
137
|
this.errorHandler(undefined)("Unable to connect to socket");
|
136
|
138
|
}
|
137
|
139
|
}
|
138
|
|
- initApis(socket) {
|
139
|
|
- const adminRPCs = [
|
140
|
|
- {
|
141
|
|
- name: 'info',
|
142
|
|
- type: 'call',
|
143
|
|
- func: async () => rpcInfos
|
144
|
|
- }
|
145
|
|
- ];
|
|
140
|
+ initRPCs(socket) {
|
|
141
|
+ socket.hook('info', () => rpcInfos);
|
146
|
142
|
const rpcInfos = [
|
147
|
|
- ...exports.rpcHooker(socket, "Admin", adminRPCs, false),
|
148
|
|
- ...this.rpcExporters.flatMap(exporter => exports.rpcHooker(socket, exporter.name, [...exporter.exportPublicRPCs(), ...exporter.exportRPCs()]))
|
|
143
|
+ ...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter))
|
149
|
144
|
];
|
150
|
145
|
}
|
151
|
|
- initPublicApis(socket) {
|
152
|
|
- const adminRPCs = [
|
153
|
|
- {
|
154
|
|
- name: 'info',
|
155
|
|
- type: 'call',
|
156
|
|
- func: async () => rpcInfos
|
157
|
|
- }
|
158
|
|
- ];
|
|
146
|
+ initPublicRPCs(socket) {
|
|
147
|
+ socket.hook('info', () => rpcInfos);
|
159
|
148
|
const rpcInfos = [
|
160
|
|
- ...exports.rpcHooker(socket, "Admin", adminRPCs, false),
|
161
|
|
- ...this.rpcExporters.flatMap(exporter => exports.rpcHooker(socket, exporter.name, exporter.exportPublicRPCs()))
|
|
149
|
+ ...this.rpcExporters.flatMap(exporter => rpcHooker(socket, exporter))
|
162
|
150
|
];
|
163
|
151
|
}
|
164
|
152
|
}
|