Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
briar
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
579
Issues
579
List
Boards
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
briar
briar
Commits
fb1d8e86
Verified
Commit
fb1d8e86
authored
Nov 30, 2018
by
Torsten Grote
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[api] Add interface for adding contacts remotely
parent
a3c526ec
Pipeline
#2878
passed with stage
in 11 minutes and 59 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
184 additions
and
0 deletions
+184
-0
ContactManager.java
.../org/briarproject/bramble/api/contact/ContactManager.java
+31
-0
PendingContact.java
.../org/briarproject/bramble/api/contact/PendingContact.java
+54
-0
PendingContactId.java
...rg/briarproject/bramble/api/contact/PendingContactId.java
+11
-0
PendingContactStateChangedEvent.java
...le/api/contact/event/PendingContactStateChangedEvent.java
+34
-0
ContactManagerImpl.java
.../org/briarproject/bramble/contact/ContactManagerImpl.java
+54
-0
No files found.
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
View file @
fb1d8e86
...
...
@@ -13,6 +13,8 @@ import java.util.Collection;
import
javax.annotation.Nullable
;
import
static
org
.
briarproject
.
bramble
.
api
.
contact
.
PendingContact
.
PendingContactState
.
FAILED
;
@NotNullByDefault
public
interface
ContactManager
{
...
...
@@ -52,6 +54,35 @@ public interface ContactManager {
long
timestamp
,
boolean
alice
,
boolean
verified
,
boolean
active
)
throws
DbException
;
/**
* Returns the static link that needs to be sent to the contact to be added.
*/
String
getRemoteContactLink
();
/**
* Returns true if the given link is syntactically valid.
*/
boolean
isValidRemoteContactLink
(
String
link
);
/**
* Requests a new contact to be added via the given {@code link}.
*
* @param link The link received from the contact we want to add.
* @param alias The alias the user has given this contact.
* @return A PendingContact representing the contact to be added.
*/
PendingContact
addRemoteContactRequest
(
String
link
,
String
alias
);
/**
* Returns a list of {@link PendingContact}s.
*/
Collection
<
PendingContact
>
getPendingContacts
();
/**
* Removes a {@link PendingContact} that is in state {@link FAILED}.
*/
void
removePendingContact
(
PendingContact
pendingContact
);
/**
* Returns the contact with the given ID.
*/
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/contact/PendingContact.java
0 → 100644
View file @
fb1d8e86
package
org
.
briarproject
.
bramble
.
api
.
contact
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
javax.annotation.concurrent.Immutable
;
@Immutable
@NotNullByDefault
public
class
PendingContact
{
public
enum
PendingContactState
{
WAITING_FOR_CONNECTION
,
CONNECTED
,
ADDING_CONTACT
,
FAILED
}
private
final
PendingContactId
id
;
private
final
String
alias
;
private
final
PendingContactState
state
;
private
final
long
timestamp
;
public
PendingContact
(
PendingContactId
id
,
String
alias
,
PendingContactState
state
,
long
timestamp
)
{
this
.
id
=
id
;
this
.
alias
=
alias
;
this
.
state
=
state
;
this
.
timestamp
=
timestamp
;
}
public
String
getAlias
()
{
return
alias
;
}
public
PendingContactState
getState
()
{
return
state
;
}
public
long
getTimestamp
()
{
return
timestamp
;
}
@Override
public
int
hashCode
()
{
return
id
.
hashCode
();
}
@Override
public
boolean
equals
(
Object
o
)
{
return
o
instanceof
PendingContact
&&
id
.
equals
(((
PendingContact
)
o
).
id
);
}
}
bramble-api/src/main/java/org/briarproject/bramble/api/contact/PendingContactId.java
0 → 100644
View file @
fb1d8e86
package
org
.
briarproject
.
bramble
.
api
.
contact
;
import
org.briarproject.bramble.api.UniqueId
;
public
class
PendingContactId
extends
UniqueId
{
public
PendingContactId
(
byte
[]
id
)
{
super
(
id
);
}
}
bramble-api/src/main/java/org/briarproject/bramble/api/contact/event/PendingContactStateChangedEvent.java
0 → 100644
View file @
fb1d8e86
package
org
.
briarproject
.
bramble
.
api
.
contact
.
event
;
import
org.briarproject.bramble.api.contact.PendingContact.PendingContactState
;
import
org.briarproject.bramble.api.contact.PendingContactId
;
import
org.briarproject.bramble.api.event.Event
;
import
org.briarproject.bramble.api.nullsafety.NotNullByDefault
;
import
javax.annotation.concurrent.Immutable
;
/**
* An event that is broadcast when a pending contact's state is changed.
*/
@Immutable
@NotNullByDefault
public
class
PendingContactStateChangedEvent
extends
Event
{
private
final
PendingContactId
id
;
private
final
PendingContactState
state
;
public
PendingContactStateChangedEvent
(
PendingContactId
id
,
PendingContactState
state
)
{
this
.
id
=
id
;
this
.
state
=
state
;
}
public
PendingContactId
getId
()
{
return
id
;
}
public
PendingContactState
getPendingContactState
()
{
return
state
;
}
}
bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java
View file @
fb1d8e86
...
...
@@ -3,6 +3,8 @@ package org.briarproject.bramble.contact;
import
org.briarproject.bramble.api.contact.Contact
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.contact.ContactManager
;
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.db.DatabaseComponent
;
import
org.briarproject.bramble.api.db.DbException
;
...
...
@@ -19,12 +21,16 @@ import org.briarproject.bramble.api.transport.KeyManager;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.regex.Pattern
;
import
javax.annotation.Nullable
;
import
javax.annotation.concurrent.ThreadSafe
;
import
javax.inject.Inject
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
org
.
briarproject
.
bramble
.
api
.
contact
.
PendingContact
.
PendingContactState
.
WAITING_FOR_CONNECTION
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorConstants
.
MAX_AUTHOR_NAME_LENGTH
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorInfo
.
Status
.
OURSELVES
;
import
static
org
.
briarproject
.
bramble
.
api
.
identity
.
AuthorInfo
.
Status
.
UNKNOWN
;
...
...
@@ -36,6 +42,12 @@ import static org.briarproject.bramble.util.StringUtils.toUtf8;
@NotNullByDefault
class
ContactManagerImpl
implements
ContactManager
{
private
static
final
int
LINK_LENGTH
=
64
;
private
static
final
String
REMOTE_CONTACT_LINK
=
"briar://"
+
getRandomBase32String
(
LINK_LENGTH
);
private
static
final
Pattern
LINK_REGEX
=
Pattern
.
compile
(
"(briar://)?([a-z2-7]{"
+
LINK_LENGTH
+
"})"
);
private
final
DatabaseComponent
db
;
private
final
KeyManager
keyManager
;
private
final
IdentityManager
identityManager
;
...
...
@@ -84,6 +96,48 @@ class ContactManagerImpl implements ContactManager {
verified
,
active
));
}
@Override
public
String
getRemoteContactLink
()
{
// TODO replace with real implementation
return
REMOTE_CONTACT_LINK
;
}
@SuppressWarnings
(
"SameParameterValue"
)
private
static
String
getRandomBase32String
(
int
length
)
{
Random
random
=
new
Random
();
char
[]
c
=
new
char
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
int
character
=
random
.
nextInt
(
32
);
if
(
character
<
26
)
c
[
i
]
=
(
char
)
(
'a'
+
character
);
else
c
[
i
]
=
(
char
)
(
'2'
+
(
character
-
26
));
}
return
new
String
(
c
);
}
@Override
public
boolean
isValidRemoteContactLink
(
String
link
)
{
return
LINK_REGEX
.
matcher
(
link
).
matches
();
}
@Override
public
PendingContact
addRemoteContactRequest
(
String
link
,
String
alias
)
{
// TODO replace with real implementation
PendingContactId
id
=
new
PendingContactId
(
link
.
getBytes
());
return
new
PendingContact
(
id
,
alias
,
WAITING_FOR_CONNECTION
,
System
.
currentTimeMillis
());
}
@Override
public
Collection
<
PendingContact
>
getPendingContacts
()
{
// TODO replace with real implementation
return
emptyList
();
}
@Override
public
void
removePendingContact
(
PendingContact
pendingContact
)
{
// TODO replace with real implementation
}
@Override
public
Contact
getContact
(
ContactId
c
)
throws
DbException
{
return
db
.
transactionWithResult
(
true
,
txn
->
db
.
getContact
(
txn
,
c
));
...
...
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