@@ -4,15 +4,17 @@ import (
4
4
"compress/zlib"
5
5
"encoding/base64"
6
6
"fmt"
7
- "github.com/andres-erbsen/torch/config"
8
- "github.com/andres-erbsen/torch/directory"
7
+ mathrand "math/rand"
9
8
"net"
10
9
"net/http"
11
10
"strconv"
12
11
"strings"
13
12
"sync"
14
13
"time"
15
14
15
+ "github.com/andres-erbsen/torch/config"
16
+ "github.com/andres-erbsen/torch/directory"
17
+
16
18
"golang.org/x/net/context"
17
19
"golang.org/x/net/proxy"
18
20
)
@@ -193,13 +195,13 @@ func (t *Torch) WithDirectory(f func(*directory.Directory) interface{}) interfac
193
195
return f (t .cachedDir )
194
196
}
195
197
196
- func (t * Torch ) Pick (weighWith func (w * directory.BandwidthWeights , n * directory.NodeInfo ) int64 ) * directory.NodeInfo {
198
+ func (t * Torch ) Pick (weighWith func (w * directory.BandwidthWeights , n * directory.NodeInfo ) int64 , rnd * mathrand. Rand ) * directory.NodeInfo {
197
199
weigh := func (n * directory.NodeInfo ) int64 {
198
200
return weighWith (& t .cachedDir .Consensus .BandwidthWeights , n )
199
201
}
200
202
201
203
return t .WithDirectory (func (d * directory.Directory ) interface {} {
202
- return directory .Pick (weigh , d .Routers , nil )
204
+ return directory .Pick (weigh , d .Routers , rnd )
203
205
}).(* directory.NodeInfo )
204
206
205
207
}
@@ -217,7 +219,7 @@ func (t *Torch) UnguardedCircuitTo(ctx context.Context, n int, dst *directory.No
217
219
218
220
nodes := make ([]* directory.NodeInfo , n )
219
221
for i := 0 ; i <= n - 2 ; i ++ {
220
- nodes [i ] = t .Pick (weighRelayWith )
222
+ nodes [i ] = t .Pick (weighRelayWith , nil )
221
223
}
222
224
nodes [n - 1 ] = dst
223
225
@@ -250,7 +252,7 @@ func BuildCircuit(ctx context.Context, dialer proxy.Dialer, nodes []*directory.N
250
252
}
251
253
252
254
func (t * Torch ) UnguardedExitCircuit (ctx context.Context , n int ) (* TorConn , * Circuit , error ) {
253
- return t .UnguardedCircuitTo (ctx , n , t .Pick (weighExitWith ))
255
+ return t .UnguardedCircuitTo (ctx , n , t .Pick (weighExitWith , nil ))
254
256
}
255
257
256
258
func (t * Torch ) Stop () error {
0 commit comments