@@ -23,7 +23,7 @@ const debug = DebugModule("wt-tracker:fast-tracker");
2323const ldebug = ldebugConstructor ( debug ) ;
2424
2525export class FastTracker implements Tracker {
26- private swarms = new Map < string , Swarm > ( ) ;
26+ private _swarms = new Map < string , Swarm > ( ) ;
2727
2828 constructor ( readonly settings : any = { } ) {
2929 this . settings = {
@@ -33,6 +33,10 @@ export class FastTracker implements Tracker {
3333 } ;
3434 }
3535
36+ public get swarms ( ) : ReadonlyMap < string , { peers : ReadonlyMap < string , PeerContext > } > {
37+ return this . _swarms ;
38+ }
39+
3640 public processMessage ( json : any , peer : PeerContext ) {
3741 const action : any = json . action ;
3842
@@ -74,7 +78,7 @@ export class FastTracker implements Tracker {
7478 swarm . removePeer ( peer ) ;
7579 if ( swarm . peers . size === 0 ) {
7680 ldebug ( ( ) => [ "swarm removed (empty)" , Buffer . from ( swarm . infoHash ) . toString ( "hex" ) ] ) ;
77- this . swarms . delete ( swarm . infoHash ) ;
81+ this . _swarms . delete ( swarm . infoHash ) ;
7882 } else if ( swarmContext . completed ) {
7983 swarm . completedCount -- ;
8084 }
@@ -128,7 +132,7 @@ export class FastTracker implements Tracker {
128132 }
129133
130134 private addPeerToSwarm ( peer : InternalPeerContext , infoHash : any ) {
131- let swarm = this . swarms . get ( infoHash ) ;
135+ let swarm = this . _swarms . get ( infoHash ) ;
132136
133137 if ( swarm === undefined ) {
134138 if ( typeof infoHash !== "string" ) {
@@ -137,7 +141,7 @@ export class FastTracker implements Tracker {
137141
138142 ldebug ( ( ) => [ "announce: swarm created:" , Buffer . from ( infoHash ) . toString ( "hex" ) ] ) ;
139143 swarm = new Swarm ( infoHash ) ;
140- this . swarms . set ( infoHash , swarm ) ;
144+ this . _swarms . set ( infoHash , swarm ) ;
141145 }
142146
143147 ldebug ( ( ) => [ "announce: peer" , Buffer . from ( peer . id ! ) . toString ( "hex" ) , "added to swarm" , Buffer . from ( infoHash ) . toString ( "hex" ) ] ) ;
@@ -243,7 +247,7 @@ export class FastTracker implements Tracker {
243247
244248 if ( swarm . peers . size === 0 ) {
245249 ldebug ( ( ) => [ "stop event: swarm removed (empty)" , Buffer . from ( infoHash ) . toString ( "hex" ) ] ) ;
246- this . swarms . delete ( infoHash ) ;
250+ this . _swarms . delete ( infoHash ) ;
247251 }
248252 }
249253
@@ -252,7 +256,7 @@ export class FastTracker implements Tracker {
252256 const files : { [ key : string ] : { complete : number , incomplete : number , downloaded : number } } = { } ;
253257
254258 if ( infoHash === undefined ) {
255- for ( const swarm of this . swarms . values ( ) ) {
259+ for ( const swarm of this . _swarms . values ( ) ) {
256260 files [ swarm . infoHash ] = {
257261 complete : swarm . completedCount ,
258262 incomplete : swarm . peersOrdered . length - swarm . completedCount ,
@@ -261,7 +265,7 @@ export class FastTracker implements Tracker {
261265 }
262266 } else if ( infoHash instanceof Array ) {
263267 for ( const singleInfoHash of infoHash ) {
264- const swarm = this . swarms . get ( singleInfoHash ) ;
268+ const swarm = this . _swarms . get ( singleInfoHash ) ;
265269 if ( swarm !== undefined ) {
266270 files [ singleInfoHash ] = {
267271 complete : swarm . completedCount ,
@@ -277,7 +281,7 @@ export class FastTracker implements Tracker {
277281 }
278282 }
279283 } else {
280- const swarm = this . swarms . get ( infoHash ) ;
284+ const swarm = this . _swarms . get ( infoHash ) ;
281285 if ( swarm !== undefined ) {
282286 files [ infoHash ] = {
283287 complete : swarm . completedCount ,
@@ -298,17 +302,6 @@ export class FastTracker implements Tracker {
298302 files : files ,
299303 } ) ;
300304 }
301-
302- public get stats ( ) {
303- let peersCount = 0 ;
304- for ( const swarm of this . swarms . values ( ) ) {
305- peersCount += swarm . peers . size ;
306- }
307- return {
308- torrentsCount : this . swarms . size ,
309- peersCount : peersCount ,
310- } ;
311- }
312305}
313306
314307interface SwarmContext {
0 commit comments