Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
c5d9d9fa
Commit
c5d9d9fa
authored
13 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Minor concurrency cleanups.
parent
3a07d1b8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java
+17
-17
17 additions, 17 deletions
...nents/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java
components/net/sf/briar/plugins/socket/SocketPlugin.java
+3
-6
3 additions, 6 deletions
components/net/sf/briar/plugins/socket/SocketPlugin.java
with
20 additions
and
23 deletions
components/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java
+
17
−
17
View file @
c5d9d9fa
...
...
@@ -89,17 +89,13 @@ class BluetoothPlugin extends AbstractPlugin implements StreamTransportPlugin {
private
void
bind
()
{
String
uuid
;
LocalDevice
ld
;
synchronized
(
this
)
{
if
(!
started
)
return
;
TransportConfig
c
=
callback
.
getConfig
();
uuid
=
c
.
get
(
"uuid"
);
if
(
uuid
==
null
)
uuid
=
createAndSetUuid
(
c
);
ld
=
localDevice
;
uuid
=
getUuid
();
}
// Try to make the device discoverable (requires root on Linux)
try
{
l
d
.
setDiscoverable
(
DiscoveryAgent
.
GIAC
);
l
ocalDevice
.
setDiscoverable
(
DiscoveryAgent
.
GIAC
);
}
catch
(
BluetoothStateException
e
)
{
if
(
LOG
.
isLoggable
(
Level
.
WARNING
))
LOG
.
warning
(
e
.
getMessage
());
}
...
...
@@ -123,22 +119,27 @@ class BluetoothPlugin extends AbstractPlugin implements StreamTransportPlugin {
return
;
}
streamConnectionNotifier
=
scn
;
s
tartListener
(
);
s
etLocalBluetoothAddress
(
localDevice
.
getBluetoothAddress
()
);
}
s
etLocalBluetoothAddress
(
ld
.
getBluetoothAddress
()
);
s
tartListener
(
);
}
private
synchronized
String
createAndSetUuid
(
TransportConfig
c
)
{
byte
[]
b
=
new
byte
[
16
];
new
Random
().
nextBytes
(
b
);
// FIXME: Use a SecureRandom?
String
uuid
=
StringUtils
.
toHexString
(
b
);
c
.
put
(
"uuid"
,
uuid
);
callback
.
setConfig
(
c
);
private
synchronized
String
getUuid
()
{
assert
started
;
TransportConfig
c
=
callback
.
getConfig
();
String
uuid
=
c
.
get
(
"uuid"
);
if
(
uuid
==
null
)
{
// Generate a (weakly) random UUID and store it
byte
[]
b
=
new
byte
[
16
];
new
Random
().
nextBytes
(
b
);
uuid
=
StringUtils
.
toHexString
(
b
);
c
.
put
(
"uuid"
,
uuid
);
callback
.
setConfig
(
c
);
}
return
uuid
;
}
private
void
startListener
()
{
assert
started
;
new
Thread
()
{
@Override
public
void
run
()
{
...
...
@@ -168,7 +169,7 @@ class BluetoothPlugin extends AbstractPlugin implements StreamTransportPlugin {
}
private
synchronized
void
setLocalBluetoothAddress
(
String
address
)
{
if
(!
started
)
return
;
assert
started
;
TransportProperties
p
=
callback
.
getLocalProperties
();
p
.
put
(
"address"
,
address
);
callback
.
setLocalProperties
(
p
);
...
...
@@ -211,7 +212,6 @@ class BluetoothPlugin extends AbstractPlugin implements StreamTransportPlugin {
Map
<
ContactId
,
String
>
uuids
;
synchronized
(
this
)
{
if
(!
started
)
return
Collections
.
emptyMap
();
if
(
localDevice
==
null
)
return
Collections
.
emptyMap
();
discoveryAgent
=
localDevice
.
getDiscoveryAgent
();
addresses
=
new
HashMap
<
String
,
ContactId
>();
uuids
=
new
HashMap
<
ContactId
,
String
>();
...
...
This diff is collapsed.
Click to expand it.
components/net/sf/briar/plugins/socket/SocketPlugin.java
+
3
−
6
View file @
c5d9d9fa
...
...
@@ -85,8 +85,8 @@ implements StreamTransportPlugin {
}
socket
=
ss
;
setLocalSocketAddress
(
ss
.
getLocalSocketAddress
());
startListener
();
}
startListener
();
}
private
void
startListener
()
{
...
...
@@ -103,7 +103,7 @@ implements StreamTransportPlugin {
ServerSocket
ss
;
Socket
s
;
synchronized
(
this
)
{
if
(!
started
||
socket
==
null
)
return
;
if
(!
started
)
return
;
ss
=
socket
;
}
try
{
...
...
@@ -120,10 +120,7 @@ implements StreamTransportPlugin {
@Override
public
synchronized
void
stop
()
throws
IOException
{
super
.
stop
();
if
(
socket
!=
null
)
{
socket
.
close
();
socket
=
null
;
}
if
(
socket
!=
null
)
socket
.
close
();
}
public
synchronized
void
poll
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment