Skip to content

Commit

Permalink
move to newtonsoft
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Dec 19, 2021
1 parent d50b343 commit cba0975
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 159 deletions.
38 changes: 20 additions & 18 deletions .run/OnionFruit Country List Generator.run.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="OnionFruit Country List Generator" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/generator/bin/Debug/net6.0/DragonFruit.OnionFruit.Tools.CountryList.exe" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/generator/bin/Debug/net6.0" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/generator/DragonFruit.OnionFruit.Tools.CountryList.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net6.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
<configuration default="false" name="OnionFruit Country List Generator" type="DotNetProject"
factoryName=".NET Project">
<option name="EXE_PATH"
value="$PROJECT_DIR$/generator/bin/Debug/net6.0/DragonFruit.OnionFruit.Tools.CountryList.exe"/>
<option name="PROGRAM_PARAMETERS" value=""/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/generator/bin/Debug/net6.0"/>
<option name="PASS_PARENT_ENVS" value="1"/>
<option name="USE_EXTERNAL_CONSOLE" value="0"/>
<option name="USE_MONO" value="0"/>
<option name="RUNTIME_ARGUMENTS" value=""/>
<option name="PROJECT_PATH" value="$PROJECT_DIR$/generator/DragonFruit.OnionFruit.Tools.CountryList.csproj"/>
<option name="PROJECT_EXE_PATH_TRACKING" value="1"/>
<option name="PROJECT_ARGUMENTS_TRACKING" value="1"/>
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1"/>
<option name="PROJECT_KIND" value="DotNetCore"/>
<option name="PROJECT_TFM" value="net6.0"/>
<method v="2">
<option name="Build"/>
</method>
</configuration>
</component>
4 changes: 2 additions & 2 deletions generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using Bia.Countries.Iso3166;
using DragonFruit.Data;
using DragonFruit.Data.Serializers.SystemJson;
using DragonFruit.Data.Serializers.Newtonsoft;
using DragonFruit.OnionFruit.Api.Enums;
using DragonFruit.OnionFruit.Api.Extensions;
using DragonFruit.OnionFruit.Api.Objects;
Expand All @@ -17,7 +17,7 @@ namespace DragonFruit.OnionFruit.Tools.CountryList
{
internal static class Program
{
private static readonly ApiClient Client = new ApiClient<ApiSystemTextJsonSerializer>();
private static readonly ApiClient Client = new ApiClient<ApiJsonSerializer>();

private static async Task Main(string[] args)
{
Expand Down
25 changes: 0 additions & 25 deletions src/Converters/DateTimeConverter.cs

This file was deleted.

15 changes: 7 additions & 8 deletions src/Converters/MillisecondEpochConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace DragonFruit.OnionFruit.Api.Converters
{
internal class MillisecondEpochConverter : JsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer)
{
var time = reader.GetInt64();
return new DateTime(1970, 1, 1).AddMilliseconds(time);
var epoch = value.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
writer.WriteValue((int)epoch);
}

public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var epoch = value.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
writer.WriteNumberValue((int)epoch);
var time = reader.ReadAsString();
return new DateTime(1970, 1, 1).AddMilliseconds(long.Parse(time));
}
}
}
2 changes: 1 addition & 1 deletion src/DragonFruit.OnionFruit.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="DragonFruit.Data" Version="2021.1218.0"/>
<PackageReference Include="DragonFruit.Data.Serializers.SystemJson" Version="2021.1218.0"/>
<PackageReference Include="DragonFruit.Data.Serializers.Newtonsoft" Version="2021.1218.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
39 changes: 20 additions & 19 deletions src/Objects/TorBridgeDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details

using System;
using System.Text.Json.Serialization;
using System.Runtime.Serialization;
using DragonFruit.OnionFruit.Api.Converters;
using DragonFruit.OnionFruit.Api.Enums;
using Newtonsoft.Json;

