Commit Graph

10184 Commits

Author SHA1 Message Date
Julian Knutsen
7b8d346aea
Remove filter for ExpirablePayload
ProtectedStorageEntry::backDate() already handles this
2019-12-04 17:28:17 -08:00
Julian Knutsen
b166009398
Remove expire optimization in onDisconnect
We already have a garbage collection thread that runs every minute
to clean up items. Doing it again during onDisconnect is an unnecessary
optimization that adds complexity and caused bugs.

For example, the original implementation did not handle the sequence
number map correctly and was removing entries during a stream iteration.

This also reduces the complexity of testing. There is one code path
responsible for reducing ttls and one code path responsible for
expiring entries. Much easier to reason about.
2019-12-04 17:25:39 -08:00
Julian Knutsen
df2e4cc013
Refactor P2PDataStorage::onDisconnect
1. Remove delete during stream iteration
2. Minimize branching w/ early returns for bad states
3. Use stream filter for readability
4. Implement additional checks that should be done when removing entries
2019-12-04 17:04:05 -08:00
Julian Knutsen
688405bc6d
[TESTS] Make onDisconnect tests more robust
Before refactoring the function ensure the tests cover all cases. This
fixes a bug where the payload ttl was too low in some instances causing
backDate to do no work when it should.
2019-12-04 16:55:41 -08:00
Julian Knutsen
c38ff9bf95
s/networkPayload/protectedStoragePayload
Helps readability when the variable name matches the type.
2019-12-04 16:01:52 -08:00
Julian Knutsen
01a7f79eec
Make CHECK_TTL_INTERVAL_SEC final
It is never changed
2019-12-04 16:00:11 -08:00
Julian Knutsen
104984cc22
@NotNull MailboxStoragePayload::senderPubKeyForAddOperation
In proto3 this is intialized to an empty ByteString so there is no valid
use for it to be null.
2019-12-04 11:39:26 -08:00
Julian Knutsen
76e8c5736a
@NotNull ProtectedStorageEntry::protectedStoragePayload
The ProtectedStoragePayload.fromProto code will throw an exception if
this is null from the wire so there is no valid use for it to be null.
2019-12-04 11:39:25 -08:00
Julian Knutsen
0c676080b6
@NotNull ProtectedStorageEntry::ownerPubKey
In proto3 the initialized value is an empty ByteString and there are no
valid uses of passing in null here.
2019-12-04 11:39:25 -08:00
Julian Knutsen
24ecfc7055
Remove ProtectedStorageEntry::maybeAdjustCreationTimeStamp
There is only 1 caller can be replaced with Math.min()
2019-12-04 11:37:53 -08:00
Julian Knutsen
b6b00268af
Remove ProtectedStorageEntry::updateSignature
The only users were tests that can just pass a bad signature directly
into the constructor.
2019-12-04 11:20:24 -08:00
Julian Knutsen
17f4b7096e
[TESTS] Clean up mockito never() and eq(null) usages
never() and any() don't play well together for nullable types. Change
the broadcast mocks to user nullable() and fixup tests.
2019-12-03 12:38:02 -08:00
Julian Knutsen
1bd450b3bc
[REFACTOR] inline maybeAddToRemoveAddOncePayloads() private function
Now that there is only one user it can be inlined.
2019-12-03 12:35:07 -08:00
Julian Knutsen
5a174d546a
[REFACTOR] inline broadcastProtectedStorageEntry() private function
Now that it is identical the the broadcaster version it can be
inlined.
2019-12-03 12:35:06 -08:00
Julian Knutsen
6ff8756dd8
[REFACTOR] inline broadcast() private function
Now that it is identical the the broadcaster version it can be
inlined.
2019-12-03 12:35:06 -08:00
Julian Knutsen
4dc4532c91
Remove isDataOwner from P2PDataStorage
Remove all usages in code and tests now that the behavior is
internal to the BroadcastHandler
2019-12-03 12:33:29 -08:00
Julian Knutsen
bfdb8f5715
Make isDataOwner a private policy decision in BroadcastHandler
isDataOwner is used when deciding how many peer nodes should receive
a BroadcastMessage. If the BroadcastMessage originated
on the local node it is sent to ALL peer nodes with a small delay.

If the node is only relaying the message (it originated on a different
node) it is sent to MAX(peers.size(), 7) peers with a delay that is
twice as long.

All the information needed to determine whether or not the
BroadcastMessage originated on the local node is available at the final
broadcast site and there is no reason to have callers pass it in.

In the event that the sender address is not known during broadcast (which
is only a remote possibility due to how early the local node address
is set during startup) we can default to relay mode.

