File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -89,18 +89,20 @@ function dial (swtch) {
89
89
90
90
const tKeys = swtch . availableTransports ( pi )
91
91
92
+ const circuitEnabled = Boolean ( swtch . transports [ Circuit . tag ] )
92
93
let circuitTried = false
93
94
nextTransport ( tKeys . shift ( ) )
94
95
95
96
function nextTransport ( key ) {
96
97
let transport = key
97
98
if ( ! transport ) {
98
- if ( circuitTried ) {
99
- return cb ( new Error ( `Circuit already tried!` ) )
99
+ if ( ! circuitEnabled ) {
100
+ const msg = `Circuit not enabled and all transports failed to dial peer ${ pi . id . toB58String ( ) } !`
101
+ return cb ( new Error ( msg ) )
100
102
}
101
103
102
- if ( ! swtch . transports [ Circuit . tag ] ) {
103
- return cb ( new Error ( `Circuit not enabled !` ) )
104
+ if ( circuitTried ) {
105
+ return cb ( new Error ( `No available transports to dial peer ${ pi . id . toB58String ( ) } !` ) )
104
106
}
105
107
106
108
log ( `Falling back to dialing over circuit` )
Original file line number Diff line number Diff line change @@ -54,6 +54,15 @@ describe(`circuit`, function () {
54
54
] , done )
55
55
} )
56
56
57
+ it ( 'circuit not enabled and all transports failed' , ( done ) => {
58
+ swarmA . dial ( swarmC . _peerInfo , ( err , conn ) => {
59
+ expect ( err ) . to . exist ( )
60
+ expect ( err ) . to . match ( / C i r c u i t n o t e n a b l e d a n d a l l t r a n s p o r t s f a i l e d t o d i a l p e e r / )
61
+ expect ( conn ) . to . not . exist ( )
62
+ done ( )
63
+ } )
64
+ } )
65
+
57
66
it ( '.enableCircuitRelay' , ( ) => {
58
67
swarmA . connection . enableCircuitRelay ( { enabled : true } )
59
68
expect ( Object . keys ( swarmA . transports ) . length ) . to . equal ( 3 )
@@ -88,7 +97,7 @@ describe(`circuit`, function () {
88
97
89
98
swarmA . dial ( swarmC . _peerInfo , ( err , conn ) => {
90
99
expect ( err ) . to . exist ( )
91
- expect ( err ) . to . match ( / C i r c u i t a l r e a d y t r i e d ! / )
100
+ expect ( err ) . to . match ( / N o a v a i l a b l e t r a n s p o r t s t o d i a l p e e r / )
92
101
expect ( conn ) . to . not . exist ( )
93
102
expect ( dialSpyA . callCount ) . to . be . eql ( 1 )
94
103
done ( )
You can’t perform that action at this time.
0 commit comments