Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #1307: Upgrade adblock stats library to use adblock-rust. (#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored and jhreis committed Aug 10, 2019
1 parent 7bf173e commit 40dfc7c
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 343 deletions.
4 changes: 2 additions & 2 deletions Client-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
#import "Shared-Bridging-Header.h"
#import "Storage-Bridging-Header.h"

#import "ABPFilterLibWrapper.h"

#import "HttpsEverywhereObjC.h"
#import "NSData+GZIP.h"
#import "NSFileManager+Tar.h"

#import <YubiKit/YubiKit.h>
#import <CommonCrypto/CommonCrypto.h>

#import "ablock_rust_lib.h"

#endif
125 changes: 32 additions & 93 deletions Client.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Client/WebFilters/AdblockResourceDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class AdblockResourceDownloader {
private let networkManager: NetworkManager
private let locale: String

private let endpoint = "https://adblock-data.s3.brave.com/ios/"
static let folderName = "abp-data"

init(networkManager: NetworkManager = NetworkManager(), locale: String? = Locale.current.languageCode) {
Expand Down Expand Up @@ -64,17 +63,16 @@ class AdblockResourceDownloader {
let queue = DispatchQueue(label: queueName)
let nm = networkManager
let folderName = AdblockResourceDownloader.folderName
// name of the file on server
let resourceName = type.resourceName

// file name of which the file will be saved on disk
let fileName = type.identifier

let completedDownloads = type.associatedFiles.map { fileType -> Deferred<AdBlockNetworkResource> in
let fileExtension = "." + fileType.rawValue
let etagExtension = fileExtension + ".etag"

guard let resourceName = resourceName,
let url = URL(string: endpoint + resourceName + fileExtension) else {
guard let resourceName = type.resourceName(for: fileType),
let url = URL(string: fileType.endpoint + resourceName + fileExtension) else {
return Deferred<AdBlockNetworkResource>()
}

Expand Down
77 changes: 46 additions & 31 deletions Client/WebFilters/AdblockResourcesMappings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
import Foundation

struct AdblockResourcesMappings {
static let generalAdblockName = "latest"
static func generalAdblockName(for fileType: FileType) -> String? {
switch fileType {
case .dat: return "rs-ABPFilterParserData"
case .json: return "latest"
default: return nil
}
}

static let generalHttpseName = "httpse"
static let defaultLocale = "en"
}
Expand All @@ -14,37 +21,45 @@ enum ResourceLocale: String {
case ar, bg, zh, cs, de, da, et, fi, fr, el, hu, id, hi, fa, `is`, he, it, ja, ko, lt, lv, nl,
pl, ru, uk, be, es, sl, sv, tr, vi

var resourceName: String {
func resourceName(for fileType: FileType) -> String {
var resourceId = ""

switch self {
case .ar: return "9FCEECEC-52B4-4487-8E57-8781E82C91D0-latest"
case .bg: return "FD176DD1-F9A0-4469-B43E-B1764893DD5C-latest"
case .zh: return "11F62B02-9D1F-4263-A7F8-77D2B55D4594-latest"
case .cs: return "7CCB6921-7FDA-4A9B-B70A-12DD0A8F08EA-latest"
case .de: return "E71426E7-E898-401C-A195-177945415F38-latest"
case .da: return "9EF6A21C-5014-4199-95A2-A82491274203-latest"
case .et: return "0783DBFD-B5E0-4982-9B4A-711BDDB925B7-latest"
case .fi: return "1C6D8556-3400-4358-B9AD-72689D7B2C46-latest"
case .fr: return "9852EFC4-99E4-4F2D-A915-9C3196C7A1DE-latest"
case .el: return "6C0F4C7F-969B-48A0-897A-14583015A587-latest"
case .hu: return "EDEEE15A-6FA9-4FAC-8CA8-3565508EAAC3-latest"
case .id: return "93123971-5AE6-47BA-93EA-BE1E4682E2B6-latest"
case .hi: return "4C07DB6B-6377-4347-836D-68702CF1494A-latest"
case .fa: return "C3C2F394-D7BB-4BC2-9793-E0F13B2B5971-latest"
case .is: return "48796273-E783-431E-B864-44D3DCEA66DC-latest"
case .he: return "85F65E06-D7DA-4144-B6A5-E1AA965D1E47-latest"
case .it: return "AB1A661D-E946-4F29-B47F-CA3885F6A9F7-latest"
case .ja: return "03F91310-9244-40FA-BCF6-DA31B832F34D-latest"
case .ko: return "1E6CF01B-AFC4-47D2-AE59-3E32A1ED094F-latest"
case .lt: return "4E8B1A63-DEBE-4B8B-AD78-3811C632B353-latest"
case .lv: return "15B64333-BAF9-4B77-ADC8-935433CD6F4C-latest"
case .nl: return "9D644676-4784-4982-B94D-C9AB19098D2A-latest"
case .pl: return "BF9234EB-4CB7-4CED-9FCB-F1FD31B0666C-latest"
case .ru, .uk, .be: return "80470EEC-970F-4F2C-BF6B-4810520C72E6-latest"
case .es: return "AE657374-1851-4DC4-892B-9212B13B15A7-latest"
case .sl: return "418D293D-72A8-4A28-8718-A1EE40A45AAF-latest"
case .sv: return "7DC2AC80-5BBC-49B8-B473-A31A1145CAC1-latest"
case .tr: return "1BE19EFD-9191-4560-878E-30ECA72B5B3C-latest"
case .vi: return "6A0209AC-9869-4FD6-A9DF-039B4200D52C-latest"
case .ar: resourceId = "9FCEECEC-52B4-4487-8E57-8781E82C91D0"
case .bg: resourceId = "FD176DD1-F9A0-4469-B43E-B1764893DD5C"
case .zh: resourceId = "11F62B02-9D1F-4263-A7F8-77D2B55D4594"
case .cs: resourceId = "7CCB6921-7FDA-4A9B-B70A-12DD0A8F08EA"
case .de: resourceId = "E71426E7-E898-401C-A195-177945415F38"
case .da: resourceId = "9EF6A21C-5014-4199-95A2-A82491274203"
case .et: resourceId = "0783DBFD-B5E0-4982-9B4A-711BDDB925B7"
case .fi: resourceId = "1C6D8556-3400-4358-B9AD-72689D7B2C46"
case .fr: resourceId = "9852EFC4-99E4-4F2D-A915-9C3196C7A1DE"
case .el: resourceId = "6C0F4C7F-969B-48A0-897A-14583015A587"
case .hu: resourceId = "EDEEE15A-6FA9-4FAC-8CA8-3565508EAAC3"
case .id: resourceId = "93123971-5AE6-47BA-93EA-BE1E4682E2B6"
case .hi: resourceId = "4C07DB6B-6377-4347-836D-68702CF1494A"
case .fa: resourceId = "C3C2F394-D7BB-4BC2-9793-E0F13B2B5971"
case .is: resourceId = "48796273-E783-431E-B864-44D3DCEA66DC"
case .he: resourceId = "85F65E06-D7DA-4144-B6A5-E1AA965D1E47"
case .it: resourceId = "AB1A661D-E946-4F29-B47F-CA3885F6A9F7"
case .ja: resourceId = "03F91310-9244-40FA-BCF6-DA31B832F34D"
case .ko: resourceId = "1E6CF01B-AFC4-47D2-AE59-3E32A1ED094F"
case .lt: resourceId = "4E8B1A63-DEBE-4B8B-AD78-3811C632B353"
case .lv: resourceId = "15B64333-BAF9-4B77-ADC8-935433CD6F4C"
case .nl: resourceId = "9D644676-4784-4982-B94D-C9AB19098D2A"
case .pl: resourceId = "BF9234EB-4CB7-4CED-9FCB-F1FD31B0666C"
case .ru, .uk, .be: resourceId = "80470EEC-970F-4F2C-BF6B-4810520C72E6"
case .es: resourceId = "AE657374-1851-4DC4-892B-9212B13B15A7"
case .sl: resourceId = "418D293D-72A8-4A28-8718-A1EE40A45AAF"
case .sv: resourceId = "7DC2AC80-5BBC-49B8-B473-A31A1145CAC1"
case .tr: resourceId = "1BE19EFD-9191-4560-878E-30ECA72B5B3C"
case .vi: resourceId = "6A0209AC-9869-4FD6-A9DF-039B4200D52C"
}

switch fileType {
case .dat: return "rs-" + resourceId
case .json: return resourceId + "-latest"
case .tgz: return ""
}
}
}
18 changes: 14 additions & 4 deletions Client/WebFilters/AdblockerType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ import Shared

private let log = Logger.browserLogger

enum FileType: String { case dat, json, tgz }
enum FileType: String {
case dat, json, tgz

var endpoint: String {
switch self {
case .dat: return "https://adblock-data.s3.brave.com/4/"
case .json: return "https://adblock-data.s3.brave.com/ios/"
case .tgz: return "" // Httpse resources are not supported yet.
}
}
}

enum AdblockerType {
case general
Expand Down Expand Up @@ -39,11 +49,11 @@ enum AdblockerType {
}

/// A name under which given resource is stored on server.
var resourceName: String? {
func resourceName(for fileType: FileType) -> String? {
switch self {
case .general: return AdblockResourcesMappings.generalAdblockName
case .general: return AdblockResourcesMappings.generalAdblockName(for: fileType)
case .httpse: return AdblockResourcesMappings.generalHttpseName
case .regional(let locale): return ResourceLocale(rawValue: locale)?.resourceName
case .regional(let locale): return ResourceLocale(rawValue: locale)?.resourceName(for: fileType)
}
}

Expand Down
10 changes: 0 additions & 10 deletions Client/WebFilters/ShieldStats/Adblock/ABPFilterLibWrapper.h

This file was deleted.

95 changes: 0 additions & 95 deletions Client/WebFilters/ShieldStats/Adblock/ABPFilterLibWrapper.mm

This file was deleted.

Binary file not shown.
Loading

0 comments on commit 40dfc7c

Please sign in to comment.