This first patch just removes the deep parameters. The next will remove
everything else. There is one real change in LiteNodeNetworkService.java
where it was using the local node when it should have been using the
peer node. This was updated to the correct behavior.
2019-12-03 12:33:29 -08:00
Julian Knutsen
9f69134568
[REFACTOR] Clean up ClientAPI for refreshTTL
Remove isDataOwner from the client API. All users pass in true. All test
users don't care.
2019-12-03 12:30:07 -08:00
Julian Knutsen
77413c9671
[REFACTOR] Clean up ClientAPI for remove
Remove isDataOwner from the client API. All users pass in true. All test
users don't care.
2019-12-03 12:30:06 -08:00
Julian Knutsen
0e6b1a2044
[REFACTOR] Clean up ClientAPI for addProtectedStorageEntry
Remove isDataOwner from the client API. All users pass in true. All test
users don't care.
2019-12-03 12:30:06 -08:00
Julian Knutsen
56a7661a02
[REFACTOR] Clean up ClientAPI for addPersistableNetworkPayload
Now that more callers have moved internal, the public facing API
can be cleaner and more simple. This should lead to a more maintainable
API and less sharp edges with future development work.
2019-12-03 12:30:06 -08:00
Julian Knutsen
0649323505
Make addPersistableNetworkPayloadFromInitialRequest private
Now that the only user is internal, the API can be made private and the
tests can be removed. This involved adding a few test cases to
processGetDataResponse to ensure the invalid hash size condition was
still covered.
2019-12-03 12:30:05 -08:00
Julian Knutsen
4fe19aeec2
[DEADCODE] Remove old request handler tests
Now that all the implementations are unit tested in P2PDataStorage,
the old tests can be removed.
2019-12-03 12:20:42 -08:00
Julian Knutsen
b1a06fe4e2
Remove @Nullable around supportedCapabilities in PreliminaryGetDataRequest
The only two users of this constructor are the fromProto path which
now creates an empty Capabilities object similar to GetDataResponse.
The other internal usage of Capabilities.app which is initialized to empty.
2019-12-03 12:20:42 -08:00
Julian Knutsen
c503bcbaed
Remove @Nullable around supportedCapabilities in GetDataResponse
The only two users of this constructor are the fromProto path which
already creates an empty Capabilities object if one is not provided and
the internal usage of Capabilities.app which is initialized to empty.

Remove the @Nullable so future readers aren't confused.
2019-12-03 12:20:41 -08:00
Julian Knutsen
a0fae12068
Remove @Nullable around persistableNetworkPayloadSet
Checking for null creates hard-to-read code and it is simpler to just
create an empty set if we receive a pre-v0.6 GetDataResponse protobuf
message that does not have the field set.
2019-12-03 12:20:41 -08:00
Julian Knutsen
ecae31eddb
[RENAME] LazyProcessedPayload to ProcessOncePersistableNetworkPayload
Name is left over from previous implementation. Change it to be more
relevant to the current code and update comments to indicate the
current usage.
2019-12-03 12:20:41 -08:00
Julian Knutsen
5db128587f
[REFACTOR] Clean up processGetDataResponse
- Add more comments
- Use Clock instead of System
- Remove unnecessary AtomicInteger
2019-12-03 12:20:40 -08:00
Julian Knutsen
f92893b097
[TESTS] Write synchronization integration tests
Write a few integration test that exercises the exercise interesting
synchronization states including the lost remove bug. This fails
with the proper validation, but will pass at the end of the new feature
development.
2019-12-03 12:20:40 -08:00
Julian Knutsen
3d6e9fbef5
Remove static from initialRequestApplied
Previously, multiple handlers needed to signal off one global variable.
Now, that this check is inside the singleton P2PDataStorage, make it
non-static and private.
2019-12-03 12:20:40 -08:00
Julian Knutsen
a34488b735
[TESTS] Add unit tests for processGetDataResponse
Add a full set of unit tests that uncovered some unexpected
behavior w.r.t. signalers.
2019-12-03 12:20:39 -08:00
Julian Knutsen
690b9808b1
[TESTS] Make verify() functions more flexible
Now that we want to unit test the GetData path which has different
behavior w.r.t. broadcasts, the tests need a way to verify that
state was updated, but not broadcast during an add.

