Skip to content

Commit ebc40cc

Browse files
- DocFx setup
- Improvements to naming convention - Added NetworkTasks
1 parent fdaeeb4 commit ebc40cc

File tree

337 files changed

+41278
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

337 files changed

+41278
-118
lines changed

P2PBootstrap/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
global using static P2PNet.PeerNetwork;
2-
global using static P2PNet.Distribution.Distribution_Protocol;
2+
global using static P2PNet.Distribution.DistributionProtocol;
33
global using static ConsoleDebugger.ConsoleDebugger;
44
global using static P2PBootstrap.GlobalConfig;
55
global using static P2PBootstrap.Database.DatabaseService;
@@ -9,7 +9,6 @@
99
using Microsoft.Extensions.Hosting;
1010
using Microsoft.Extensions.Configuration;
1111
using P2PNet;
12-
using P2PNet.Distribution;
1312
using P2PNet.NetworkPackets;
1413
using P2PNet.Peers;
1514
using System.Text.Json.Serialization;
@@ -24,6 +23,7 @@
2423
using Microsoft.Extensions.FileProviders;
2524
using ConsoleDebugger;
2625
using P2PBootstrap.Encryption;
26+
using P2PNet.Distribution.NetworkTasks;
2727

2828
namespace P2PBootstrap
2929
{

P2PBootstrap/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"xterm": "^5.3.0"
4+
}
5+
}

P2PNet/DicoveryChannels/Discovery_Channel_Base.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Net.Sockets;
1010
using System.Text;
1111
using System.Threading.Tasks;
12-
using static P2PNet.Distribution.Distribution_Protocol;
12+
using static P2PNet.Distribution.DistributionProtocol;
1313
using static P2PNet.Distribution.DistributionHandler;
1414
using static P2PNet.PeerNetwork;
1515

P2PNet/Distribution/Distribution_Protocol.cs

