Updated libraries, most notably Jabit to develop-SNAPSHOT
Also, finally added proper icon Known issue: the client seems to sever all connections after some time, I'll need to look into this. This might happen when 8 connections are reached for the first time.
@ -1,25 +1,25 @@
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
ext {
|
||||
appName = "Abit"
|
||||
}
|
||||
if (project.hasProperty("project.configs")
|
||||
&& new File(project.property("project.configs") + appName + ".gradle").exists()) {
|
||||
apply from: project.property("project.configs") + appName + ".gradle";
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.3"
|
||||
compileSdkVersion 24
|
||||
buildToolsVersion "24.0.1"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "ch.dissem.apps.abit"
|
||||
applicationId "ch.dissem.apps." + appName.toLowerCase()
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 23
|
||||
targetSdkVersion 24
|
||||
versionCode 7
|
||||
versionName "1.0-beta7"
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
storeFile file(keyStoreFile)
|
||||
storePassword keyStorePassword
|
||||
keyAlias signingKeyAlias
|
||||
keyPassword signingKeyPassword
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
@ -29,12 +29,12 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
ext.jabitVersion = '1.1.0-SNAPSHOT'
|
||||
ext.jabitVersion = 'develop-SNAPSHOT'
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:23.3.0'
|
||||
compile 'com.android.support:support-v4:23.3.0'
|
||||
compile 'com.android.support:design:23.3.0'
|
||||
compile 'com.android.support:appcompat-v7:24.1.1'
|
||||
compile 'com.android.support:support-v4:24.1.1'
|
||||
compile 'com.android.support:design:24.1.1'
|
||||
|
||||
compile "ch.dissem.jabit:jabit-core:$jabitVersion"
|
||||
compile "ch.dissem.jabit:jabit-networking:$jabitVersion"
|
||||
|
@ -0,0 +1,2 @@
|
||||
ALTER TABLE POW ADD COLUMN expiration_time BIGINT;
|
||||
ALTER TABLE POW ADD COLUMN message_id BIGINT;
|
@ -0,0 +1,4 @@
|
||||
ALTER TABLE Message ADD COLUMN ack_data BINARY(32);
|
||||
ALTER TABLE Message ADD COLUMN ttl BIGINT NOT NULL DEFAULT 0;
|
||||
ALTER TABLE Message ADD COLUMN retries INT NOT NULL DEFAULT 0;
|
||||
ALTER TABLE Message ADD COLUMN next_try BIGINT;
|
BIN
app/src/main/ic_launcher-web.png
Normal file
After Width: | Height: | Size: 25 KiB |
@ -36,7 +36,7 @@ import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest;
|
||||
import ch.dissem.bitmessage.ports.ProofOfWorkEngine;
|
||||
|
||||
import static ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest.Request.CALCULATE;
|
||||
import static ch.dissem.bitmessage.utils.Singleton.security;
|
||||
import static ch.dissem.bitmessage.utils.Singleton.cryptography;
|
||||
|
||||
/**
|
||||
* @author Christian Basler
|
||||
@ -78,7 +78,7 @@ public class ServerPowEngine implements ProofOfWorkEngine, InternalContext
|
||||
(request);
|
||||
cryptoMsg.signAndEncrypt(
|
||||
identity,
|
||||
security().createPublicKey(identity.getPublicDecryptionKey())
|
||||
cryptography().createPublicKey(identity.getPublicDecryptionKey())
|
||||
);
|
||||
context.getNetworkHandler().send(
|
||||
Preferences.getTrustedNode(ctx), Preferences.getTrustedNodePort(ctx),
|
||||
|
@ -22,17 +22,6 @@ import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteConstraintException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.v4.database.DatabaseUtilsCompat;
|
||||
|
||||
import ch.dissem.apps.abit.R;
|
||||
import ch.dissem.bitmessage.InternalContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||
import ch.dissem.bitmessage.ports.MessageRepository;
|
||||
import ch.dissem.bitmessage.utils.Encode;
|
||||
import ch.dissem.bitmessage.utils.Strings;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -43,12 +32,19 @@ import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static ch.dissem.apps.abit.repository.SqlHelper.join;
|
||||
import ch.dissem.apps.abit.R;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||
import ch.dissem.bitmessage.ports.AbstractMessageRepository;
|
||||
import ch.dissem.bitmessage.ports.MessageRepository;
|
||||
import ch.dissem.bitmessage.utils.Encode;
|
||||
|
||||
/**
|
||||
* {@link MessageRepository} implementation using the Android SQL API.
|
||||
*/
|
||||
public class AndroidMessageRepository implements MessageRepository, InternalContext.ContextHolder {
|
||||
public class AndroidMessageRepository extends AbstractMessageRepository {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AndroidMessageRepository.class);
|
||||
|
||||
private static final String TABLE_NAME = "Message";
|
||||
@ -58,9 +54,13 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont
|
||||
private static final String COLUMN_SENDER = "sender";
|
||||
private static final String COLUMN_RECIPIENT = "recipient";
|
||||
private static final String COLUMN_DATA = "data";
|
||||
private static final String COLUMN_ACK_DATA = "ack_data";
|
||||
private static final String COLUMN_SENT = "sent";
|
||||
private static final String COLUMN_RECEIVED = "received";
|
||||
private static final String COLUMN_STATUS = "status";
|
||||
private static final String COLUMN_TTL = "ttl";
|
||||
private static final String COLUMN_RETRIES = "retries";
|
||||
private static final String COLUMN_NEXT_TRY = "next_try";
|
||||
private static final String COLUMN_INITIAL_HASH = "initial_hash";
|
||||
|
||||
private static final String JOIN_TABLE_NAME = "Message_Label";
|
||||
@ -74,27 +74,11 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont
|
||||
private static final String LBL_COLUMN_COLOR = "color";
|
||||
private static final String LBL_COLUMN_ORDER = "ord";
|
||||
private final SqlHelper sql;
|
||||
private final Context ctx;
|
||||
private InternalContext bmc;
|
||||
private final Context context;
|
||||
|
||||
public AndroidMessageRepository(SqlHelper sql, Context ctx) {
|
||||
this.sql = sql;
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContext(InternalContext context) {
|
||||
bmc = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Label> getLabels() {
|
||||
return findLabels(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Label> getLabels(Label.Type... types) {
|
||||
return findLabels("type IN (" + join(types) + ")");
|
||||
this.context = ctx;
|
||||
}
|
||||
|
||||
public List<Label> findLabels(String where) {
|
||||
@ -134,22 +118,22 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont
|
||||
} else {
|
||||
switch (type) {
|
||||
case INBOX:
|
||||
text = ctx.getString(R.string.inbox);
|
||||
text = context.getString(R.string.inbox);
|
||||
break;
|
||||
case DRAFT:
|
||||
text = ctx.getString(R.string.draft);
|
||||
text = context.getString(R.string.draft);
|
||||
break;
|
||||
case SENT:
|
||||
text = ctx.getString(R.string.sent);
|
||||
text = context.getString(R.string.sent);
|
||||
break;
|
||||
case UNREAD:
|
||||
text = ctx.getString(R.string.unread);
|
||||
text = context.getString(R.string.unread);
|
||||
break;
|
||||
case TRASH:
|
||||
text = ctx.getString(R.string.trash);
|
||||
text = context.getString(R.string.trash);
|
||||
break;
|
||||
case BROADCAST:
|
||||
text = ctx.getString(R.string.broadcasts);
|
||||
text = context.getString(R.string.broadcasts);
|
||||
break;
|
||||
default:
|
||||
text = c.getString(c.getColumnIndex(LBL_COLUMN_LABEL));
|
||||
@ -179,47 +163,7 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plaintext getMessage(byte[] initialHash) {
|
||||
List<Plaintext> results = find("initial_hash=X'" + Strings.hex(initialHash) + "'");
|
||||
switch (results.size()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return results.get(0);
|
||||
default:
|
||||
throw new RuntimeException("This shouldn't happen, found " + results.size() +
|
||||
" messages, one or none was expected");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Plaintext> findMessages(Label label) {
|
||||
if (label != null) {
|
||||
return find("id IN (SELECT message_id FROM Message_Label WHERE label_id=" + label
|
||||
.getId() + ")");
|
||||
} else {
|
||||
return find("id NOT IN (SELECT message_id FROM Message_Label)");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Plaintext> findMessages(Plaintext.Status status, BitmessageAddress recipient) {
|
||||
return find("status='" + status.name() + "' AND recipient='" + recipient.getAddress() +
|
||||
"'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Plaintext> findMessages(BitmessageAddress sender) {
|
||||
return find("sender=" + sender.getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Plaintext> findMessages(Plaintext.Status status) {
|
||||
return find("status='" + status.name() + "'");
|
||||
}
|
||||
|
||||
private List<Plaintext> find(String where) {
|
||||
protected List<Plaintext> find(String where) {
|
||||
List<Plaintext> result = new LinkedList<>();
|
||||
|
||||
// Define a projection that specifies which columns from the database
|
||||
@ -231,9 +175,13 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont
|
||||
COLUMN_SENDER,
|
||||
COLUMN_RECIPIENT,
|
||||
COLUMN_DATA,
|
||||
COLUMN_ACK_DATA,
|
||||
COLUMN_SENT,
|
||||
COLUMN_RECEIVED,
|
||||
COLUMN_STATUS
|
||||
COLUMN_STATUS,
|
||||
COLUMN_TTL,
|
||||
COLUMN_RETRIES,
|
||||
COLUMN_NEXT_TRY
|
||||
};
|
||||
|
||||
SQLiteDatabase db = sql.getReadableDatabase();
|
||||
@ -254,14 +202,21 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont
|
||||
long id = c.getLong(c.getColumnIndex(COLUMN_ID));
|
||||
builder.id(id);
|
||||
builder.IV(new InventoryVector(iv));
|
||||
builder.from(bmc.getAddressRepository().getAddress(c.getString(c.getColumnIndex
|
||||
builder.from(ctx.getAddressRepository().getAddress(c.getString(c.getColumnIndex
|
||||
(COLUMN_SENDER))));
|
||||
builder.to(bmc.getAddressRepository().getAddress(c.getString(c.getColumnIndex
|
||||
builder.to(ctx.getAddressRepository().getAddress(c.getString(c.getColumnIndex
|
||||
(COLUMN_RECIPIENT))));
|
||||
builder.ackData(c.getBlob(c.getColumnIndex(COLUMN_ACK_DATA)));
|
||||
builder.sent(c.getLong(c.getColumnIndex(COLUMN_SENT)));
|
||||
builder.received(c.getLong(c.getColumnIndex(COLUMN_RECEIVED)));
|
||||
builder.status(Plaintext.Status.valueOf(c.getString(c.getColumnIndex
|
||||
(COLUMN_STATUS))));
|
||||
builder.ttl(c.getLong(c.getColumnIndex(COLUMN_TTL)));
|
||||
builder.retries(c.getInt(c.getColumnIndex(COLUMN_RETRIES)));
|
||||
int nextTryColumn = c.getColumnIndex(COLUMN_NEXT_TRY);
|
||||
if (!c.isNull(nextTryColumn)) {
|
||||
builder.nextTry(c.getLong(nextTryColumn));
|
||||
}
|
||||
builder.labels(findLabels(id));
|
||||
result.add(builder.build());
|
||||
c.moveToNext();
|
||||
@ -284,13 +239,13 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont
|
||||
|
||||
// save from address if necessary
|
||||
if (message.getId() == null) {
|
||||
BitmessageAddress savedAddress = bmc.getAddressRepository().getAddress(message
|
||||
BitmessageAddress savedAddress = ctx.getAddressRepository().getAddress(message
|
||||
.getFrom().getAddress());
|
||||
if (savedAddress == null || savedAddress.getPrivateKey() == null) {
|
||||
if (savedAddress != null && savedAddress.getAlias() != null) {
|
||||
message.getFrom().setAlias(savedAddress.getAlias());
|
||||
}
|
||||
bmc.getAddressRepository().save(message.getFrom());
|
||||
ctx.getAddressRepository().save(message.getFrom());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ import ch.dissem.bitmessage.ports.ProofOfWorkRepository;
|
||||
import ch.dissem.bitmessage.utils.Encode;
|
||||
import ch.dissem.bitmessage.utils.Strings;
|
||||
|
||||
import static ch.dissem.bitmessage.utils.Singleton.security;
|
||||
import static ch.dissem.bitmessage.utils.Singleton.cryptography;
|
||||
|
||||
/**
|
||||
* @author Christian Basler
|
||||
@ -49,6 +49,8 @@ public class AndroidProofOfWorkRepository implements ProofOfWorkRepository {
|
||||
private static final String COLUMN_VERSION = "version";
|
||||
private static final String COLUMN_NONCE_TRIALS_PER_BYTE = "nonce_trials_per_byte";
|
||||
private static final String COLUMN_EXTRA_BYTES = "extra_bytes";
|
||||
private static final String COLUMN_EXPIRATION_TIME = "expiration_time";
|
||||
private static final String COLUMN_MESSAGE_ID = "message_id";
|
||||
|
||||
private final SqlHelper sql;
|
||||
|
||||
@ -114,16 +116,20 @@ public class AndroidProofOfWorkRepository implements ProofOfWorkRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putObject(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) {
|
||||
public void putObject(Item item) {
|
||||
try {
|
||||
SQLiteDatabase db = sql.getWritableDatabase();
|
||||
// Create a new map of values, where column names are the keys
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_INITIAL_HASH, security().getInitialHash(object));
|
||||
values.put(COLUMN_DATA, Encode.bytes(object));
|
||||
values.put(COLUMN_VERSION, object.getVersion());
|
||||
values.put(COLUMN_NONCE_TRIALS_PER_BYTE, nonceTrialsPerByte);
|
||||
values.put(COLUMN_EXTRA_BYTES, extraBytes);
|
||||
values.put(COLUMN_INITIAL_HASH, cryptography().getInitialHash(item.object));
|
||||
values.put(COLUMN_DATA, Encode.bytes(item.object));
|
||||
values.put(COLUMN_VERSION, item.object.getVersion());
|
||||
values.put(COLUMN_NONCE_TRIALS_PER_BYTE, item.nonceTrialsPerByte);
|
||||
values.put(COLUMN_EXTRA_BYTES, item.extraBytes);
|
||||
if (item.message != null) {
|
||||
values.put(COLUMN_EXPIRATION_TIME, item.expirationTime);
|
||||
values.put(COLUMN_MESSAGE_ID, (Long) item.message.getId());
|
||||
}
|
||||
|
||||
db.insertOrThrow(TABLE_NAME, null, values);
|
||||
} catch (SQLiteConstraintException e) {
|
||||
@ -133,6 +139,11 @@ public class AndroidProofOfWorkRepository implements ProofOfWorkRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putObject(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) {
|
||||
putObject(new Item(object, nonceTrialsPerByte, extraBytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeObject(byte[] initialHash) {
|
||||
SQLiteDatabase db = sql.getWritableDatabase();
|
||||
|
@ -26,7 +26,7 @@ import ch.dissem.apps.abit.util.Assets;
|
||||
*/
|
||||
public class SqlHelper extends SQLiteOpenHelper {
|
||||
// If you change the database schema, you must increment the database version.
|
||||
public static final int DATABASE_VERSION = 3;
|
||||
public static final int DATABASE_VERSION = 4;
|
||||
public static final String DATABASE_NAME = "jabit.db";
|
||||
|
||||
protected final Context ctx;
|
||||
@ -53,6 +53,9 @@ public class SqlHelper extends SQLiteOpenHelper {
|
||||
executeMigration(db, "V2.1__Create_table_POW");
|
||||
case 2:
|
||||
executeMigration(db, "V3.0__Update_table_address");
|
||||
case 3:
|
||||
executeMigration(db, "V3.1__Update_table_POW");
|
||||
executeMigration(db, "V3.2__Update_table_message");
|
||||
default:
|
||||
// Nothing to do. Let's assume we won't upgrade from a version that's newer than DATABASE_VERSION.
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ import static ch.dissem.apps.abit.synchronization.Authenticator.ACCOUNT_SYNC;
|
||||
import static ch.dissem.apps.abit.synchronization.StubProvider.AUTHORITY;
|
||||
import static ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest.Request.CALCULATE;
|
||||
import static ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest.Request.COMPLETE;
|
||||
import static ch.dissem.bitmessage.utils.Singleton.security;
|
||||
import static ch.dissem.bitmessage.utils.Singleton.cryptography;
|
||||
|
||||
/**
|
||||
* Sync Adapter to synchronize with the Bitmessage network - fetches
|
||||
@ -107,13 +107,13 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
try {
|
||||
BitmessageAddress identity = Singleton.getIdentity(getContext());
|
||||
byte[] privateKey = identity.getPrivateKey().getPrivateEncryptionKey();
|
||||
byte[] signingKey = security().createPublicKey(identity.getPublicDecryptionKey());
|
||||
byte[] signingKey = cryptography().createPublicKey(identity.getPublicDecryptionKey());
|
||||
ProofOfWorkRequest.Reader reader = new ProofOfWorkRequest.Reader(identity);
|
||||
ProofOfWorkRepository powRepo = Singleton.getProofOfWorkRepository(getContext());
|
||||
List<byte[]> items = powRepo.getItems();
|
||||
for (byte[] initialHash : items) {
|
||||
ProofOfWorkRepository.Item item = powRepo.getItem(initialHash);
|
||||
byte[] target = security().getProofOfWorkTarget(item.object, item
|
||||
byte[] target = cryptography().getProofOfWorkTarget(item.object, item
|
||||
.nonceTrialsPerByte, item.extraBytes);
|
||||
CryptoCustomMessage<ProofOfWorkRequest> cryptoMsg = new CryptoCustomMessage<>(
|
||||
new ProofOfWorkRequest(identity, initialHash, CALCULATE, target));
|
||||
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 5.1 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 7.3 KiB |