namespace DragonFruit.OnionFruit.Api.Objects
{
[Serializable]
[DataContract]
[JsonObject(MemberSerialization.OptIn)]
public class TorBridgeDetails
{
[JsonPropertyName("nickname")]
[DataMember(Name = "nickname")]
public string Nickname { get; set; }

[JsonPropertyName("hashed_fingerprint")]
[DataMember(Name = "hashed_fingerprint")]
public string HashedFingerprint { get; set; }

[JsonPropertyName("first_seen")]
[JsonConverter(typeof(DateTimeConverter))]
[DataMember(Name = "first_seen")]
public DateTime FirstSeen { get; set; }

[JsonPropertyName("last_seen")]
[JsonConverter(typeof(DateTimeConverter))]
[DataMember(Name = "last_seen")]
public DateTime LastSeen { get; set; }

/// <summary>
/// Whether the Bridge is currently online
/// </summary>
[JsonPropertyName("running")]
[DataMember(Name = "running")]
public bool Running { get; set; }

/// <summary>
/// Features the tor node has
/// </summary>
public TorNodeFlags Flags { get; set; }

[JsonPropertyName("flags")]
[DataMember(Name = "flags")]
public string[] RawFlags
{
get => NodeFlagConverter.ToString(Flags);
Expand All @@ -46,44 +47,44 @@ public string[] RawFlags
/// <summary>
/// UTC DateTime the server was last restarted
/// </summary>
[JsonPropertyName("last_restarted")]
[JsonConverter(typeof(DateTimeConverter))]
[DataMember(Name = "last_restarted")]

public DateTime? LastRestarted { get; set; }

/// <summary>
/// Bandwidth, in bytes/sec, the server is capable of providing
/// </summary>
[JsonPropertyName("advertised_bandwidth")]
[DataMember(Name = "advertised_bandwidth")]
public long AdvertisedBandwidth { get; set; }

/// <summary>
/// The Tor version and
/// The Tor version and
/// </summary>
[JsonPropertyName("platform")]
[DataMember(Name = "platform")]
public string Platform { get; set; }

/// <summary>
/// The version of Tor the server is running
/// </summary>
[JsonPropertyName("version")]
[DataMember(Name = "version")]
public string Version { get; set; }

/// <summary>
/// Whether the bridge is running a recommended version of Tor
/// </summary>
[JsonPropertyName("recommended_version")]
[DataMember(Name = "recommended_version")]
public bool RecommendedVersion { get; set; }

/// <summary>
/// The pluggable transport types this bridge supports
/// </summary>
[JsonPropertyName("transports")]
[DataMember(Name = "transports")]
public string[] Transports { get; set; }

[JsonPropertyName("or_addresses")]
[DataMember(Name = "or_addresses")]
public string[] OrAddresses { get; set; }

[JsonPropertyName("bridgedb_distributor")]
[DataMember(Name = "bridgedb_distributor")]
public string BridgeDbDistributor { get; set; }
}
}
11 changes: 7 additions & 4 deletions src/Objects/TorBridgeSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details

using System;
using System.Text.Json.Serialization;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace DragonFruit.OnionFruit.Api.Objects
{
[Serializable]
[DataContract]
[JsonObject(MemberSerialization.OptIn)]
public class TorBridgeSummary
{
/// <summary>
/// The relay nickname, represented as 1-19 chars
/// </summary>
[JsonPropertyName("n")]
[DataMember(Name = "n")]
public string Nickname { get; set; }

/// <summary>
/// SHA-1 hash of the bridge fingerprint
/// </summary>
[JsonPropertyName("h")]
[DataMember(Name = "h")]
public string Fingerprint { get; set; }

/// <summary>
/// Whether the relay was running at the last consensus
/// </summary>
[JsonPropertyName("r")]
[DataMember(Name = "r")]
public bool Running { get; set; }
}
}
9 changes: 6 additions & 3 deletions src/Objects/TorClientConnectionHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace DragonFruit.OnionFruit.Api.Objects
{
[Serializable]
[DataContract]
[JsonObject(MemberSerialization.OptIn)]
public class TorClientConnectionHistory
{
[JsonPropertyName("fingerprint")]
[DataMember(Name = "fingerprint")]
public string Fingerprint { get; set; }

[JsonPropertyName("average_clients")]
[DataMember(Name = "average_clients")]
public IReadOnlyDictionary<string, TorHistoryGraph> Clients { get; set; }
}
}
18 changes: 9 additions & 9 deletions src/Objects/TorHistoryGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using DragonFruit.OnionFruit.Api.Converters;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace DragonFruit.OnionFruit.Api.Objects
{
[Serializable]
[DataContract]
[JsonObject(MemberSerialization.OptIn)]
public class TorHistoryGraph
{
[JsonPropertyName("first")]
[JsonConverter(typeof(DateTimeConverter))]
[DataMember(Name = "first")]
public DateTime Start { get; set; }

[JsonPropertyName("last")]
[JsonConverter(typeof(DateTimeConverter))]
[DataMember(Name = "last")]
public DateTime End { get; set; }

[JsonPropertyName("interval")]
[DataMember(Name = "interval")]
public int IntervalSeconds { get; set; }

/// <summary>
Expand All @@ -32,13 +32,13 @@ public class TorHistoryGraph
/// <summary>
/// The scale factor each value needs to be multiplied by to get the original value
/// </summary>
[JsonPropertyName("factor")]
[DataMember(Name = "factor")]
public double ScaleFactor { get; set; }

/// <summary>
/// The normalised values, as sent by the api
/// </summary>
[JsonPropertyName("values")]
[DataMember(Name = "values")]
public int?[] NormalisedValues { get; set; }

/// <summary>
Expand Down
13 changes: 8 additions & 5 deletions src/Objects/TorNodeBandwidthHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace DragonFruit.OnionFruit.Api.Objects
{
[Serializable]
[DataContract]
[JsonObject(MemberSerialization.OptIn)]
public class TorNodeBandwidthHistory
{
[JsonPropertyName("fingerprint")]
[DataMember(Name = "fingerprint")]
public string Fingerprint { get; set; }

[JsonPropertyName("write_history")]
[DataMember(Name = "write_history")]
public IReadOnlyDictionary<string, TorHistoryGraph> WriteHistory { get; set; }

[JsonPropertyName("read_history")]
[DataMember(Name = "read_history")]
public IReadOnlyDictionary<string, TorHistoryGraph> ReadHistory { get; set; }

[JsonPropertyName("overload_ratelimits")]
[DataMember(Name = "overload_ratelimits")]
public TorNodeOverloadRateLimit OverloadRateLimits { get; set; }
}
}
Loading

0 comments on commit cba0975

Please sign in to comment.