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
708e4f87
Commit
708e4f87
authored
12 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Fixed some bugs and cleaned up code in TransportConnectionRecogniser.
parent
79c3ef57
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
components/net/sf/briar/transport/TransportConnectionRecogniser.java
+55
-40
55 additions, 40 deletions
...net/sf/briar/transport/TransportConnectionRecogniser.java
with
55 additions
and
40 deletions
components/net/sf/briar/transport/TransportConnectionRecogniser.java
+
55
−
40
View file @
708e4f87
...
...
@@ -26,7 +26,7 @@ class TransportConnectionRecogniser {
private
final
DatabaseComponent
db
;
private
final
TransportId
transportId
;
private
final
Map
<
Bytes
,
WindowContext
>
tagMap
;
// Locking: this
private
final
Map
<
RemovalKey
,
RemovalContext
>
window
Map
;
// Locking: this
private
final
Map
<
RemovalKey
,
RemovalContext
>
removal
Map
;
// Locking: this
TransportConnectionRecogniser
(
CryptoComponent
crypto
,
DatabaseComponent
db
,
TransportId
transportId
)
{
...
...
@@ -34,72 +34,87 @@ class TransportConnectionRecogniser {
this
.
db
=
db
;
this
.
transportId
=
transportId
;
tagMap
=
new
HashMap
<
Bytes
,
WindowContext
>();
window
Map
=
new
HashMap
<
RemovalKey
,
RemovalContext
>();
removal
Map
=
new
HashMap
<
RemovalKey
,
RemovalContext
>();
}
synchronized
ConnectionContext
acceptConnection
(
byte
[]
tag
)
throws
DbException
{
WindowContext
wctx
=
tagMap
.
remove
(
new
Bytes
(
tag
));
if
(
wctx
==
null
)
return
null
;
ConnectionWindow
w
=
wctx
.
window
;
if
(
wctx
==
null
)
return
null
;
// The tag was not expected
ConnectionWindow
w
indow
=
wctx
.
window
;
ConnectionContext
ctx
=
wctx
.
context
;
long
period
=
wctx
.
period
;
ContactId
contactId
=
ctx
.
getContactId
();
byte
[]
secret
=
ctx
.
getSecret
();
long
connection
=
ctx
.
getConnectionNumber
();
boolean
alice
=
ctx
.
getAlice
();
// Update the connection window and the expected tags
Cipher
cipher
=
crypto
.
getTagCipher
();
ErasableKey
key
=
crypto
.
deriveTagKey
(
ctx
.
getSecret
(),
ctx
.
getAlice
());
byte
[]
changedTag
=
new
byte
[
TAG_LENGTH
];
Bytes
changedTagWrapper
=
new
Bytes
(
changedTag
);
for
(
long
conn
:
w
.
setSeen
(
connection
))
{
TagEncoder
.
encodeTag
(
changedTag
,
cipher
,
key
,
conn
);
WindowContext
old
;
if
(
conn
<=
connection
)
old
=
tagMap
.
remove
(
changedTagWrapper
);
else
old
=
tagMap
.
put
(
changedTagWrapper
,
wctx
);
assert
old
==
null
;
ErasableKey
key
=
crypto
.
deriveTagKey
(
secret
,
alice
);
for
(
long
connection1
:
window
.
setSeen
(
connection
))
{
byte
[]
tag1
=
new
byte
[
TAG_LENGTH
];
TagEncoder
.
encodeTag
(
tag1
,
cipher
,
key
,
connection1
);
if
(
connection1
<=
connection
)
{
WindowContext
old
=
tagMap
.
remove
(
new
Bytes
(
tag1
));
assert
old
==
null
;
}
else
{
ConnectionContext
ctx1
=
new
ConnectionContext
(
contactId
,
transportId
,
tag1
,
secret
,
connection1
,
alice
);
WindowContext
wctx1
=
new
WindowContext
(
window
,
ctx1
,
period
);
WindowContext
old
=
tagMap
.
put
(
new
Bytes
(
tag1
),
wctx1
);
assert
old
==
null
;
}
}
key
.
erase
();
ContactId
c
=
ctx
.
getContactId
();
long
centre
=
w
.
getCentre
();
byte
[]
bitmap
=
w
.
getBitmap
();
db
.
setConnectionWindow
(
c
,
transportId
,
wctx
.
period
,
centre
,
bitmap
);
return
w
ctx
.
context
;
// Store the updated connection window in the DB
long
centre
=
windo
w
.
getCentre
();
byte
[]
bitmap
=
windo
w
.
getBitmap
();
db
.
setConnectionWindow
(
c
ontactId
,
transportId
,
period
,
centre
,
bitmap
);
return
ctx
;
}
synchronized
void
addWindow
(
ContactId
c
,
long
period
,
boolean
alice
,
synchronized
void
addWindow
(
ContactId
c
ontactId
,
long
period
,
boolean
alice
,
byte
[]
secret
,
long
centre
,
byte
[]
bitmap
)
throws
DbException
{
// Create the connection window and the expected tags
Cipher
cipher
=
crypto
.
getTagCipher
();
ErasableKey
key
=
crypto
.
deriveTagKey
(
secret
,
alice
);
ConnectionWindow
w
=
new
ConnectionWindow
(
centre
,
bitmap
);
for
(
long
conn
:
w
.
getUnseen
())
{
ConnectionWindow
w
indow
=
new
ConnectionWindow
(
centre
,
bitmap
);
for
(
long
conn
ection
:
windo
w
.
getUnseen
())
{
byte
[]
tag
=
new
byte
[
TAG_LENGTH
];
TagEncoder
.
encodeTag
(
tag
,
cipher
,
key
,
conn
);
ConnectionContext
ctx
=
new
ConnectionContext
(
c
,
transportId
,
tag
,
secret
,
conn
,
alice
);
WindowContext
wctx
=
new
WindowContext
(
w
,
ctx
,
period
);
tagMap
.
put
(
new
Bytes
(
tag
),
wctx
);
TagEncoder
.
encodeTag
(
tag
,
cipher
,
key
,
connection
);
ConnectionContext
ctx
=
new
ConnectionContext
(
contactId
,
transportId
,
tag
,
secret
,
connection
,
alice
);
WindowContext
wctx
=
new
WindowContext
(
window
,
ctx
,
period
);
WindowContext
old
=
tagMap
.
put
(
new
Bytes
(
tag
),
wctx
);
assert
old
==
null
;
}
db
.
setConnectionWindow
(
c
,
transportId
,
period
,
centre
,
bitmap
);
RemovalContext
ctx
=
new
RemovalContext
(
w
,
secret
,
alice
);
windowMap
.
put
(
new
RemovalKey
(
c
,
period
),
ctx
);
// Store the new connection window in the DB
db
.
setConnectionWindow
(
contactId
,
transportId
,
period
,
centre
,
bitmap
);
// Create a removal context to remove the window when the key expires
RemovalContext
rctx
=
new
RemovalContext
(
window
,
secret
,
alice
);
removalMap
.
put
(
new
RemovalKey
(
contactId
,
period
),
rctx
);
}
synchronized
void
removeWindow
(
ContactId
c
,
long
period
)
{
RemovalContext
ctx
=
windowMap
.
remove
(
new
RemovalKey
(
c
,
period
));
if
(
ctx
==
null
)
throw
new
IllegalArgumentException
();
synchronized
void
removeWindow
(
ContactId
contactId
,
long
period
)
{
RemovalKey
rk
=
new
RemovalKey
(
contactId
,
period
);
RemovalContext
rctx
=
removalMap
.
remove
(
rk
);
if
(
rctx
==
null
)
throw
new
IllegalArgumentException
();
// Remove the expected tags
Cipher
cipher
=
crypto
.
getTagCipher
();
ErasableKey
key
=
crypto
.
deriveTagKey
(
ctx
.
secret
,
ctx
.
alice
);
byte
[]
removedTag
=
new
byte
[
TAG_LENGTH
];
Bytes
removedTagWrapper
=
new
Bytes
(
removedTag
);
for
(
long
conn
:
ctx
.
window
.
getUnseen
())
{
TagEncoder
.
encodeTag
(
removedTag
,
cipher
,
key
,
conn
);
WindowContext
old
=
tagMap
.
remove
(
removedTagWrapper
);
ErasableKey
key
=
crypto
.
deriveTagKey
(
rctx
.
secret
,
rctx
.
alice
);
byte
[]
tag
=
new
byte
[
TAG_LENGTH
];
for
(
long
connection
:
rctx
.
window
.
getUnseen
())
{
TagEncoder
.
encodeTag
(
tag
,
cipher
,
key
,
connection
);
WindowContext
old
=
tagMap
.
remove
(
new
Bytes
(
tag
));
assert
old
!=
null
;
}
key
.
erase
();
ByteUtils
.
erase
(
ctx
.
secret
);
ByteUtils
.
erase
(
r
ctx
.
secret
);
}
synchronized
void
removeWindows
(
ContactId
c
)
{
Collection
<
RemovalKey
>
keysToRemove
=
new
ArrayList
<
RemovalKey
>();
for
(
RemovalKey
k
:
window
Map
.
keySet
())
{
for
(
RemovalKey
k
:
removal
Map
.
keySet
())
{
if
(
k
.
contactId
.
equals
(
c
))
keysToRemove
.
add
(
k
);
}
for
(
RemovalKey
k
:
keysToRemove
)
removeWindow
(
k
.
contactId
,
k
.
period
);
...
...
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