Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
briar
briar
Commits
20b52804
Commit
20b52804
authored
Dec 16, 2021
by
akwizgran
Browse files
Merge branch 'add-pending-contact-transactional' into 'master'
Transactional versions of some more API calls See merge request
!1561
parents
c3400714
5b27eb35
Pipeline
#8739
failed with stages
in 39 minutes and 27 seconds
Changes
6
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
View file @
20b52804
...
...
@@ -113,6 +113,26 @@ public interface ContactManager {
*/
String
getHandshakeLink
(
Transaction
txn
)
throws
DbException
;
/**
* Creates a {@link PendingContact} from the given handshake link and
* alias, adds it to the database and returns it.
*
* @param link The handshake link received from the pending contact
* @param alias The alias the user has given this pending contact
* @throws UnsupportedVersionException If the link uses a format version
* that is not supported
* @throws FormatException If the link is invalid
* @throws GeneralSecurityException If the pending contact's handshake
* public key is invalid
* @throws ContactExistsException If a contact with the same handshake
* public key already exists
* @throws PendingContactExistsException If a pending contact with the same
* handshake public key already exists
*/
PendingContact
addPendingContact
(
Transaction
txn
,
String
link
,
String
alias
)
throws
DbException
,
FormatException
,
GeneralSecurityException
,
ContactExistsException
,
PendingContactExistsException
;
/**
* Creates a {@link PendingContact} from the given handshake link and
* alias, adds it to the database and returns it.
...
...
@@ -146,6 +166,13 @@ public interface ContactManager {
Collection
<
Pair
<
PendingContact
,
PendingContactState
>>
getPendingContacts
()
throws
DbException
;
/**
* Returns a list of {@link PendingContact PendingContacts} and their
* {@link PendingContactState states}.
*/
Collection
<
Pair
<
PendingContact
,
PendingContactState
>>
getPendingContacts
(
Transaction
txn
)
throws
DbException
;
/**
* Removes a {@link PendingContact}.
*/
...
...
bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java
View file @
20b52804
...
...
@@ -131,22 +131,29 @@ class ContactManagerImpl implements ContactManager, EventListener {
}
@Override
public
PendingContact
addPendingContact
(
String
link
,
String
alias
)
public
PendingContact
addPendingContact
(
Transaction
txn
,
String
link
,
String
alias
)
throws
DbException
,
FormatException
,
GeneralSecurityException
{
PendingContact
p
=
pendingContactFactory
.
createPendingContact
(
link
,
alias
);
AuthorId
local
=
identityManager
.
getLocalAuthor
(
txn
).
getId
();
db
.
addPendingContact
(
txn
,
p
,
local
);
KeyPair
ourKeyPair
=
identityManager
.
getHandshakeKeys
(
txn
);
keyManager
.
addPendingContact
(
txn
,
p
.
getId
(),
p
.
getPublicKey
(),
ourKeyPair
);
return
p
;
}
@Override
public
PendingContact
addPendingContact
(
String
link
,
String
alias
)
throws
DbException
,
FormatException
,
GeneralSecurityException
{
Transaction
txn
=
db
.
startTransaction
(
false
);
try
{
AuthorId
local
=
identityManager
.
getLocalAuthor
(
txn
).
getId
();
db
.
addPendingContact
(
txn
,
p
,
local
);
KeyPair
ourKeyPair
=
identityManager
.
getHandshakeKeys
(
txn
);
keyManager
.
addPendingContact
(
txn
,
p
.
getId
(),
p
.
getPublicKey
(),
ourKeyPair
);
PendingContact
p
=
addPendingContact
(
txn
,
link
,
alias
);
db
.
commitTransaction
(
txn
);
return
p
;
}
finally
{
db
.
endTransaction
(
txn
);
}
return
p
;
}
@Override
...
...
@@ -158,8 +165,13 @@ class ContactManagerImpl implements ContactManager, EventListener {
@Override
public
Collection
<
Pair
<
PendingContact
,
PendingContactState
>>
getPendingContacts
()
throws
DbException
{
Collection
<
PendingContact
>
pendingContacts
=
db
.
transactionWithResult
(
true
,
db:
:
getPendingContacts
);
return
db
.
transactionWithResult
(
true
,
this
::
getPendingContacts
);
}
@Override
public
Collection
<
Pair
<
PendingContact
,
PendingContactState
>>
getPendingContacts
(
Transaction
txn
)
throws
DbException
{
Collection
<
PendingContact
>
pendingContacts
=
db
.
getPendingContacts
(
txn
);
List
<
Pair
<
PendingContact
,
PendingContactState
>>
pairs
=
new
ArrayList
<>(
pendingContacts
.
size
());
for
(
PendingContact
p
:
pendingContacts
)
{
...
...
briar-api/src/main/java/org/briarproject/briar/api/introduction/IntroductionManager.java
View file @
20b52804
...
...
@@ -3,6 +3,7 @@ package org.briarproject.briar.api.introduction;
import
org.briarproject.bramble.api.contact.Contact
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.db.DbException
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
org.briarproject.bramble.api.sync.ClientId
;
import
org.briarproject.briar.api.client.SessionId
;
...
...
@@ -45,4 +46,10 @@ public interface IntroductionManager extends ConversationClient {
void
respondToIntroduction
(
ContactId
contactId
,
SessionId
sessionId
,
boolean
accept
)
throws
DbException
;
/**
* Responds to an introduction.
*/
void
respondToIntroduction
(
Transaction
txn
,
ContactId
contactId
,
SessionId
sessionId
,
boolean
accept
)
throws
DbException
;
}
briar-api/src/main/java/org/briarproject/briar/api/messaging/MessagingManager.java
View file @
20b52804
...
...
@@ -67,6 +67,11 @@ public interface MessagingManager extends ConversationClient {
*/
GroupId
getConversationId
(
ContactId
c
)
throws
DbException
;
/**
* Returns the ID of the private conversation with the given contact.
*/
GroupId
getConversationId
(
Transaction
txn
,
ContactId
c
)
throws
DbException
;
/**
* Returns the text of the private message with the given ID, or null if
* the private message has no text.
...
...
briar-core/src/main/java/org/briarproject/briar/introduction/IntroductionManagerImpl.java
View file @
20b52804
...
...
@@ -377,6 +377,12 @@ class IntroductionManagerImpl extends ConversationClientImpl
respondToIntroduction
(
contactId
,
sessionId
,
accept
,
false
);
}
@Override
public
void
respondToIntroduction
(
Transaction
txn
,
ContactId
contactId
,
SessionId
sessionId
,
boolean
accept
)
throws
DbException
{
respondToIntroduction
(
txn
,
contactId
,
sessionId
,
accept
,
false
);
}
private
void
respondToIntroduction
(
ContactId
contactId
,
SessionId
sessionId
,
boolean
accept
,
boolean
isAutoDecline
)
throws
DbException
{
db
.
transaction
(
false
,
...
...
briar-core/src/main/java/org/briarproject/briar/messaging/MessagingManagerImpl.java
View file @
20b52804
...
...
@@ -389,14 +389,13 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
@Override
public
GroupId
getConversationId
(
ContactId
c
)
throws
DbException
{
Contact
contact
;
Transaction
txn
=
db
.
startTransaction
(
true
);
try
{
contact
=
db
.
getContact
(
txn
,
c
);
db
.
commitTransaction
(
txn
);
}
finally
{
db
.
endTransaction
(
txn
);
}
return
db
.
transactionWithResult
(
true
,
txn
->
getConversationId
(
txn
,
c
));
}
@Override
public
GroupId
getConversationId
(
Transaction
txn
,
ContactId
c
)
throws
DbException
{
Contact
contact
=
db
.
getContact
(
txn
,
c
);
return
getContactGroup
(
contact
).
getId
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment