Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lifespan to messages #1171

Merged
merged 9 commits into from
Jan 29, 2021
Merged

Conversation

limebell
Copy link
Member

@limebell limebell commented Jan 27, 2021

Added timestamp to messages. Network transport used in swarm will now ignore messages created in certain time before current time, or after current moment. The amount of lifespan of a message is configured in SwarmOptions.MessageLifespan, if null is given then timestamp will not being used in message validation.

There are API changes in Message, but I omitted it in the changelog because the abstract class Message haven't released yet.

Please refer to #1160.

@limebell limebell added the network Related to networking (Libplanet.Net) label Jan 27, 2021
@limebell limebell self-assigned this Jan 27, 2021
@limebell limebell changed the title Feature/message timestamp Add lifespan to messages Jan 27, 2021
@codecov
Copy link

codecov bot commented Jan 27, 2021

Codecov Report

Merging #1171 (034ad38) into main (64ecc25) will decrease coverage by 15.01%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             main    #1171       +/-   ##
===========================================
- Coverage   87.58%   72.56%   -15.02%     
===========================================
  Files         355       61      -294     
  Lines       31022     1604    -29418     
===========================================
- Hits        27171     1164    -26007     
+ Misses       2102      368     -1734     
+ Partials     1749       72     -1677     
Impacted Files Coverage Δ
Libplanet.Stun/Stun/TurnClientException.cs 0.00% <0.00%> (-80.00%) ⬇️
Libplanet.Stun/Stun/TurnClient.cs 0.00% <0.00%> (-79.60%) ⬇️
...lanet.Stun/Stun/Messages/BindingSuccessResponse.cs 40.00% <0.00%> (-20.00%) ⬇️
Libplanet.Stun/Stun/Messages/StunMessage.cs 69.02% <0.00%> (-1.64%) ⬇️
Libplanet/Net/Messages/DifferentVersion.cs
Libplanet/Store/Trie/Nodes/NodeDecoder.cs
...net.Tests/Store/Trie/CacheableKeyValueStoreTest.cs
Libplanet.Tests/Store/StoreTrackLog.cs
...sts/Blockchain/Policies/VolatileStagePolicyTest.cs
Libplanet/Net/AppProtocolVersion.cs
... and 280 more

CHANGES.md Outdated Show resolved Hide resolved
Libplanet/Net/InvalidTimestampException.cs Show resolved Hide resolved
Libplanet/Net/Messages/Message.cs Show resolved Hide resolved
Libplanet/Net/Messages/Message.cs Show resolved Hide resolved
Libplanet/Net/Messages/Message.cs Show resolved Hide resolved
Libplanet/Net/NetMQTransport.cs Show resolved Hide resolved
Libplanet/Net/SwarmOptions.cs Show resolved Hide resolved
Libplanet/Net/Messages/Message.cs Show resolved Hide resolved
Libplanet/Net/NetMQTransport.cs Show resolved Hide resolved
Libplanet/Net/NetMQTransport.cs Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
dahlia
dahlia previously approved these changes Jan 29, 2021
longfin
longfin previously approved these changes Jan 29, 2021
@dahlia
Copy link
Contributor

dahlia commented Jan 29, 2021

The unit test fails on ar_SA (Arabic/Saudi Arabia) & fr_FR (French/France):

Libplanet.Tests.Net.Messages.MessageTest.InvalidTimestamp [FAIL]
  Assert.Throws() Failure
  Expected: typeof(Libplanet.Net.InvalidTimestampException)
  Actual:   typeof(System.ArgumentOutOfRangeException): Specified time is not supported in this calendar. It should be between 04/30/1900 00:00:00 (Gregorian date) and 11/16/2077 23:59:59 (Gregorian date), inclusive. (Parameter 'time')
  Actual value was 3155378975999999999.
  ---- System.ArgumentOutOfRangeException : Specified time is not supported in this calendar. It should be between 04/30/1900 00:00:00 (Gregorian date) and 11/16/2077 23:59:59 (Gregorian date), inclusive. (Parameter 'time')
  Actual value was 3155378975999999999.
  Stack Trace:
       at System.Globalization.UmAlQuraCalendar.CheckTicksRange(Int64 ticks)
       at System.Globalization.UmAlQuraCalendar.GetDatePart(DateTime time, Int32 part)
       at System.Globalization.UmAlQuraCalendar.GetDayOfMonth(DateTime time)
       at System.DateTimeFormat.FormatCustomized(DateTime dateTime, ReadOnlySpan`1 format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder result)
       at System.DateTimeFormat.FormatStringBuilder(DateTime dateTime, ReadOnlySpan`1 format, DateTimeFormatInfo dtfi, TimeSpan offset)
       at System.DateTimeFormat.TryFormat(DateTime dateTime, Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider provider, TimeSpan offset)
       at System.DateTimeOffset.TryFormat(Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider formatProvider)
       at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
       at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
       at System.String.Format(String format, Object arg0)
    /home/vsts/work/1/s/Libplanet/Net/Messages/Message.cs(248,0): at Libplanet.Net.Messages.Message.Parse(NetMQMessage raw, Boolean reply, AppProtocolVersion localVersion, IImmutableSet`1 trustedAppProtocolVersionSigners, DifferentAppProtocolVersionEncountered differentAppProtocolVersionEncountered, Nullable`1 lifetime)
    /home/vsts/work/1/s/Libplanet.Tests/Net/Messages/MessageTest.cs(88,0): at Libplanet.Tests.Net.Messages.MessageTest.<>c__DisplayClass2_0.<InvalidTimestamp>b__0()
    ----- Inner Stack Trace -----
       at System.Globalization.UmAlQuraCalendar.CheckTicksRange(Int64 ticks)
       at System.Globalization.UmAlQuraCalendar.GetDatePart(DateTime time, Int32 part)
       at System.Globalization.UmAlQuraCalendar.GetDayOfMonth(DateTime time)
       at System.DateTimeFormat.FormatCustomized(DateTime dateTime, ReadOnlySpan`1 format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder result)
       at System.DateTimeFormat.FormatStringBuilder(DateTime dateTime, ReadOnlySpan`1 format, DateTimeFormatInfo dtfi, TimeSpan offset)
       at System.DateTimeFormat.TryFormat(DateTime dateTime, Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider provider, TimeSpan offset)
       at System.DateTimeOffset.TryFormat(Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider formatProvider)
       at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
       at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
       at System.String.Format(String format, Object arg0)
    /home/vsts/work/1/s/Libplanet/Net/Messages/Message.cs(248,0): at Libplanet.Net.Messages.Message.Parse(NetMQMessage raw, Boolean reply, AppProtocolVersion localVersion, IImmutableSet`1 trustedAppProtocolVersionSigners, DifferentAppProtocolVersionEncountered differentAppProtocolVersionEncountered, Nullable`1 lifetime)
    /home/vsts/work/1/s/Libplanet.Tests/Net/Messages/MessageTest.cs(88,0): at Libplanet.Tests.Net.Messages.MessageTest.<>c__DisplayClass2_0.<InvalidTimestamp>b__0()
Libplanet.Tests.Net.Messages.MessageTest.InvalidTimestamp [FINISHED] Time: 0٫0228238s

@limebell limebell dismissed stale reviews from longfin and dahlia via 034ad38 January 29, 2021 10:28
@limebell limebell merged commit be499b4 into planetarium:main Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
network Related to networking (Libplanet.Net)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants