paid-services 3.19.0 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/trades/connect_to_seller.js +57 -4
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"integration-tests": "tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
|
|
48
48
|
"test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.js test/balanced/*.js test/capacity/*.js test/client/*.js test/config/*.js test/p2p/*.js test/records/*.js test/respond/*.js test/server/*.js test/server/*.js test/services/*.js test/trades/*.js"
|
|
49
49
|
},
|
|
50
|
-
"version": "3.19.
|
|
50
|
+
"version": "3.19.1"
|
|
51
51
|
}
|
|
@@ -2,12 +2,15 @@ const {addPeer} = require('ln-service');
|
|
|
2
2
|
const asyncAuto = require('async/auto');
|
|
3
3
|
const asyncDetect = require('async/detect');
|
|
4
4
|
const asyncDetectSeries = require('async/detectSeries');
|
|
5
|
+
const asyncEach = require('async/each');
|
|
5
6
|
const asyncMap = require('async/map');
|
|
6
7
|
const asyncRetry = require('async/retry');
|
|
7
8
|
const {getChannel} = require('ln-service');
|
|
9
|
+
const {getChannels} = require('ln-service');
|
|
8
10
|
const {getIdentity} = require('ln-service');
|
|
9
11
|
const {getNode} = require('ln-service');
|
|
10
12
|
const {getPeers} = require('ln-service');
|
|
13
|
+
const {removePeer} = require('ln-service');
|
|
11
14
|
const {returnResult} = require('asyncjs-util');
|
|
12
15
|
|
|
13
16
|
const interval = 1000;
|
|
@@ -55,12 +58,14 @@ module.exports = ({lnd, logger, nodes}, cbk) => {
|
|
|
55
58
|
return cbk();
|
|
56
59
|
},
|
|
57
60
|
|
|
61
|
+
// Get the channels to see if this is a channel peer
|
|
62
|
+
getChannels: ['validate', ({}, cbk) => {
|
|
63
|
+
return getChannels({lnd, is_active: true}, cbk);
|
|
64
|
+
}],
|
|
65
|
+
|
|
58
66
|
// Derive the self public key
|
|
59
67
|
getIdentity: ['validate', ({}, cbk) => getIdentity({lnd}, cbk)],
|
|
60
68
|
|
|
61
|
-
// Get the list of connected peers
|
|
62
|
-
getPeers: ['validate', ({}, cbk) => getPeers({lnd}, cbk)],
|
|
63
|
-
|
|
64
69
|
// Find node connect info to connect to
|
|
65
70
|
getNodes: ['getIdentity', ({getIdentity}, cbk) => {
|
|
66
71
|
return asyncMap(nodes, (connect, cbk) => {
|
|
@@ -135,8 +140,56 @@ module.exports = ({lnd, logger, nodes}, cbk) => {
|
|
|
135
140
|
cbk);
|
|
136
141
|
}],
|
|
137
142
|
|
|
143
|
+
// Remove the peer if there is no channel peer to avoid stale peers
|
|
144
|
+
removePeer: [
|
|
145
|
+
'getChannels',
|
|
146
|
+
'getNodes',
|
|
147
|
+
({getChannels, getNodes}, cbk) =>
|
|
148
|
+
{
|
|
149
|
+
const ids = getChannels.channels.map(n => n.partner_public_key);
|
|
150
|
+
|
|
151
|
+
return asyncEach(getNodes, (node, cbk) => {
|
|
152
|
+
// Exit early when there is no node id
|
|
153
|
+
if (!node || !node.id || ids.includes(node.id)) {
|
|
154
|
+
return cbk();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return removePeer({lnd, public_key: node.id}, (err, res) => {
|
|
158
|
+
if (!!err) {
|
|
159
|
+
return cbk(err);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return asyncRetry({interval, times}, cbk => {
|
|
163
|
+
return getPeers({lnd}, (err, res) => {
|
|
164
|
+
if (!!err) {
|
|
165
|
+
return cbk(err);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const peers = res.peers.map(n => n.public_key);
|
|
169
|
+
|
|
170
|
+
if (!!peers.includes(node.id)) {
|
|
171
|
+
return cbk([503, 'FailedToDisconnectSellerPeer']);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return cbk();
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
cbk);
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
cbk);
|
|
181
|
+
}],
|
|
182
|
+
|
|
183
|
+
// Get the list of connected peers
|
|
184
|
+
getPeers: ['removePeer', ({}, cbk) => getPeers({lnd}, cbk)],
|
|
185
|
+
|
|
138
186
|
// Try and connect to a node in order to do p2p messaging
|
|
139
|
-
connect: [
|
|
187
|
+
connect: [
|
|
188
|
+
'getNodes',
|
|
189
|
+
'getPeers',
|
|
190
|
+
'removePeer',
|
|
191
|
+
({getNodes, getPeers}, cbk) =>
|
|
192
|
+
{
|
|
140
193
|
const connected = getPeers.peers.map(n => n.public_key);
|
|
141
194
|
|
|
142
195
|
// Look for a node that is already a connected peer
|