Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
briar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
675
Issues
675
List
Boards
Labels
Service Desk
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
briar
briar
Commits
9c08073e
Verified
Commit
9c08073e
authored
May 03, 2019
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename account to identity.
parent
5553b7d0
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
453 additions
and
447 deletions
+453
-447
bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java
...va/org/briarproject/bramble/api/db/DatabaseComponent.java
+34
-33
bramble-api/src/main/java/org/briarproject/bramble/api/identity/Identity.java
.../java/org/briarproject/bramble/api/identity/Identity.java
+10
-10
bramble-api/src/main/java/org/briarproject/bramble/api/identity/IdentityManager.java
...rg/briarproject/bramble/api/identity/IdentityManager.java
+7
-7
bramble-api/src/test/java/org/briarproject/bramble/test/TestUtils.java
...rc/test/java/org/briarproject/bramble/test/TestUtils.java
+4
-3
bramble-core/src/main/java/org/briarproject/bramble/account/AccountManagerImpl.java
.../org/briarproject/bramble/account/AccountManagerImpl.java
+3
-3
bramble-core/src/main/java/org/briarproject/bramble/db/Database.java
...e/src/main/java/org/briarproject/bramble/db/Database.java
+34
-33
bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java
...va/org/briarproject/bramble/db/DatabaseComponentImpl.java
+51
-51
bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java
...c/main/java/org/briarproject/bramble/db/JdbcDatabase.java
+133
-132
bramble-core/src/main/java/org/briarproject/bramble/identity/IdentityManagerImpl.java
...rg/briarproject/bramble/identity/IdentityManagerImpl.java
+39
-38
bramble-core/src/test/java/org/briarproject/bramble/account/AccountManagerImplTest.java
.../briarproject/bramble/account/AccountManagerImplTest.java
+7
-7
bramble-core/src/test/java/org/briarproject/bramble/db/DatabaseComponentImplTest.java
...rg/briarproject/bramble/db/DatabaseComponentImplTest.java
+24
-25
bramble-core/src/test/java/org/briarproject/bramble/db/DatabasePerformanceTest.java
.../org/briarproject/bramble/db/DatabasePerformanceTest.java
+14
-14
bramble-core/src/test/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
...st/java/org/briarproject/bramble/db/JdbcDatabaseTest.java
+49
-47
bramble-core/src/test/java/org/briarproject/bramble/identity/IdentityManagerImplTest.java
...riarproject/bramble/identity/IdentityManagerImplTest.java
+21
-21
briar-core/src/test/java/org/briarproject/briar/feed/FeedManagerIntegrationTest.java
...g/briarproject/briar/feed/FeedManagerIntegrationTest.java
+3
-3
briar-core/src/test/java/org/briarproject/briar/messaging/SimplexMessagingIntegrationTest.java
...ject/briar/messaging/SimplexMessagingIntegrationTest.java
+10
-10
briar-core/src/test/java/org/briarproject/briar/test/BriarIntegrationTest.java
...ava/org/briarproject/briar/test/BriarIntegrationTest.java
+10
-10
No files found.
bramble-api/src/main/java/org/briarproject/bramble/api/db/DatabaseComponent.java
View file @
9c08073e
...
...
@@ -5,9 +5,9 @@ import org.briarproject.bramble.api.contact.ContactId;
import
org.briarproject.bramble.api.contact.PendingContact
;
import
org.briarproject.bramble.api.contact.PendingContactId
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.identity.Account
;
import
org.briarproject.bramble.api.identity.Author
;
import
org.briarproject.bramble.api.identity.AuthorId
;
import
org.briarproject.bramble.api.identity.Identity
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
org.briarproject.bramble.api.settings.Settings
;
...
...
@@ -101,11 +101,6 @@ public interface DatabaseComponent {
<
R
,
E
extends
Exception
>
R
transactionWithNullableResult
(
boolean
readOnly
,
NullableDbCallable
<
R
,
E
>
task
)
throws
DbException
,
E
;
/**
* Stores an account.
*/
void
addAccount
(
Transaction
txn
,
Account
a
)
throws
DbException
;
/**
* Stores a contact associated with the given local and remote pseudonyms,
* and returns an ID for the contact.
...
...
@@ -132,6 +127,11 @@ public interface DatabaseComponent {
HandshakeKeySetId
addHandshakeKeys
(
Transaction
txn
,
PendingContactId
p
,
HandshakeKeys
k
)
throws
DbException
;
/**
* Stores an identity.
*/
void
addIdentity
(
Transaction
txn
,
Identity
i
)
throws
DbException
;
/**
* Stores a local message.
*/
...
...
@@ -157,13 +157,6 @@ public interface DatabaseComponent {
TransportKeySetId
addTransportKeys
(
Transaction
txn
,
ContactId
c
,
TransportKeys
k
)
throws
DbException
;
/**
* Returns true if the database contains an account for the given pseudonym.
* <p/>
* Read-only.
*/
boolean
containsAccount
(
Transaction
txn
,
AuthorId
local
)
throws
DbException
;
/**
* Returns true if the database contains the given contact for the given
* local pseudonym.
...
...
@@ -180,6 +173,14 @@ public interface DatabaseComponent {
*/
boolean
containsGroup
(
Transaction
txn
,
GroupId
g
)
throws
DbException
;
/**
* Returns true if the database contains an identity for the given
* pseudonym.
* <p/>
* Read-only.
*/
boolean
containsIdentity
(
Transaction
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Returns true if the database contains the given pending contact.
* <p/>
...
...
@@ -246,20 +247,6 @@ public interface DatabaseComponent {
Collection
<
Message
>
generateRequestedBatch
(
Transaction
txn
,
ContactId
c
,
int
maxLength
,
int
maxLatency
)
throws
DbException
;
/**
* Returns the account for the local pseudonym with the given ID.
* <p/>
* Read-only.
*/
Account
getAccount
(
Transaction
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Returns the accounts for all local pseudonyms.
* <p/>
* Read-only.
*/
Collection
<
Account
>
getAccounts
(
Transaction
txn
)
throws
DbException
;
/**
* Returns the contact with the given ID.
* <p/>
...
...
@@ -329,6 +316,20 @@ public interface DatabaseComponent {
Collection
<
HandshakeKeySet
>
getHandshakeKeys
(
Transaction
txn
,
TransportId
t
)
throws
DbException
;
/**
* Returns the identity for the local pseudonym with the given ID.
* <p/>
* Read-only.
*/
Identity
getIdentity
(
Transaction
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Returns the identities for all local pseudonyms.
* <p/>
* Read-only.
*/
Collection
<
Identity
>
getIdentities
(
Transaction
txn
)
throws
DbException
;
/**
* Returns the message with the given ID.
* <p/>
...
...
@@ -541,11 +542,6 @@ public interface DatabaseComponent {
void
receiveRequest
(
Transaction
txn
,
ContactId
c
,
Request
r
)
throws
DbException
;
/**
* Removes an account (and all associated state) from the database.
*/
void
removeAccount
(
Transaction
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Removes a contact (and all associated state) from the database.
*/
...
...
@@ -562,6 +558,11 @@ public interface DatabaseComponent {
void
removeHandshakeKeys
(
Transaction
txn
,
TransportId
t
,
HandshakeKeySetId
k
)
throws
DbException
;
/**
* Removes an identity (and all associated state) from the database.
*/
void
removeIdentity
(
Transaction
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Removes a message (and all associated state) from the database.
*/
...
...
@@ -619,7 +620,7 @@ public interface DatabaseComponent {
Collection
<
MessageId
>
dependencies
)
throws
DbException
;
/**
* Sets the handshake key pair for the
account
with the given ID.
* Sets the handshake key pair for the
identity
with the given ID.
*/
void
setHandshakeKeyPair
(
Transaction
txn
,
AuthorId
local
,
byte
[]
publicKey
,
byte
[]
privateKey
)
throws
DbException
;
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/identity/
Account
.java
→
bramble-api/src/main/java/org/briarproject/bramble/api/identity/
Identity
.java
View file @
9c08073e
...
...
@@ -11,14 +11,14 @@ import static org.briarproject.bramble.api.crypto.CryptoConstants.MAX_AGREEMENT_
@Immutable
@NotNullByDefault
public
class
Account
{
public
class
Identity
{
private
final
LocalAuthor
localAuthor
;
@Nullable
private
final
byte
[]
handshakePublicKey
,
handshakePrivateKey
;
private
final
long
created
;
public
Account
(
LocalAuthor
localAuthor
,
public
Identity
(
LocalAuthor
localAuthor
,
@Nullable
byte
[]
handshakePublicKey
,
@Nullable
byte
[]
handshakePrivateKey
,
long
created
)
{
if
(
handshakePublicKey
!=
null
)
{
...
...
@@ -47,7 +47,7 @@ public class Account {
}
/**
* Returns true if the
account
has a handshake key pair.
* Returns true if the
identity
has a handshake key pair.
*/
public
boolean
hasHandshakeKeyPair
()
{
return
handshakePublicKey
!=
null
&&
handshakePrivateKey
!=
null
;
...
...
@@ -70,7 +70,7 @@ public class Account {
}
/**
* Returns the time the
account
was created, in milliseconds since the
* Returns the time the
identity
was created, in milliseconds since the
* Unix epoch.
*/
public
long
getTimeCreated
()
{
...
...
@@ -84,12 +84,12 @@ public class Account {
@Override
public
boolean
equals
(
Object
o
)
{
if
(
o
instanceof
Account
)
{
Account
a
=
(
Account
)
o
;
return
created
==
a
.
created
&&
localAuthor
.
equals
(
a
.
localAuthor
)
&&
Arrays
.
equals
(
handshakePublicKey
,
a
.
handshakePublicKey
)
&&
Arrays
.
equals
(
handshakePrivateKey
,
a
.
handshakePrivateKey
);
if
(
o
instanceof
Identity
)
{
Identity
i
=
(
Identity
)
o
;
return
created
==
i
.
created
&&
localAuthor
.
equals
(
i
.
localAuthor
)
&&
Arrays
.
equals
(
handshakePublicKey
,
i
.
handshakePublicKey
)
&&
Arrays
.
equals
(
handshakePrivateKey
,
i
.
handshakePrivateKey
);
}
return
false
;
}
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/identity/IdentityManager.java
View file @
9c08073e
...
...
@@ -11,19 +11,19 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
public
interface
IdentityManager
{
/**
* Creates an
account with the given name. The account includes a handshake
* key pair.
* Creates an
identity with the given name. The identity includes a
*
handshake
key pair.
*/
@CryptoExecutor
Account
createAccount
(
String
name
);
Identity
createIdentity
(
String
name
);
/**
* Registers the given
account
with the manager. This method should be
* Registers the given
identity
with the manager. This method should be
* called before {@link LifecycleManager#startServices(SecretKey)}. The
*
account
is stored when {@link LifecycleManager#startServices(SecretKey)}
* is called. The
account
must include a handshake key pair.
*
identity
is stored when {@link LifecycleManager#startServices(SecretKey)}
* is called. The
identity
must include a handshake key pair.
*/
void
register
Account
(
Account
a
);
void
register
Identity
(
Identity
i
);
/**
* Returns the cached local identity or loads it from the database.
...
...
bramble-api/src/test/java/org/briarproject/bramble/test/TestUtils.java
View file @
9c08073e
...
...
@@ -6,9 +6,9 @@ import org.briarproject.bramble.api.contact.ContactId;
import
org.briarproject.bramble.api.contact.PendingContact
;
import
org.briarproject.bramble.api.contact.PendingContactId
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.identity.Account
;
import
org.briarproject.bramble.api.identity.Author
;
import
org.briarproject.bramble.api.identity.AuthorId
;
import
org.briarproject.bramble.api.identity.Identity
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
org.briarproject.bramble.api.properties.TransportProperties
;
...
...
@@ -101,11 +101,12 @@ public class TestUtils {
return
new
SecretKey
(
getRandomBytes
(
SecretKey
.
LENGTH
));
}
public
static
Account
getAccount
()
{
public
static
Identity
getIdentity
()
{
LocalAuthor
localAuthor
=
getLocalAuthor
();
byte
[]
handshakePub
=
getRandomBytes
(
MAX_AGREEMENT_PUBLIC_KEY_BYTES
);
byte
[]
handshakePriv
=
getRandomBytes
(
MAX_AGREEMENT_PUBLIC_KEY_BYTES
);
return
new
Account
(
localAuthor
,
handshakePub
,
handshakePriv
,
timestamp
);
return
new
Identity
(
localAuthor
,
handshakePub
,
handshakePriv
,
timestamp
);
}
public
static
LocalAuthor
getLocalAuthor
()
{
...
...
bramble-core/src/main/java/org/briarproject/bramble/account/AccountManagerImpl.java
View file @
9c08073e
...
...
@@ -4,7 +4,7 @@ import org.briarproject.bramble.api.account.AccountManager;
import
org.briarproject.bramble.api.crypto.CryptoComponent
;
import
org.briarproject.bramble.api.crypto.SecretKey
;
import
org.briarproject.bramble.api.db.DatabaseConfig
;
import
org.briarproject.bramble.api.identity.
Account
;
import
org.briarproject.bramble.api.identity.
Identity
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault
;
import
org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault
;
...
...
@@ -161,8 +161,8 @@ class AccountManagerImpl implements AccountManager {
synchronized
(
stateChangeLock
)
{
if
(
hasDatabaseKey
())
throw
new
AssertionError
(
"Already have a database key"
);
Account
account
=
identityManager
.
createAccount
(
name
);
identityManager
.
register
Account
(
account
);
Identity
identity
=
identityManager
.
createIdentity
(
name
);
identityManager
.
register
Identity
(
identity
);
SecretKey
key
=
crypto
.
generateSecretKey
();
if
(!
encryptAndStoreDatabaseKey
(
key
,
password
))
return
false
;
databaseKey
=
key
;
...
...
bramble-core/src/main/java/org/briarproject/bramble/db/Database.java
View file @
9c08073e
...
...
@@ -13,9 +13,9 @@ import org.briarproject.bramble.api.db.DbException;
import
org.briarproject.bramble.api.db.MessageDeletedException
;
import
org.briarproject.bramble.api.db.Metadata
;
import
org.briarproject.bramble.api.db.MigrationListener
;
import
org.briarproject.bramble.api.identity.Account
;
import
org.briarproject.bramble.api.identity.Author
;
import
org.briarproject.bramble.api.identity.AuthorId
;
import
org.briarproject.bramble.api.identity.Identity
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.bramble.api.plugin.TransportId
;
import
org.briarproject.bramble.api.settings.Settings
;
...
...
@@ -86,11 +86,6 @@ interface Database<T> {
*/
void
commitTransaction
(
T
txn
)
throws
DbException
;
/**
* Stores an account.
*/
void
addAccount
(
T
txn
,
Account
a
)
throws
DbException
;
/**
* Stores a contact associated with the given local and remote pseudonyms,
* and returns an ID for the contact.
...
...
@@ -124,6 +119,11 @@ interface Database<T> {
HandshakeKeySetId
addHandshakeKeys
(
T
txn
,
PendingContactId
p
,
HandshakeKeys
k
)
throws
DbException
;
/**
* Stores an identity.
*/
void
addIdentity
(
T
txn
,
Identity
i
)
throws
DbException
;
/**
* Stores a message.
*
...
...
@@ -163,13 +163,6 @@ interface Database<T> {
TransportKeySetId
addTransportKeys
(
T
txn
,
ContactId
c
,
TransportKeys
k
)
throws
DbException
;
/**
* Returns true if the database contains an account for the given pseudonym.
* <p/>
* Read-only.
*/
boolean
containsAccount
(
T
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Returns true if the database contains the given contact for the given
* local pseudonym.
...
...
@@ -193,6 +186,14 @@ interface Database<T> {
*/
boolean
containsGroup
(
T
txn
,
GroupId
g
)
throws
DbException
;
/**
* Returns true if the database contains an identity for the given
* pseudonym.
* <p/>
* Read-only.
*/
boolean
containsIdentity
(
T
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Returns true if the database contains the given message.
* <p/>
...
...
@@ -245,20 +246,6 @@ interface Database<T> {
*/
void
deleteMessageMetadata
(
T
txn
,
MessageId
m
)
throws
DbException
;
/**
* Returns the account for local pseudonym with the given ID.
* <p/>
* Read-only.
*/
Account
getAccount
(
T
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Returns the accounts for all local pseudonyms.
* <p/>
* Read-only.
*/
Collection
<
Account
>
getAccounts
(
T
txn
)
throws
DbException
;
/**
* Returns the contact with the given ID.
* <p/>
...
...
@@ -336,6 +323,20 @@ interface Database<T> {
Collection
<
HandshakeKeySet
>
getHandshakeKeys
(
T
txn
,
TransportId
t
)
throws
DbException
;
/**
* Returns the identity for local pseudonym with the given ID.
* <p/>
* Read-only.
*/
Identity
getIdentity
(
T
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Returns the identities for all local pseudonyms.
* <p/>
* Read-only.
*/
Collection
<
Identity
>
getIdentities
(
T
txn
)
throws
DbException
;
/**
* Returns the message with the given ID.
* <p/>
...
...
@@ -605,11 +606,6 @@ interface Database<T> {
*/
void
raiseSeenFlag
(
T
txn
,
ContactId
c
,
MessageId
m
)
throws
DbException
;
/**
* Removes an account (and all associated state) from the database.
*/
void
removeAccount
(
T
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Removes a contact from the database.
*/
...
...
@@ -633,6 +629,11 @@ interface Database<T> {
void
removeHandshakeKeys
(
T
txn
,
TransportId
t
,
HandshakeKeySetId
k
)
throws
DbException
;
/**
* Removes an identity (and all associated state) from the database.
*/
void
removeIdentity
(
T
txn
,
AuthorId
a
)
throws
DbException
;
/**
* Removes a message (and all associated state) from the database.
*/
...
...
@@ -686,7 +687,7 @@ interface Database<T> {
throws
DbException
;
/**
* Sets the handshake key pair for the
account
with the given ID.
* Sets the handshake key pair for the
identity
with the given ID.
*/
void
setHandshakeKeyPair
(
T
txn
,
AuthorId
local
,
byte
[]
publicKey
,
byte
[]
privateKey
)
throws
DbException
;
...
...
bramble-core/src/main/java/org/briarproject/bramble/db/DatabaseComponentImpl.java
View file @
9c08073e
...
...
@@ -30,9 +30,9 @@ import org.briarproject.bramble.api.db.TaskAction;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.briarproject.bramble.api.event.EventBus
;
import
org.briarproject.bramble.api.event.EventExecutor
;
import
org.briarproject.bramble.api.identity.Account
;
import
org.briarproject.bramble.api.identity.Author
;
import
org.briarproject.bramble.api.identity.AuthorId
;
import
org.briarproject.bramble.api.identity.Identity
;
import
org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent
;
import
org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent
;
import
org.briarproject.bramble.api.lifecycle.ShutdownManager
;
...
...
@@ -231,26 +231,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
return
txnClass
.
cast
(
transaction
.
unbox
());
}
@Override
public
void
addAccount
(
Transaction
transaction
,
Account
a
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(!
db
.
containsAccount
(
txn
,
a
.
getId
()))
{
db
.
addAccount
(
txn
,
a
);
transaction
.
attach
(
new
LocalAuthorAddedEvent
(
a
.
getId
()));
}
}
@Override
public
ContactId
addContact
(
Transaction
transaction
,
Author
remote
,
AuthorId
local
,
boolean
verified
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(!
db
.
contains
Account
(
txn
,
local
))
if
(!
db
.
contains
Identity
(
txn
,
local
))
throw
new
NoSuchLocalAuthorException
();
if
(
db
.
contains
Account
(
txn
,
remote
.
getId
()))
if
(
db
.
contains
Identity
(
txn
,
remote
.
getId
()))
throw
new
ContactExistsException
();
if
(
db
.
containsContact
(
txn
,
remote
.
getId
(),
local
))
throw
new
ContactExistsException
();
...
...
@@ -293,6 +282,17 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
return
db
.
addHandshakeKeys
(
txn
,
p
,
k
);
}
@Override
public
void
addIdentity
(
Transaction
transaction
,
Identity
i
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(!
db
.
containsIdentity
(
txn
,
i
.
getId
()))
{
db
.
addIdentity
(
txn
,
i
);
transaction
.
attach
(
new
LocalAuthorAddedEvent
(
i
.
getId
()));
}
}
@Override
public
void
addLocalMessage
(
Transaction
transaction
,
Message
m
,
Metadata
meta
,
boolean
shared
)
throws
DbException
{
...
...
@@ -341,18 +341,11 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
return
db
.
addTransportKeys
(
txn
,
c
,
k
);
}
@Override
public
boolean
containsAccount
(
Transaction
transaction
,
AuthorId
local
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
return
db
.
containsAccount
(
txn
,
local
);
}
@Override
public
boolean
containsContact
(
Transaction
transaction
,
AuthorId
remote
,
AuthorId
local
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
if
(!
db
.
contains
Account
(
txn
,
local
))
if
(!
db
.
contains
Identity
(
txn
,
local
))
throw
new
NoSuchLocalAuthorException
();
return
db
.
containsContact
(
txn
,
remote
,
local
);
}
...
...
@@ -364,6 +357,13 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
return
db
.
containsGroup
(
txn
,
g
);
}
@Override
public
boolean
containsIdentity
(
Transaction
transaction
,
AuthorId
a
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
return
db
.
containsIdentity
(
txn
,
a
);
}
@Override
public
boolean
containsPendingContact
(
Transaction
transaction
,
PendingContactId
p
)
throws
DbException
{
...
...
@@ -478,22 +478,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
return
messages
;
}
@Override
public
Account
getAccount
(
Transaction
transaction
,
AuthorId
a
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
if
(!
db
.
containsAccount
(
txn
,
a
))
throw
new
NoSuchLocalAuthorException
();
return
db
.
getAccount
(
txn
,
a
);
}
@Override
public
Collection
<
Account
>
getAccounts
(
Transaction
transaction
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
return
db
.
getAccounts
(
txn
);
}
@Override
public
Contact
getContact
(
Transaction
transaction
,
ContactId
c
)
throws
DbException
{
...
...
@@ -521,7 +505,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
public
Collection
<
ContactId
>
getContacts
(
Transaction
transaction
,
AuthorId
a
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
if
(!
db
.
contains
Account
(
txn
,
a
))
if
(!
db
.
contains
Identity
(
txn
,
a
))
throw
new
NoSuchLocalAuthorException
();
return
db
.
getContacts
(
txn
,
a
);
}
...
...
@@ -569,6 +553,22 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
return
db
.
getHandshakeKeys
(
txn
,
t
);
}
@Override
public
Identity
getIdentity
(
Transaction
transaction
,
AuthorId
a
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
if
(!
db
.
containsIdentity
(
txn
,
a
))
throw
new
NoSuchLocalAuthorException
();
return
db
.
getIdentity
(
txn
,
a
);
}
@Override
public
Collection
<
Identity
>
getIdentities
(
Transaction
transaction
)
throws
DbException
{
T
txn
=
unbox
(
transaction
);
return
db
.
getIdentities
(
txn
);
}
@Override
public
Message
getMessage
(
Transaction
transaction
,
MessageId
m
)
throws
DbException
{
...
...
@@ -868,17 +868,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
if
(
requested
)
transaction
.
attach
(
new
MessageRequestedEvent
(
c
));
}
@Override
public
void
removeAccount
(
Transaction
transaction
,
AuthorId
a
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(!
db
.
containsAccount
(
txn
,
a
))
throw
new
NoSuchLocalAuthorException
();
db
.
removeAccount
(
txn
,
a
);
transaction
.
attach
(
new
LocalAuthorRemovedEvent
(
a
));
}
@Override
public
void
removeContact
(
Transaction
transaction
,
ContactId
c
)
throws
DbException
{
...
...
@@ -915,6 +904,17 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
db
.
removeHandshakeKeys
(
txn
,
t
,
k
);
}
@Override
public
void
removeIdentity
(
Transaction
transaction
,
AuthorId
a
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(!
db
.
containsIdentity
(
txn
,
a
))
throw
new
NoSuchLocalAuthorException
();
db
.
removeIdentity
(
txn
,
a
);
transaction
.
attach
(
new
LocalAuthorRemovedEvent
(
a
));
}
@Override
public
void
removeMessage
(
Transaction
transaction
,
MessageId
m
)
throws
DbException
{
...
...
@@ -1040,7 +1040,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
byte
[]
publicKey
,
byte
[]
privateKey
)
throws
DbException
{
if
(
transaction
.
isReadOnly
())
throw
new
IllegalArgumentException
();
T
txn
=
unbox
(
transaction
);
if
(!
db
.
contains
Account
(
txn
,
local
))
if
(!
db
.
contains
Identity
(
txn
,
local
))
throw
new
NoSuchLocalAuthorException
();
db
.
setHandshakeKeyPair
(
txn
,
local
,
publicKey
,
privateKey
);
}
...
...
bramble-core/src/main/java/org/briarproject/bramble/db/JdbcDatabase.java
View file @
9c08073e
This diff is collapsed.
Click to expand it.
bramble-core/src/main/java/org/briarproject/bramble/identity/IdentityManagerImpl.java
View file @
9c08073e
...
...
@@ -5,8 +5,8 @@ import org.briarproject.bramble.api.crypto.KeyPair;
import
org.briarproject.bramble.api.db.DatabaseComponent
;
import
org.briarproject.bramble.api.db.DbException
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.briarproject.bramble.api.identity.Account
;
import
org.briarproject.bramble.api.identity.AuthorFactory
;
import
org.briarproject.bramble.api.identity.Identity
;
import
org.briarproject.bramble.api.identity.IdentityManager
;
import
org.briarproject.bramble.api.identity.LocalAuthor
;
import
org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook
;
...
...
@@ -38,23 +38,23 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
private
final
Clock
clock
;
/**
* The user's
account, or null if no account has been registered or loaded.
*
If non-null, this account
always has handshake keys.
* The user's
identity, or null if no identity has been registered or
*
loaded. If non-null, this identity
always has handshake keys.
*/
@Nullable
private
volatile
Account
cachedAccount
=
null
;
private
volatile
Identity
cachedIdentity
=
null
;