+5-107
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using P2PNet.NetworkPackets;
1+
using P2PNet.Distribution.NetworkTasks;
2+
using P2PNet.NetworkPackets;
23
using P2PNet.Peers;
34
using System;
45
using System.Collections.Generic;
@@ -12,10 +13,10 @@
1213
namespace P2PNet.Distribution
1314
{
1415
/// <summary>
15-
/// The Distribution_Protocol provides uniformity with data exchange, packet formatting, and other functions within the peer-to-peer network.
16+
/// The DistributionProtocol provides uniformity with data exchange, packet formatting, and other functions within the peer-to-peer network.
1617
/// This should be included as a static reference.
1718
/// </summary>
18-
public static class Distribution_Protocol
19+
public static class DistributionProtocol
1920
{
2021
public struct MessageTags
2122
{
@@ -198,112 +199,9 @@ public static T Deserialize<T>(string json)
198199
#endregion
199200
}
200201

201-
#region Tasks
202-
203-
/// <summary>
204-
/// Defines the types of tasks that can be executed within the peer-to-peer network.
205-
/// </summary>
206-
public enum TaskType
207-
{
208-
/// <summary>
209-
/// Block a peer and removes it from the network.
210-
/// </summary>
211-
BlockAndRemovePeer,
212-
213-
/// <summary>
214-
/// Block a specific IP address from connecting to the network.
215-
/// </summary>
216-
BlockIP,
217-
218-
/// <summary>
219-
/// Send a message to a specific peer or group of peers.
220-
/// </summary>
221-
SendMessage,
222-
223-
/// <summary>
224-
/// Send a ping to a specific peer to check its availability.
225-
/// </summary>
226-
PingPeer,
227-
228-
/// <summary>
229-
/// Disconnect a specific peer from the network.
230-
/// </summary>
231-
DisconnectPeer,
232-
233-
/// <summary>
234-
/// Authorize a peer to perform certain actions or access certain resources.
235-
/// </summary>
236-
AuthorizePeer,
237-
238-
/// <summary>
239-
/// Revoke the authorization of a peer.
240-
/// </summary>
241-
RevokePeerAuthorization,
242-
243-
/// <summary>
244-
/// Request specific data from a peer.
245-
/// </summary>
246-
RequestData,
247-
248-
/// <summary>
249-
/// Send specific data to a peer.
250-
/// </summary>
251-
SendData,
252-
253-
/// <summary>
254-
/// Synchronize data between peers.
255-
/// </summary>
256-
SynchronizeData,
257-
258-
/// <summary>
259-
/// Update network settings or peer settings.
260-
/// </summary>
261-
UpdateSettings,
262-
263-
/// <summary>
264-
/// Verify the PGP signature of a message or command.
265-
/// </summary>
266-
VerifySignature,
267-
268-
/// <summary>
269-
/// Request the public key of a peer or bootstrap server.
270-
/// </summary>
271-
RequestPublicKey,
272-
273-
/// <summary>
274-
/// Send the public key to a peer or bootstrap server.
275-
/// </summary>
276-
SendPublicKey,
277-
278-
/// <summary>
279-
/// Send a heartbeat signal to check the status of a peer or server.
280-
/// </summary>
281-
Heartbeat
282-
}
283-
284202
/// <summary>
285-
/// Represents a network task that can be executed within the peer-to-peer network.
203+
/// This region keeps the packet objects and classes AOT compliant for JSON serialization.
286204
/// </summary>
287-
/// <remarks>
288-
/// A network task defines an action to be performed, such as blocking a peer, sending a message, or synchronizing data.
289-
/// Each task is identified by a <see cref="TaskType"/> and can include additional data in the form of key-value pairs.
290-
/// </remarks>
291-
public sealed class NetworkTask
292-
{
293-
public TaskType TaskType { get; set; }
294-
public Dictionary<string, string> TaskData { get; set; }
295-
296-
[JsonConstructor]
297-
public NetworkTask() { }
298-
299-
public byte[] ToByte()
300-
{
301-
return Encoding.UTF8.GetBytes(Distribution_Protocol.Serialize(this));
302-
}
303-
}
304-
305-
#endregion
306-
307205
#region PACKET_CONTEXT
308206
[JsonSerializable(typeof(PureMessagePacket))]
309207
public partial class PureMessagePacketContext : JsonSerializerContext { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System.Text;
2+
using System.Text.Json.Serialization;
3+
4+
namespace P2PNet.Distribution.NetworkTasks
5+
{
6+
/// <summary>
7+
/// Represents a network task that can be executed within the peer-to-peer network.
8+
/// </summary>
9+
/// <remarks>
10+
/// A network task defines an action to be performed, such as blocking a peer, sending a message, or synchronizing data.
11+
/// Each task is identified by a <see cref="TaskType"/> and can include additional data in the form of key-value pairs.
12+
/// </remarks>
13+
public sealed class NetworkTask
14+
{
15+
public TaskType TaskType { get; set; }
16+
public Dictionary<string, string> TaskData { get; set; }
17+
18+
[JsonConstructor]
19+
public NetworkTask() { }
20+
21+
public byte[] ToByte()
22+
{
23+
return Encoding.UTF8.GetBytes(Serialize(this));
24+
}
25+
}
26+
27+
/// <summary>
28+
/// Defines the types of tasks that can be executed within the peer-to-peer network.
29+
/// </summary>
30+
public enum TaskType
31+
{
32+
/// <summary>
33+
/// Block a peer and removes it from the network.
34+
/// </summary>
35+
BlockAndRemovePeer,
36+
37+
/// <summary>
38+
/// Block a specific IP address from connecting to the network.
39+
/// </summary>
40+
BlockIP,
41+
42+
/// <summary>
43+
/// Send a message to a specific peer or group of peers.
44+
/// </summary>
45+
SendMessage,
46+
47+
/// <summary>
48+
/// Send a ping to a specific peer to check its availability.
49+
/// </summary>
50+
PingPeer,
51+
52+
/// <summary>
53+
/// Disconnect a specific peer from the network.
54+
/// </summary>
55+
DisconnectPeer,
56+
57+
/// <summary>
58+
/// Authorize a peer to perform certain actions or access certain resources.
59+
/// </summary>
60+
AuthorizePeer,
61+
62+
/// <summary>
63+
/// Revoke the authorization of a peer.
64+
/// </summary>
65+
RevokePeerAuthorization,
66+
67+
/// <summary>
68+
/// Request specific data from a peer.
69+
/// </summary>
70+
RequestData,
71+
72+
/// <summary>
73+
/// Send specific data to a peer.
74+
/// </summary>
75+
SendData,
76+
77+
/// <summary>
78+
/// Synchronize data between peers.
79+
/// </summary>
80+
SynchronizeData,
81+
82+
/// <summary>
83+
/// Update network settings or peer settings.
84+
/// </summary>
85+
UpdateSettings,
86+
87+
/// <summary>
88+
/// Verify the PGP signature of a message or command.
89+
/// </summary>
90+
VerifySignature,
91+
92+
/// <summary>
93+
/// Request the public key of a peer or bootstrap server.
94+
/// </summary>
95+
RequestPublicKey,
96+
97+
/// <summary>
98+
/// Send the public key to a peer or bootstrap server.
99+
/// </summary>
100+
SendPublicKey,
101+
102+
/// <summary>
103+
/// Send a heartbeat signal to check the status of a peer or server.
104+
/// </summary>
105+
/// <remarks>This can be useful with bootstrap servers to track if peers are still live or drop off the network.</remarks>
106+
Heartbeat,
107+
108+
/// <summary>
109+
/// Set the local identifier to the specified value.
110+
/// </summary>
111+
/// <remarks>This can be useful with the Authority trust policy to assign unique IDs to peers.</remarks>
112+
AcceptIdentifier,
113+
114+
/// <summary>
115+
/// Set the identifier of a peer to the specified value.
116+
/// </summary>
117+
AssignIdentifierToPeer,
118+
}
119+
120+
}

P2PNet/NetworkPackets/CollectionSharePacket.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace P2PNet.NetworkPackets
1212
{
1313
/// <summary>
14-
/// Standard packet used to relay a collection of peer-identifying information through out a network.
14+
/// Standard packet used to relay a collection of peers on the network using peer-identifying information.
1515
/// </summary>
1616
public class CollectionSharePacket : INetworkPacket
1717
{

P2PNet/NetworkPackets/DataTransmissionPacket.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
using static P2PNet.Distribution.Distribution_Protocol;
1+
using static P2PNet.Distribution.DistributionProtocol;
22
using P2PNet.NetworkPackets;
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Text;
77
using System.Threading.Tasks;
8+
using P2PNet.Distribution.NetworkTasks;
89

910
namespace P2PNet.NetworkPackets
1011
{
1112
/// <summary>
12-
/// Represents a data transmission packet used for transmitting data throughout the peer network.
13+
/// Represents a data transmission packet used for transmitting data throughout the peer-to-peer network.
1314
/// </summary>
15+
/// <remarks>This packet can be used to transmit <see cref="NetworkTask"/> and files throughout the network.</remarks>
1416
public sealed class DataTransmissionPacket : INetworkPacket
1517
{
1618
/// <summary>

P2PNet/P2PNet.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<IsPackable>true</IsPackable>
@@ -33,7 +33,7 @@ Including PacketDotNet and SharpPcap as dependencies.</PackageReleaseNotes>
3333
</ItemGroup>
3434

3535
<ItemGroup>
36-
<Using Include="P2PNet.Distribution.Distribution_Protocol">
36+
<Using Include="P2PNet.Distribution.DistributionProtocol">
3737
<Static>True</Static>
3838
</Using>
3939
<Using Include="System.Timers.Timer">

P2PNet/PeerNetwork.cs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static class PeerNetwork
6060

6161
/// <summary>
6262
/// Gets or sets whether a designated TCP port will be actively listening for and accepting inbound TCP peer connections.
63+
/// Setting this value will automatically start or stop acceptance of inbound peers.
6364
/// The default is true, but you may want to toggle this for server instances that serve different network purposes.
6465
/// </summary>
6566
public static bool AcceptInboundPeers

P2PNet/Peers/PeerChannel.cs

+17
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,37 @@
1313

1414
namespace P2PNet.Peers
1515
{
16+
/// <summary>
17+
/// Represents a communication channel with a peer in the P2P network.
18+
/// </summary>
1619
public class PeerChannel : PeerChannel_Base
1720
{
1821
/// <summary>
1922
/// Gets the DateTime value of when the last piece of data or information was received from this peer.
2023
/// </summary>
2124
public DateTime LastIncomingDataReceived { get; internal set; } = DateTime.Now;
2225

26+
/// <summary>
27+
/// Gets or sets the peer associated with this channel.
28+
/// </summary>
2329
public IPeer peer { get; set; }
2430

2531
private int RETRIES = 0; // for retrying connections
2632
public int GOODPINGS { get; internal set; } = 0; // readonly
2733
private const int MAX_RETRIES = 3;
2834

35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="PeerChannel"/> class with the specified peer.
37+
/// </summary>
38+
/// <param name="peer_">The peer to associate with this channel.</param>
2939
public PeerChannel(IPeer peer_)
3040
{
3141
peer = peer_;
3242
}
3343

44+
/// <summary>
45+
/// Opens the communication channel with the peer and starts handling incoming and outgoing data.
46+
/// </summary>
3447
public async void OpenPeerChannel()
3548
{
3649
cancelSender = new CancellationTokenSource();
@@ -52,6 +65,10 @@ public async void OpenPeerChannel()
5265
Task.Run(() => CreatePing());
5366
}
5467
}
68+
69+
/// <summary>
70+
/// Closes the communication channel with the peer and terminates all associated tasks.
71+
/// </summary>
5572
public void ClosePeerChannel()
5673
{
5774
if ((cancelSender != null) && (cancelReceiver != null))

0 commit comments

Comments
 (0)