Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Login verifies mnemonic with the bridge. (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloyan-raev authored Jan 30, 2018
1 parent e87a192 commit 911b303
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.goobox</groupId>
<artifactId>goobox-sync-storj</artifactId>
<version>0.0.16</version>
<version>0.0.17</version>
<packaging>jar</packaging>

<name>Goobox sync app for Storj</name>
Expand Down Expand Up @@ -62,7 +62,7 @@
<dependency>
<groupId>io.storj</groupId>
<artifactId>libstorj-java</artifactId>
<version>0.5.1</version>
<version>0.6</version>
</dependency>
<dependency>
<groupId>net.harawata</groupId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/goobox/sync/storj/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ public void onBucketsReceived(Bucket[] buckets) {
logger.info("Goobox bucket does not exist");
storj.createBucket("Goobox", new CreateBucketCallback() {
@Override
public void onError(String message) {
logger.error("Failed creating cloud Goobox bucket: {}", message);
public void onError(int code, String message) {
logger.error("Failed creating cloud Goobox bucket: {} ({})", message, code);
latch.countDown();
}

Expand All @@ -255,8 +255,8 @@ public void onBucketCreated(Bucket bucket) {
}

@Override
public void onError(String message) {
logger.error(message);
public void onError(int code, String message) {
logger.error("{} ({})", message, code);
latch.countDown();
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/goobox/sync/storj/CheckStateTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public void onFilesReceived(File[] files) {
}

@Override
public void onError(String message) {
logger.error(message);
public void onError(int code, String message) {
logger.error("{} ({})", message, code);
// Try again
tasks.add(CheckStateTask.this);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/goobox/sync/storj/CreateCloudDirTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public void onComplete(final String filePath, final File file) {
}

@Override
public void onError(String filePath, String message) {
public void onError(String filePath, int code, String message) {
try {
deleteTempDirFile(tmp);

DB.setUploadFailed(path);
DB.commit();

logger.error(message);
logger.error("{} ({})", message, code);
} catch (IOException e) {
logger.error("I/O error", e);
}
Expand Down Expand Up @@ -118,9 +118,9 @@ public void onFilesReceived(File[] files) {
}

@Override
public void onError(String message) {
logger.error("Error checking if directory with name {} exists: {}. Trying again.", dirName,
message);
public void onError(int code, String message) {
logger.error("Error checking if directory with name {} exists: {} ({}). Trying again.",
dirName, message, code);
latch.countDown();
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/goobox/sync/storj/DeleteCloudFileTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void onFileDeleted() {
}

@Override
public void onError(String message) {
logger.error("Failed deleting on cloud: {}", message);
public void onError(int code, String message) {
logger.error("Failed deleting on cloud: {} ({})", message, code);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/goobox/sync/storj/DownloadFileTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public void onComplete(String fileId, String localPath) {
}

@Override
public void onError(String fileId, String message) {
public void onError(String fileId, int code, String message) {
Path localPath = App.getInstance().getSyncDir().resolve(file.getName());
try {
DB.setDownloadFailed(file, localPath);
DB.commit();
logger.error("Download failed: {}", message);
logger.error("Download failed: {} ({})", message, code);
} catch (IOException e) {
logger.error("I/O error", e);
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/io/goobox/sync/storj/UploadFileTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public void onComplete(final String filePath, final File file) {
}

@Override
public void onError(String filePath, String message) {
public void onError(String filePath, int code, String message) {
try {
DB.setUploadFailed(path);
DB.commit();
logger.error("Upload failed: {}", message);
logger.error("Upload failed: {} ({})", message, code);
} catch (IOException e) {
logger.error("I/O error", e);
}
Expand Down Expand Up @@ -118,17 +118,18 @@ public void onFileDeleted() {
}

@Override
public void onError(String message) {
logger.error("Failed deleting old version: {}. Trying again.", message);
public void onError(int code, String message) {
logger.error("Failed deleting old version: {} ({}). Trying again.", message, code);
latch.countDown();
}
});
}
}

@Override
public void onError(String message) {
logger.error("Error checking if file with name {} exists: {}. Trying again.", fileName, message);
public void onError(int code, String message) {
logger.error("Error checking if file with name {} exists: {} ({}). Trying again.",
fileName, message, code);
latch.countDown();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public void onConfirmationPending(String email) {
}

@Override
public void onError(String message) {
error[0] = message.substring(message.indexOf("Error: ") + 7);
public void onError(int code, String message) {
error[0] = message;
latch.countDown();
}
});
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/io/goobox/sync/storj/ipc/LoginRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,32 @@ public CommandResult execute() {
Storj storj = App.getInstance().getStorj();
Keys keys = new Keys(email, password, encryptionKey);

boolean result = storj.verifyKeys(email, password);
if (!result) {
String msg = "Email and password do not match";
logger.error(msg);
try {
int result = storj.verifyKeys(new Keys(email, password, encryptionKey));
if (result != Storj.NO_ERROR) {
String msg;

switch (result) {
case Storj.HTTP_UNAUTHORIZED:
msg = "Email and password do not match";
break;
case Storj.STORJ_META_DECRYPTION_ERROR:
msg = "Encryption key cannot decrypt content";
break;
default:
msg = Storj.getErrorMessage(result);
}

logger.error(msg);
return new CommandResult(Status.ERROR, msg);
}
} catch (InterruptedException e) {
String msg = "Login interrupted";
logger.error(msg, e);
return new CommandResult(Status.ERROR, msg);
}

result = storj.importKeys(keys, "");
if (!result) {
if (!storj.importKeys(keys, "")) {
String msg = "Failed to write authentication file";
logger.error(msg);
return new CommandResult(Status.ERROR, msg);
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/io/goobox/sync/storj/helpers/StorjUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public void onFileDeleted() {
}

@Override
public void onError(String message) {
throw new IllegalStateException(message);
public void onError(int code, String message) {
String msg = String.format("%s (%d)", message, code);
throw new IllegalStateException(msg);
}

}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/goobox/sync/storj/mocks/StorjMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void deleteFile(Bucket bucket, File file, DeleteFileCallback callback) th
return;
}
}
callback.onError("file not found");
callback.onError(Storj.HTTP_NOT_FOUND, "file not found");
}

@Mock
Expand All @@ -104,7 +104,7 @@ public void downloadFile(Bucket bucket, File file, DownloadFileCallback callback
filesMock.addFile(FileMock.SUB_SUB_FILE);
callback.onComplete(file.getId(), FileMock.SUB_SUB_FILE.getPath().toString());
} else {
callback.onError(file.getId(), "error downloading");
callback.onError(file.getId(), Storj.STORJ_BRIDGE_FILE_NOTFOUND_ERROR, "error downloading");
}
}

Expand All @@ -113,7 +113,7 @@ public void uploadFile(Bucket bucket, String fileName, String localPath, UploadF
throws KeysNotFoundException {
if (FileMock.FILE_1.getPath().toString().equals(localPath)) {
if (files.contains(FILE_1)) {
callback.onError(localPath, "File already exists");
callback.onError(localPath, Storj.STORJ_BRIDGE_BUCKET_FILE_EXISTS, "File already exists");
} else {
files.add(FILE_1);
callback.onComplete(localPath, FILE_1);
Expand All @@ -131,7 +131,7 @@ public void uploadFile(Bucket bucket, String fileName, String localPath, UploadF
files.add(SUB_SUB_FILE);
callback.onComplete(localPath, SUB_SUB_FILE);
} else {
callback.onError(localPath, "error uploading");
callback.onError(localPath, Storj.ENOENT, "error uploading");
}
}

Expand Down

0 comments on commit 911b303

Please sign in to comment.