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

feat: add expiry optional #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/src/main/java/net/nymtech/nymvpn/ui/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ constructor(
AppUiState(),
)

private fun setCredentialExpiry(instant: Instant) {
_uiState.update {
it.copy(
credentialExpiryTime = instant,
)
private fun setCredentialExpiry(instant: Instant?) {
instant?.let {
_uiState.update {
it.copy(
credentialExpiryTime = instant,
)
}
}
}

Expand All @@ -102,7 +104,7 @@ constructor(
}
}

suspend fun onValidCredentialCheck(): Result<Instant> {
suspend fun onValidCredentialCheck(): Result<Instant?> {
return withContext(viewModelScope.coroutineContext) {
val credential = secretsRepository.get().getCredential()
if (credential != null) {
Expand All @@ -113,7 +115,7 @@ constructor(
}
}

private suspend fun getCredentialExpiry(credential: String): Result<Instant> {
private suspend fun getCredentialExpiry(credential: String): Result<Instant?> {
return vpnClient.get().validateCredential(credential).onFailure {
return Result.failure(NymVpnExceptions.InvalidCredentialException())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ constructor(
private val vpnClient: Provider<VpnClient>,
) : ViewModel() {

suspend fun onImportCredential(credential: String): Result<Instant> {
suspend fun onImportCredential(credential: String): Result<Instant?> {
val trimmedCred = credential.trim()
return withContext(viewModelScope.coroutineContext) {
vpnClient.get().validateCredential(trimmedCred).onSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,21 @@ object LogcatHelper {
val outputFilePath = Paths.get(outputFile.absolutePath)
val logcatPath = Paths.get(sourceDir)

Files.list(logcatPath)
.sorted { o1, o2 ->
Files.list(logcatPath).use {
it.sorted { o1, o2 ->
Files.getLastModifiedTime(o1).compareTo(Files.getLastModifiedTime(o2))
}
.flatMap(Files::lines)
.forEach { line ->
Files.write(
outputFilePath,
(line + System.lineSeparator()).toByteArray(),
StandardOpenOption.CREATE,
StandardOpenOption.APPEND,
)
}
.flatMap(Files::lines).use { lines ->
lines.forEach { line ->
Files.write(
outputFilePath,
(line + System.lineSeparator()).toByteArray(),
StandardOpenOption.CREATE,
StandardOpenOption.APPEND,
)
}
}
}
}

override suspend fun getLogFile(): Result<File> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object NymVpnClient {
private val _state = MutableStateFlow(VpnClientState())
override val stateFlow: Flow<VpnClientState> = _state.asStateFlow()

override suspend fun validateCredential(credential: String): Result<Instant> {
override suspend fun validateCredential(credential: String): Result<Instant?> {
return withContext(ioDispatcher) {
try {
val expiry = checkCredential(credential)
Expand Down
2 changes: 1 addition & 1 deletion nym_vpn_client/src/main/java/net/nymtech/vpn/VpnClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface VpnClient {
var exitPoint: ExitPoint
var mode: VpnMode

suspend fun validateCredential(credential: String): Result<Instant>
suspend fun validateCredential(credential: String): Result<Instant?>

@Throws(InvalidCredentialException::class)
suspend fun start(context: Context, credential: String, foreground: Boolean = false): Result<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ private fun uniffiCheckContractApiVersion(lib: UniffiLib) {

@Suppress("UNUSED_PARAMETER")
private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_nym_vpn_lib_checksum_func_checkcredential() != 44396.toShort()) {
if (lib.uniffi_nym_vpn_lib_checksum_func_checkcredential() != 2527.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_nym_vpn_lib_checksum_func_getgatewaycountries() != 4475.toShort()) {
Expand Down Expand Up @@ -1576,6 +1576,35 @@ public object FfiConverterOptionalDouble: FfiConverterRustBuffer<kotlin.Double?>



public object FfiConverterOptionalTimestamp: FfiConverterRustBuffer<java.time.Instant?> {
override fun read(buf: ByteBuffer): java.time.Instant? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTimestamp.read(buf)
}

override fun allocationSize(value: java.time.Instant?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTimestamp.allocationSize(value)
}
}

override fun write(value: java.time.Instant?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTimestamp.write(value, buf)
}
}
}




public object FfiConverterOptionalTypePathBuf: FfiConverterRustBuffer<PathBuf?> {
override fun read(buf: ByteBuffer): PathBuf? {
if (buf.get().toInt() == 0) {
Expand Down Expand Up @@ -1725,8 +1754,8 @@ public object FfiConverterTypeUrl: FfiConverter<Url, RustBuffer.ByValue> {
FfiConverterString.write(builtinValue, buf)
}
}
@Throws(FfiException::class) fun `checkCredential`(`credential`: kotlin.String): java.time.Instant {
return FfiConverterTimestamp.lift(
@Throws(FfiException::class) fun `checkCredential`(`credential`: kotlin.String): java.time.Instant? {
return FfiConverterOptionalTimestamp.lift(
uniffiRustCallWithError(FfiException) { _status ->
UniffiLib.INSTANCE.uniffi_nym_vpn_lib_fn_func_checkcredential(
FfiConverterString.lower(`credential`),_status)
Expand Down
7 changes: 3 additions & 4 deletions nym_vpn_client/src/main/scripts/build-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export NDK_TOOLCHAIN_DIR="$1/toolchains/llvm/prebuilt/${archDir}/bin"
bash $PWD/src/tools/nym-vpn-client/wireguard/build-wireguard-go.sh
bash $PWD/src/tools/nym-vpn-client/wireguard/libwg/build-android.sh
echo "Building nym-vpn-lib dep"
export RUSTFLAGS="-L $PWD/src/tools/nym-vpn-client/build/lib/aarch64-linux-android"
#fix emulators later
#(cd $PWD/src/tools/nym-vpn-client/nym-vpn-lib; cargo ndk -t armeabi-v7a -t arm64-v8a -t i686-linux-android -t x86_64-linux-android -o ../../../main/jniLibs build --release)
(cd $PWD/src/tools/nym-vpn-client/nym-vpn-lib; cargo ndk -t arm64-v8a -o ../../../main/jniLibs build --release)
(cd $PWD/src/tools/nym-vpn-client/nym-vpn-core/nym-vpn-lib; cargo ndk -t arm64-v8a -o ../../../../main/jniLibs build --release)
#mv wireguard

case "$(uname -s)" in
Expand All @@ -22,9 +23,7 @@ case "$(uname -s)" in
MINGW*|MSYS_NT*) export RUSTFLAGS="-L ${PWD}/src/tools/nym-vpn-client/build/lib/x86_64-pc-windows-msvc";;
esac

(cd $PWD/src/tools/nym-vpn-client; cargo run --bin uniffi-bindgen generate --library ./target/aarch64-linux-android/release/libnym_vpn_lib.so --language kotlin --out-dir ../../main/java/net/nymtech/vpn -n)
#fix package name
sed -i 's/package nym-vpn-lib;/package nym_vpn_lib;/g' $PWD/src/main/java/net/nymtech/vpn/nym-vpn-lib/nym_vpn_lib.kt
(cd $PWD/src/tools/nym-vpn-client/nym-vpn-core; cargo run --bin uniffi-bindgen generate --library ./target/aarch64-linux-android/release/libnym_vpn_lib.so --language kotlin --out-dir ../../../main/java/net/nymtech/vpn -n)

mv $PWD/src/main/jniLibs/arm64-v8a/libnym_vpn_lib.so $PWD/src/main/jniLibs/arm64-v8a/libnym_vpn_lib.so
#mv $PWD/src/main/jniLibs/armeabi-v7a/libnym_vpn_lib.so $PWD/src/main/jniLibs/armeabi-v7a/libnym_vpn_lib.so
Expand Down