@@ -37,6 +37,9 @@ function HeuristicBlocker(pbStorage) {
37
37
// impossible to attribute to a tab.
38
38
this . tabOrigins = { } ;
39
39
this . tabUrls = { } ;
40
+
41
+ // in-memory cache for community learning
42
+ this . previouslySharedTrackers = new Set ( ) ;
40
43
}
41
44
42
45
HeuristicBlocker . prototype = {
@@ -356,6 +359,29 @@ HeuristicBlocker.prototype = {
356
359
shareTrackerInfo : function ( page_host , tracker_host , tracker_type ) {
357
360
// Share a random sample of trackers we observe
358
361
if ( Math . random ( ) < constants . CL_PROBABILITY ) {
362
+ // check if we've shared this tracker recently
363
+ // note that this check comes after checking against the snitch map
364
+ let tr_str = page_host + '+' + tracker_host + '+' + tracker_type ;
365
+ if ( this . previouslySharedTrackers . has ( tr_str ) ) {
366
+ return ;
367
+ }
368
+
369
+ // add this entry to the cache
370
+ this . previouslySharedTrackers . add ( tr_str ) ;
371
+
372
+ // if the cache gets too big, cut it in half
373
+ if ( this . previouslySharedTrackers . size > constants . CL_CACHE_SIZE ) {
374
+ this . previouslySharedTrackers = new Set (
375
+ // An array created from the set will have all of its entries ordered
376
+ // by when they were added
377
+ Array . from ( this . previouslySharedTrackers ) . slice (
378
+ // keep the most recent half of the cache entries
379
+ Math . floor ( constants . CL_CACHE_SIZE / 2 )
380
+ )
381
+ ) ;
382
+ }
383
+
384
+ // now make the request to the database server
359
385
setTimeout ( function ( ) {
360
386
fetch ( "http://localhost:8080" , {
361
387
method : "POST" ,
0 commit comments