@@ -20,6 +20,7 @@ import { ed25519Str } from '../utils/String';
20
20
import { SnodePool } from '../apis/snode_api/snodePool' ;
21
21
import { SnodePoolConstants } from '../apis/snode_api/snodePoolConstants' ;
22
22
import { desiredGuardCount , minimumGuardCount , ONION_REQUEST_HOPS } from './onionPathConstants' ;
23
+ import { OnionPathEmptyError } from '../utils/errors' ;
23
24
24
25
export function getOnionPathMinTimeout ( ) {
25
26
return DURATION . SECONDS ;
@@ -158,11 +159,14 @@ export async function getOnionPath({ toExclude }: { toExclude?: Snode }): Promis
158
159
window . inboxStore ?. dispatch ( updateOnionPaths ( [ ] ) ) ;
159
160
}
160
161
} else {
161
- const ipsOnly = onionPaths . map ( m =>
162
- m . map ( c => {
163
- return { ip : c . ip } ;
164
- } )
165
- ) ;
162
+ const ipsOnly = onionPaths
163
+ // NOTE Filter out nodes that have missing ip addresses since they are not valid
164
+ . filter ( m => m . filter ( c => c . ip ) )
165
+ . map ( m =>
166
+ m . map ( c => {
167
+ return { ip : c . ip } ;
168
+ } )
169
+ ) ;
166
170
if ( ! _ . isEqual ( window . inboxStore ?. getState ( ) . onionPaths . snodePaths , ipsOnly ) ) {
167
171
window . inboxStore ?. dispatch ( updateOnionPaths ( ipsOnly ) ) ;
168
172
}
@@ -171,11 +175,11 @@ export async function getOnionPath({ toExclude }: { toExclude?: Snode }): Promis
171
175
if ( ! toExclude ) {
172
176
// no need to exclude a node, then just return a random path from the list of path
173
177
if ( ! onionPaths || onionPaths . length === 0 ) {
174
- throw new Error ( 'No onion paths available' ) ;
178
+ throw new OnionPathEmptyError ( ) ;
175
179
}
176
180
const randomPathNoExclude = _ . sample ( onionPaths ) ;
177
181
if ( ! randomPathNoExclude ) {
178
- throw new Error ( 'No onion paths available' ) ;
182
+ throw new OnionPathEmptyError ( ) ;
179
183
}
180
184
return randomPathNoExclude ;
181
185
}
@@ -186,11 +190,11 @@ export async function getOnionPath({ toExclude }: { toExclude?: Snode }): Promis
186
190
) ;
187
191
188
192
if ( ! onionPathsWithoutExcluded || onionPathsWithoutExcluded . length === 0 ) {
189
- throw new Error ( 'No onion paths available after filtering' ) ;
193
+ throw new OnionPathEmptyError ( ) ;
190
194
}
191
195
const randomPath = _ . sample ( onionPathsWithoutExcluded ) ;
192
196
if ( ! randomPath ) {
193
- throw new Error ( 'No onion paths available after filtering' ) ;
197
+ throw new OnionPathEmptyError ( ) ;
194
198
}
195
199
return randomPath ;
196
200
}
0 commit comments