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
ab7cc130
Unverified
Commit
ab7cc130
authored
9 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Added QueueMessage support to BdfMessageValidator.
parent
a4d6de03
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-core/src/org/briarproject/clients/BdfMessageValidator.java
+20
-3
20 additions, 3 deletions
...ore/src/org/briarproject/clients/BdfMessageValidator.java
with
20 additions
and
3 deletions
briar-core/src/org/briarproject/clients/BdfMessageValidator.java
+
20
−
3
View file @
ab7cc130
...
@@ -2,6 +2,8 @@ package org.briarproject.clients;
...
@@ -2,6 +2,8 @@ package org.briarproject.clients;
import
org.briarproject.api.FormatException
;
import
org.briarproject.api.FormatException
;
import
org.briarproject.api.clients.ClientHelper
;
import
org.briarproject.api.clients.ClientHelper
;
import
org.briarproject.api.clients.QueueMessage
;
import
org.briarproject.api.clients.QueueMessageValidator
;
import
org.briarproject.api.data.BdfDictionary
;
import
org.briarproject.api.data.BdfDictionary
;
import
org.briarproject.api.data.BdfList
;
import
org.briarproject.api.data.BdfList
;
import
org.briarproject.api.data.MetadataEncoder
;
import
org.briarproject.api.data.MetadataEncoder
;
...
@@ -14,10 +16,12 @@ import org.briarproject.util.StringUtils;
...
@@ -14,10 +16,12 @@ import org.briarproject.util.StringUtils;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
static
org
.
briarproject
.
api
.
clients
.
QueueMessage
.
QUEUE_MESSAGE_HEADER_LENGTH
;
import
static
org
.
briarproject
.
api
.
sync
.
SyncConstants
.
MESSAGE_HEADER_LENGTH
;
import
static
org
.
briarproject
.
api
.
sync
.
SyncConstants
.
MESSAGE_HEADER_LENGTH
;
import
static
org
.
briarproject
.
api
.
transport
.
TransportConstants
.
MAX_CLOCK_DIFFERENCE
;
import
static
org
.
briarproject
.
api
.
transport
.
TransportConstants
.
MAX_CLOCK_DIFFERENCE
;
public
abstract
class
BdfMessageValidator
implements
MessageValidator
{
public
abstract
class
BdfMessageValidator
implements
MessageValidator
,
QueueMessageValidator
{
protected
static
final
Logger
LOG
=
protected
static
final
Logger
LOG
=
Logger
.
getLogger
(
BdfMessageValidator
.
class
.
getName
());
Logger
.
getLogger
(
BdfMessageValidator
.
class
.
getName
());
...
@@ -38,6 +42,15 @@ public abstract class BdfMessageValidator implements MessageValidator {
...
@@ -38,6 +42,15 @@ public abstract class BdfMessageValidator implements MessageValidator {
@Override
@Override
public
Metadata
validateMessage
(
Message
m
,
Group
g
)
{
public
Metadata
validateMessage
(
Message
m
,
Group
g
)
{
return
validateMessage
(
m
,
g
,
MESSAGE_HEADER_LENGTH
);
}
@Override
public
Metadata
validateMessage
(
QueueMessage
q
,
Group
g
)
{
return
validateMessage
(
q
,
g
,
QUEUE_MESSAGE_HEADER_LENGTH
);
}
private
Metadata
validateMessage
(
Message
m
,
Group
g
,
int
headerLength
)
{
// Reject the message if it's too far in the future
// Reject the message if it's too far in the future
long
now
=
clock
.
currentTimeMillis
();
long
now
=
clock
.
currentTimeMillis
();
if
(
m
.
getTimestamp
()
-
now
>
MAX_CLOCK_DIFFERENCE
)
{
if
(
m
.
getTimestamp
()
-
now
>
MAX_CLOCK_DIFFERENCE
)
{
...
@@ -45,9 +58,13 @@ public abstract class BdfMessageValidator implements MessageValidator {
...
@@ -45,9 +58,13 @@ public abstract class BdfMessageValidator implements MessageValidator {
return
null
;
return
null
;
}
}
byte
[]
raw
=
m
.
getRaw
();
byte
[]
raw
=
m
.
getRaw
();
if
(
raw
.
length
<=
headerLength
)
{
LOG
.
info
(
"Message is too short"
);
return
null
;
}
try
{
try
{
BdfList
message
=
clientHelper
.
toList
(
raw
,
MESSAGE_HEADER_LENGTH
,
BdfList
message
=
clientHelper
.
toList
(
raw
,
headerLength
,
raw
.
length
-
MESSAGE_HEADER_LENGTH
);
raw
.
length
-
headerLength
);
BdfDictionary
meta
=
validateMessage
(
message
,
g
,
m
.
getTimestamp
());
BdfDictionary
meta
=
validateMessage
(
message
,
g
,
m
.
getTimestamp
());
if
(
meta
==
null
)
{
if
(
meta
==
null
)
{
LOG
.
info
(
"Invalid message"
);
LOG
.
info
(
"Invalid message"
);
...
...
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