-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce shadowsocks request and decoding capabilities
- Loading branch information
1 parent
536a9d7
commit 4b9e63f
Showing
19 changed files
with
512 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...idMain/kotlin/com/privateinternetaccess/regions/internals/RegionsDataSourceFactoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 26 additions & 7 deletions
33
...Main/kotlin/com/privateinternetaccess/regions/internals/InMemoryRegionsCacheDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
package com.privateinternetaccess.regions.internals | ||
|
||
import com.privateinternetaccess.regions.model.RegionsResponse | ||
import com.privateinternetaccess.regions.model.ShadowsocksRegionsResponse | ||
import com.privateinternetaccess.regions.model.VpnRegionsResponse | ||
|
||
|
||
internal class InMemoryRegionsCacheDataSource: RegionsCacheDataSource { | ||
private var cacheEntry: CacheEntry? = null | ||
private var vpnRegionsCacheEntry: CacheEntry? = null | ||
private var shadowsocksRegionsEntry: List<ShadowsocksRegionsResponse> = emptyList() | ||
|
||
override fun saveRegion(locale: String, regionsResponse: RegionsResponse) { | ||
this.cacheEntry = CacheEntry( | ||
override fun saveVpnRegions(locale: String, regionsResponse: VpnRegionsResponse) { | ||
this.vpnRegionsCacheEntry = CacheEntry( | ||
locale = locale, | ||
regionsResponse = regionsResponse | ||
) | ||
} | ||
|
||
override fun getRegion(locale: String?): Result<RegionsResponse> { | ||
val cacheEntry: CacheEntry? = this.cacheEntry | ||
override fun getVpnRegions(locale: String?): Result<VpnRegionsResponse> { | ||
val cacheEntry: CacheEntry? = this.vpnRegionsCacheEntry | ||
return when { | ||
cacheEntry != null && (locale == null || cacheEntry.locale == locale) -> Result.success(cacheEntry.regionsResponse) | ||
else -> Result.failure(CacheError(locale)) | ||
} | ||
} | ||
} | ||
|
||
override fun saveShadowsocksRegions( | ||
locale: String, | ||
response: List<ShadowsocksRegionsResponse> | ||
) { | ||
this.shadowsocksRegionsEntry = response | ||
} | ||
|
||
override fun getShadowsocksRegions( | ||
locale: String? | ||
): Result<List<ShadowsocksRegionsResponse>> { | ||
return when { | ||
shadowsocksRegionsEntry.isNotEmpty() -> Result.success(shadowsocksRegionsEntry) | ||
else -> Result.failure(Error("Shadowsocks entry is empty")) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...s/src/commonMain/kotlin/com/privateinternetaccess/regions/internals/MessageVerificator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.privateinternetaccess.regions.internals | ||
|
||
internal expect object MessageVerificator { | ||
|
||
/** | ||
* @param message String. Message to verify. | ||
* @param key String. Verification key. | ||
*/ | ||
fun verifyMessage(message: String, key: String): Boolean | ||
} |
15 changes: 15 additions & 0 deletions
15
regions/src/commonMain/kotlin/com/privateinternetaccess/regions/internals/PingPerformer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.privateinternetaccess.regions.internals | ||
|
||
internal expect class PingPerformer() { | ||
|
||
/** | ||
* @param endpoints Map<String, List<String>>. Key: Region. List<String>: Endpoints within the | ||
* region. | ||
* @param callback Map<String, List<Pair<String, Long>>>. Key: Region. | ||
* List<Pair<String, Long>>>: Endpoints and latencies within the region. | ||
*/ | ||
fun pingEndpoints( | ||
endpoints: Map<String, List<String>>, | ||
callback: (result: Map<String, List<Pair<String, Long>>>) -> Unit | ||
) | ||
} |
19 changes: 19 additions & 0 deletions
19
...ons/src/commonMain/kotlin/com/privateinternetaccess/regions/internals/RegionHttpClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.privateinternetaccess.regions.internals | ||
|
||
import io.ktor.client.HttpClient | ||
|
||
|
||
internal expect object RegionHttpClient { | ||
|
||
/** | ||
* @param certificate String?. Certificate required for pinning capabilities. | ||
* @param pinnedEndpoint Pair<String, String>?. Contains endpoint as first, | ||
* commonName as second. | ||
* | ||
* @return `Pair<HttpClient?, Exception?>`. | ||
*/ | ||
fun client( | ||
certificate: String? = null, | ||
pinnedEndpoint: Pair<String, String>? = null | ||
): Pair<HttpClient?, Exception?> | ||
} |
Oops, something went wrong.