This patch changes all verification function to take each state update
explicitly so the tests can do the proper verification.
2019-12-03 12:20:39 -08:00
Julian Knutsen
873271c5ce
[REFACTOR] Introduce processGetDataResponse
Just a code move for now.
2019-12-03 12:20:39 -08:00
Julian Knutsen
c7bce9e999
[TESTS] Add test of RequestDataHandler::onMessage
Add heavy-handed test that exercises the logic to use as a safeguard
for refactoring.
2019-12-03 12:20:38 -08:00
Julian Knutsen
00128d912d
[BUGFIX] Fix off-by-one in truncation logic
Now, the truncation is only triggered if more than MAX_ENTRIES could
have been returned.
2019-12-03 12:20:38 -08:00
Julian Knutsen
e7673407f1
[REFACTOR] Remove duplication in filtering functions
Introduce a generic function that can be used to filter
Map<ByteArray, PersistableNetworkPayload> or
Map<ByteArray, ProtectedStorageEntry>.

Used to deduplicate the GetData code paths and ensure the logic is the
same between the two payload types.
2019-12-03 12:20:37 -08:00
Julian Knutsen
4c5d8184b7
[REFACTOR] Inline filtering functions
Removes unnecessary calculations converting Set<byte[]> into
Set<ByteArray> and allows additional deduplication of stream operations.
2019-12-03 12:20:37 -08:00
Julian Knutsen
3aaf8a285e
[REFACTOR] Inline capability check for ProtectedStorageEntries
Move the capability check inside the stream operation. This should
improve performance slightly, but more importantly it makes the
two filter functions almost identical so they can be combined.
2019-12-03 12:20:37 -08:00
Julian Knutsen
703a9a0ddd
[REFACTOR] Move required capabilities log
Move the logging function to the common capabilities check
so it can run on both ProtectedStoragePayload and
PersistableNetworkPayload objects
2019-12-03 12:20:36 -08:00
Julian Knutsen
caf946dfe0
Remove redundant HashSet lookups in filter functions
The appendOnlyDataStoreService and map already have unique keys that
are based on the hash of the payload. This would catch instances
where:

PersistableNetworkPayload
- None: The key is based on ByteArray(payload.getHash()) which is the
        same as this check.

ProtectedStorageEntry
- Cases where multiple PSEs contain payloads that have equivalent
  hashCode(), but different data.toProtoMessage().toByteArray().
  I don't think it is a good idea to keep 2 "unique" methods on
  payloads. This is likely left over from a time when
  Payload hashCode() needed to be different than the hash of
  the payload.
2019-12-03 12:20:36 -08:00
Julian Knutsen
5630b35755
[TESTS] Unit tests of buildGetDataResponse
Write a full set of unit tests for buildGetDataResponse. This provides
a safety net with additional refactoring work.
2019-12-03 12:20:36 -08:00
Julian Knutsen
dafc76200a
[REFACTOR] Pass peerCapabilities into buildGetDataResponse
Remove the dependence on the connection object by having the handler
pass in the peer's capabilities. This now allows unit testing of
buildGetDataResponse without any connection dependencies.
2019-12-03 12:20:35 -08:00
Julian Knutsen
a6e8868563
[REFACTOR] Extract truncation logging
Move the logging that utilizes connection information into the request
handler. Now, buildGetDataResponse just returns whether or not the list
is truncated which will make it easier to test.
2019-12-03 12:20:35 -08:00
Julian Knutsen
54021551bf
[REFACTOR] Extract getDataResponse logging
Changed the log to reference getDataResponse instead of getData. Now
that we might truncate the response, it ins't true that this is exactly
what the peer asked.
2019-12-03 12:20:35 -08:00
Julian Knutsen
8208f78837
[REFACTOR] Extract connectionInfo String 2019-12-03 12:20:34 -08:00
Julian Knutsen
944b3fffbc
[REFACTOR] Introduce buildGetDataResponse
This is just a strict move of code to reduce errors.
2019-12-03 12:20:34 -08:00
Julian Knutsen
daffe6dc38
[TESTS] Add tests of GetDataRequestHandler
Add some basic sanity tests prior to the refactor to help catch issues.
2019-12-03 12:20:34 -08:00
Julian Knutsen
a927ed42ac
[TESTS] Add tests of new RequestData APIs
These are identical test cases to the requestHandler tests, but with much
fewer dependencies. The requestHandler tests will eventually be deleted,
but they are going to remain throughout development as an extra safety
net.
2019-12-03 12:20:33 -08:00
Julian Knutsen
1e814d9f1d
[REFACTOR] Introduce buildGetDataRequest variants
As part of changing the GetData path, we want to move all creation
and processing of GetData messages inside P2PDataStorage. This will allow
easier unit testing of the behavior as well as cleaner code in the
request handlers that can just focus on nonces, connections, etc.
2019-12-03 12:20:33 -08:00
Julian Knutsen
5fcd18c4b5
[TESTS] Add tests of requestData
This will allow us to push the GetData creation inside P2PDataStorage
safely.
2019-12-03 12:20:28 -08:00