├── P2PNET.Test
├── app.config
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ └── AssemblyInfo.cs
├── Cat.cs
├── Dog.cs
├── Fish.cs
├── packages.config
├── FilePart.cs
├── Pet.cs
├── Person.cs
└── P2PNET.Test.csproj
├── Samples
├── WorkSpace
│ ├── App.config
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── packages.config
│ ├── Cat.cs
│ ├── Dog.cs
│ ├── Fish.cs
│ ├── Pet.cs
│ ├── Program.cs
│ ├── Person.cs
│ ├── Form1.cs
│ ├── Form1.Designer.cs
│ ├── WorkSpace.csproj
│ └── Form1.resx
├── ObjectSamples
│ └── ObjectSender
│ │ ├── App.config
│ │ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ │ ├── packages.config
│ │ ├── Cat.cs
│ │ ├── Dog.cs
│ │ ├── Fish.cs
│ │ ├── Program.cs
│ │ ├── Pet.cs
│ │ ├── Person.cs
│ │ ├── Form1.cs
│ │ ├── Form1.resx
│ │ └── ObjectSender.csproj
└── TransportSamples
│ ├── AutoDiscovery
│ ├── App.config
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── packages.config
│ ├── Program.cs
│ ├── HeartBeatManager.cs
│ ├── Form1.cs
│ ├── Form1.Designer.cs
│ ├── AutoDiscovery.csproj
│ └── Form1.resx
│ ├── MessageProgram
│ ├── App.config
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── packages.config
│ ├── Program.cs
│ ├── Form1.cs
│ ├── Form1.Designer.cs
│ └── BroadcastProgram.csproj
│ └── MessageSender
│ ├── App.config
│ ├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
│ ├── packages.config
│ ├── Program.cs
│ ├── Form1.cs
│ └── MessageSender.csproj
├── P2PNET
├── ILogger.cs
├── TransportLayer
│ ├── TransportType.cs
│ ├── EventArgs
│ │ ├── PeerEventArgs.cs
│ │ ├── PeerChangeEventArgs.cs
│ │ └── MsgReceivedEventArgs.cs
│ ├── AbstractStreamUtil.cs
│ ├── ReadStreamUtil.cs
│ ├── BufferedUDPStream.cs
│ ├── WriteStreamUtil.cs
│ └── Peer.cs
├── FileLayer
│ ├── EventArgs
│ │ ├── DebugInfoEventArgs.cs
│ │ ├── FileReceivedEventArgs.cs
│ │ └── FileTransferEventArgs.cs
│ ├── SendableObjects
│ │ ├── ReqAck.cs
│ │ ├── FileMeta.cs
│ │ ├── FileAck.cs
│ │ ├── FileReqMeta.cs
│ │ └── FilePartObj.cs
│ ├── FileReceivedReq.cs
│ ├── FileSentReq.cs
│ └── FileTransReq.cs
├── packages.config
├── ObjectLayer
│ ├── EventArgs
│ │ └── ObjReceivedEventArgs.cs
│ ├── Metadata.cs
│ ├── ObjPackage.cs
│ ├── BObject.cs
│ └── Serializer.cs
├── P2PNET.nuspec
├── Properties
│ └── AssemblyInfo.cs
└── Exceptions.cs
├── LICENSE
├── README.md
├── P2PNET.sln
└── .gitignore
/P2PNET.Test/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageProgram/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageSender/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/P2PNET.Test/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/P2PNET/ILogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET
8 | {
9 | public interface ILogger
10 | {
11 | void WriteLine(string msg);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/P2PNET/TransportLayer/TransportType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.TransportLayer
8 | {
9 | public enum TransportType
10 | {
11 | TCP,
12 | UDP
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/EventArgs/DebugInfoEventArgs.cs:
--------------------------------------------------------------------------------
1 | namespace P2PNET.FileLayer.EventArgs
2 | {
3 | public class DebugInfoEventArgs : System.EventArgs
4 | {
5 | public string Msg { get; }
6 | public DebugInfoEventArgs(string msg)
7 | {
8 | this.Msg = msg;
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageProgram/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageSender/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageProgram/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageSender/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/P2PNET.Test/Cat.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | class Cat : Pet
10 | {
11 | public Cat(string petName) : base(petName)
12 | {
13 | this.Type = AnimalType.Cat;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/P2PNET.Test/Dog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | class Dog : Pet
10 | {
11 |
12 | public Dog(string petName) : base(petName)
13 | {
14 | this.Type = AnimalType.Dog;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/P2PNET.Test/Fish.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | class Fish : Pet
10 | {
11 | public Fish(string petName) : base(petName)
12 | {
13 | this.Type = AnimalType.Fish;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Cat.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | class Cat : Pet
10 | {
11 | public Cat(string petName) : base(petName)
12 | {
13 | this.Type = AnimalType.Cat;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Dog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | class Dog : Pet
10 | {
11 |
12 | public Dog(string petName) : base(petName)
13 | {
14 | this.Type = AnimalType.Dog;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Fish.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | class Fish : Pet
10 | {
11 | public Fish(string petName) : base(petName)
12 | {
13 | this.Type = AnimalType.Fish;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/P2PNET.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/P2PNET/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Cat.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ObjectSender
8 | {
9 | class Cat : Pet
10 | {
11 | public Cat(string petName) : base(petName)
12 | {
13 | this.Type = AnimalType.Cat;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Dog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ObjectSender
8 | {
9 | class Dog : Pet
10 | {
11 |
12 | public Dog(string petName) : base(petName)
13 | {
14 | this.Type = AnimalType.Dog;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/P2PNET/TransportLayer/EventArgs/PeerEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 |
4 | namespace P2PNET.TransportLayer.EventArgs
5 | {
6 | public class PeerEventArgs : System.EventArgs
7 | {
8 | public Peer Peer { get; }
9 |
10 | //constructor
11 | public PeerEventArgs( Peer peer )
12 | {
13 | this.Peer = peer;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/EventArgs/FileReceivedEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.FileLayer.EventArgs
8 | {
9 | public class FileReceivedEventArgs : System.EventArgs
10 | {
11 | //constructor
12 | public FileReceivedEventArgs()
13 | {
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/P2PNET/TransportLayer/EventArgs/PeerChangeEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 |
4 | namespace P2PNET.TransportLayer.EventArgs
5 | {
6 | public class PeerChangeEventArgs : System.EventArgs
7 | {
8 | public List Peers { get; }
9 |
10 | //constructor
11 | public PeerChangeEventArgs( List peers )
12 | {
13 | this.Peers = peers;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Fish.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ObjectSender
8 | {
9 | class Fish : Pet
10 | {
11 | public bool FreshWater { get; set; }
12 | public Fish(string petName) : base(petName)
13 | {
14 | this.Type = AnimalType.Fish;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/SendableObjects/ReqAck.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.FileLayer.SendableObjects
8 | {
9 | class ReqAck
10 | {
11 | public bool AcceptedFile { get; set; }
12 |
13 | //constructor
14 | public ReqAck(bool mAcceptedFile)
15 | {
16 | this.AcceptedFile = mAcceptedFile;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/P2PNET.Test/FilePart.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | public class FilePart
10 | {
11 | public byte[] BinaryData { get; set; }
12 |
13 | public int Length;
14 |
15 | public FilePart(byte[] mBinaryData)
16 | {
17 | this.BinaryData = mBinaryData;
18 | this.Length = mBinaryData.Length;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/P2PNET/ObjectLayer/EventArgs/ObjReceivedEventArgs.cs:
--------------------------------------------------------------------------------
1 | using P2PNET.ObjectLayer;
2 | using P2PNET.TransportLayer;
3 |
4 | namespace P2PNET.ObjectLayer.EventArgs
5 | {
6 | public class ObjReceivedEventArgs : System.EventArgs
7 | {
8 | public BObject Obj { get; }
9 | public Metadata Meta { get; }
10 |
11 | //constructor
12 | public ObjReceivedEventArgs(BObject mObj, Metadata mMetadata)
13 | {
14 | this.Obj = mObj;
15 | this.Meta = mMetadata;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/P2PNET/ObjectLayer/Metadata.cs:
--------------------------------------------------------------------------------
1 | using P2PNET.TransportLayer;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Runtime.Serialization;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace P2PNET.ObjectLayer
10 | {
11 | public class Metadata
12 | {
13 | //the type of the object
14 | public string ObjectType { get; set; }
15 |
16 | public string SourceIp { get; set; }
17 |
18 | //UDP or TCP
19 | public TransportType? BindType { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Pet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | public enum AnimalType
10 | {
11 | Dog = 0,
12 | Cat = 1,
13 | Fish = 2
14 | }
15 | public class Pet
16 | {
17 | public AnimalType Type { get; set; }
18 | public string Name { get; set; }
19 |
20 | public Pet(string petName)
21 | {
22 | this.Name = petName;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/P2PNET/TransportLayer/EventArgs/MsgReceivedEventArgs.cs:
--------------------------------------------------------------------------------
1 | namespace P2PNET.TransportLayer.EventArgs
2 | {
3 | public class MsgReceivedEventArgs : System.EventArgs
4 | {
5 | public byte[] Message { get; }
6 | public TransportType BindingType { get; }
7 | public string RemoteIp { get; }
8 |
9 | public MsgReceivedEventArgs(string remoteIp, byte[] msg, TransportType bindType)
10 | {
11 | this.RemoteIp = remoteIp;
12 | this.Message = msg;
13 | this.BindingType = bindType;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace WorkSpace
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form1());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/P2PNET/ObjectLayer/ObjPackage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.ObjectLayer
8 | {
9 | public class ObjPackage
10 | {
11 | public T Obj { get; set; }
12 | public Metadata Metadata { get; set; }
13 |
14 | public ObjPackage()
15 | {
16 | }
17 |
18 | //constructor
19 | public ObjPackage(T mObject, Metadata metadata)
20 | {
21 | this.Obj = mObject;
22 | this.Metadata = metadata;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace ObjectSender
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form1());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace AutoDiscovery
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form1());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageSender/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace MessageSender
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form1());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageProgram/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace BroadcastProgram
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form1());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/SendableObjects/FileMeta.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.FileLayer.SendableObjects
8 | {
9 | public class FileMeta
10 | {
11 | public string FileName { get; set; }
12 | public string FilePath { get; set; }
13 | public long FileSize { get; set; }
14 |
15 | //constructor
16 | public FileMeta(string mFileName, string mFilePath, long mFileSize)
17 | {
18 | this.FileName = mFileName;
19 | this.FilePath = mFilePath;
20 | this.FileSize = mFileSize;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/P2PNET.Test/Pet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 | public enum AnimalType
10 | {
11 | Dog = 0,
12 | Cat = 1,
13 | Fish = 2
14 | }
15 | public class Pet
16 | {
17 | public AnimalType Type { get; set; }
18 | public string Name { get; set; }
19 |
20 | public Pet(string petName)
21 | {
22 | this.Name = petName;
23 | }
24 |
25 | public bool Equals(Pet pet)
26 | {
27 | if(pet.Name == this.Name && pet.Type == this.Type)
28 | {
29 | return true;
30 | }
31 | return false;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/SendableObjects/FileAck.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.FileLayer.SendableObjects
8 | {
9 | public class FileAck
10 | {
11 | //set true to let sender know to keep sending the
12 | //file parts
13 | public bool AcceptedFile { get; set; }
14 | public string FileName { get; set; }
15 | public string FilePath { get; set; }
16 |
17 | public FileAck(FilePartObj filePart, bool acceptFutureParts = true)
18 | {
19 | this.AcceptedFile = acceptFutureParts;
20 | this.FileName = filePart.FileMetadata.FileName;
21 | this.FilePath = filePart.FileMetadata.FilePath;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Pet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ObjectSender
8 | {
9 | public enum AnimalType
10 | {
11 | Dog = 0,
12 | Cat = 1,
13 | Fish = 2
14 | }
15 | public class Pet
16 | {
17 | public AnimalType Type { get; set; }
18 | public string Name { get; set; }
19 |
20 | public Pet(string petName)
21 | {
22 | this.Name = petName;
23 | }
24 |
25 | public bool Equals(Pet pet)
26 | {
27 | if(pet.Name == this.Name && pet.Type == this.Type)
28 | {
29 | return true;
30 | }
31 | return false;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/SendableObjects/FileReqMeta.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.FileLayer.SendableObjects
8 | {
9 | public class FileReqMeta
10 | {
11 | //data the receiver can use to decide whether or not to reject the request
12 | public List Files { get; set; }
13 | public int BufferSize { get; set; }
14 |
15 | //identification data
16 | public string SenderIpAddress { get; set; }
17 |
18 | public FileReqMeta(List mFiles, int mBufferSize, string mSenderIpAddress)
19 | {
20 | this.Files = mFiles;
21 | this.BufferSize = mBufferSize;
22 | this.SenderIpAddress = mSenderIpAddress;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/P2PNET/P2PNET.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SquidInc.P2PNET
5 | $version$
6 | $title$
7 | Clinton Page
8 | en-US
9 | Clinton Page
10 | https://github.com/BlueSquid1/P2PNET
11 | https://github.com/BlueSquid1/P2PNET/blob/master/LICENSE
12 | false
13 | P2PNET is a low level portable peer to peer library written in C# with an emphasises on being simple to use
14 | Further stability updates
15 | Copyright 2017
16 | P2P NET peer2peer peer network networking symetric .net P2PNET sockets tcp udp xamarin windows phone wp8 winrt uwp android xamarin.forms asp.net ios
17 |
18 |
--------------------------------------------------------------------------------
/P2PNET/TransportLayer/AbstractStreamUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace P2PNET.TransportLayer
9 | {
10 | class AbstractStreamUtil
11 | {
12 | public Stream ActiveStream { get; set; }
13 |
14 | //constructor
15 | public AbstractStreamUtil(Stream inputStream)
16 | {
17 | this.ActiveStream = inputStream;
18 | }
19 |
20 | protected byte[] IntToBinary(int value)
21 | {
22 | byte[] valueBin = BitConverter.GetBytes(value);
23 | if (BitConverter.IsLittleEndian)
24 | {
25 | Array.Reverse(valueBin);
26 | }
27 | return valueBin;
28 | }
29 |
30 | protected int BinaryToInt(byte[] binArray)
31 | {
32 | if (BitConverter.IsLittleEndian)
33 | {
34 | Array.Reverse(binArray);
35 | }
36 | return BitConverter.ToInt32(binArray, 0);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 CrazySquid1
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/SendableObjects/FilePartObj.cs:
--------------------------------------------------------------------------------
1 | using PCLStorage;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Runtime.Serialization;
8 |
9 | namespace P2PNET.FileLayer.SendableObjects
10 | {
11 | //file objects are sent between peers
12 | //for that reason they must be seralizable
13 | //contains enough information so that both sender and
14 | //receiver's are stateless
15 | public class FilePartObj
16 | {
17 | //identification
18 | public FileMeta FileMetadata { get; set; }
19 |
20 | //data
21 | public byte[] FileData { get; set; }
22 |
23 |
24 | public int FilePartNum { get; set; }
25 | public int TotalPartNum { get; set; }
26 |
27 |
28 | public FilePartObj(FileMeta mMetadata, byte[] mFileData, int mFilePartNum, int TotalPartNum)
29 | {
30 | this.FileMetadata = mMetadata;
31 | this.FileData = mFileData;
32 | this.FilePartNum = mFilePartNum;
33 | this.TotalPartNum = TotalPartNum;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/EventArgs/FileTransferEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.FileLayer.EventArgs
8 | {
9 | public enum TransDirrection
10 | {
11 | sending,
12 | receiving
13 | }
14 | public class FileTransferEventArgs : System.EventArgs
15 | {
16 | public TransDirrection Dirrection { get; }
17 | public string FileName { get; }
18 | public long FileLength { get; }
19 | public long BytesProcessed { get; }
20 | public float Percent
21 | {
22 | get
23 | {
24 | return (float)BytesProcessed / FileLength;
25 | }
26 | }
27 |
28 | //constructor
29 | public FileTransferEventArgs(FileTransReq fileTrans, TransDirrection mDir)
30 | {
31 | this.FileLength = fileTrans.FileDetails.FileSize;
32 | this.BytesProcessed = fileTrans.BytesProcessed;
33 | this.FileName = fileTrans.FileDetails.FileName;
34 | this.Dirrection = mDir;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/P2PNET.Test/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace P2PNET.Test.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WorkSpace.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageSender/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace MessageSender.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageProgram/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace BroadcastProgram.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace P2PNET.Test
8 | {
9 |
10 | public class FavNum
11 | {
12 | public int number { get; set; }
13 | }
14 |
15 | public class Person
16 | {
17 | public string FirstName { get; set; }
18 | public string LastName { get; set; }
19 |
20 | public int Age { get; set; }
21 |
22 | //public List favNums { get; set; }
23 | public List OwnedPets { get; set; }
24 |
25 | public Person(string firstName, string lastName, int age)
26 | {
27 | //this.favNums = new List();
28 | this.FirstName = firstName;
29 | this.LastName = lastName;
30 | this.Age = age;
31 |
32 | OwnedPets = new List();
33 | }
34 |
35 | /*
36 | public void AddNum(FavNum favNum)
37 | {
38 | favNums.Add(favNum);
39 | }
40 | */
41 |
42 | public void AddPet(Pet newPet)
43 | {
44 | OwnedPets.Add(newPet);
45 | }
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/HeartBeatManager.cs:
--------------------------------------------------------------------------------
1 | using P2PNET.TransportLayer;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows.Forms;
8 |
9 | namespace AutoDiscovery
10 | {
11 | class HeartBeatManager
12 | {
13 | private string heartBeatMsg;
14 | private TransportManager transMgr;
15 | private Timer hrtBtTimer;
16 |
17 | //constructor
18 | public HeartBeatManager(string mHeartBeatMsg, TransportManager mTransMgr)
19 | {
20 | this.heartBeatMsg = mHeartBeatMsg;
21 | this.transMgr = mTransMgr;
22 | this.hrtBtTimer = new Timer();
23 | }
24 |
25 | public void StartBroadcasting()
26 | {
27 | byte[] msgBin = Encoding.ASCII.GetBytes(heartBeatMsg);
28 |
29 | hrtBtTimer.Tick += async (object sender, EventArgs e) =>
30 | {
31 | await this.transMgr.SendBroadcastAsyncUDP(msgBin);
32 | Console.WriteLine("sent heartbeat");
33 | };
34 | hrtBtTimer.Interval = 1000;
35 | hrtBtTimer.Start();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ObjectSender.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/P2PNET/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Resources;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("P2PNET")]
10 | [assembly: AssemblyDescription("Peer-To-Peer network library")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("Clinton Page")]
13 | [assembly: AssemblyProduct("P2PNET")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en")]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Build and Revision Numbers
27 | // by using the '*' as shown below:
28 | // [assembly: AssemblyVersion("1.0.*")]
29 | [assembly: AssemblyVersion("1.5.0.0")]
30 | [assembly: AssemblyFileVersion("1.0.0.0")]
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace AutoDiscovery.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 | using P2PNET.TransportLayer;
11 |
12 | namespace AutoDiscovery
13 | {
14 | public partial class Form1 : Form
15 | {
16 | private TransportManager transMgr;
17 | private int portNum = 8080;
18 | private HeartBeatManager hrtBtMgr;
19 |
20 | public Form1()
21 | {
22 | transMgr = new TransportManager(portNum, true);
23 | hrtBtMgr = new HeartBeatManager("heartbeat", transMgr);
24 |
25 | InitializeComponent();
26 | }
27 |
28 | private async void Form1_Load(object sender, EventArgs e)
29 | {
30 | transMgr.PeerChange += TransMgr_PeerChange;
31 | await transMgr.StartAsync();
32 | hrtBtMgr.StartBroadcasting();
33 | }
34 |
35 | private void TransMgr_PeerChange(object sender, P2PNET.TransportLayer.EventArgs.PeerChangeEventArgs e)
36 | {
37 | peerListView.Items.Clear();
38 | foreach(Peer peer in e.Peers)
39 | {
40 | string[] peerDtl = {
41 | peer.IpAddress
42 | };
43 | ListViewItem item = new ListViewItem(peerDtl);
44 | peerListView.Items.Add(item);
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Samples/WorkSpace/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Test")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1d621566-6326-4298-90cd-9dd0c310ed25")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/P2PNET.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("P2PNET.Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("P2PNET.Test")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("067456c0-086c-46a8-b37f-1405717b7bfc")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/ObjectSamples/ObjectSender/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ObjectSender")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ObjectSender")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("dec94d14-4588-4558-93d2-ca04cff85799")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageSender/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SendObjects")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SendObjects")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("6464da1f-347c-4f10-ba92-e1e441b7aaa7")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/AutoDiscovery/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("AutoDiscovery")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("AutoDiscovery")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c6fb1278-f3c4-49f3-9838-e449dab2f4b5")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Samples/TransportSamples/MessageProgram/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MessageProgram")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("MessageProgram")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("d415dd7f-5517-46cb-898b-95387248f33d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/P2PNET/TransportLayer/ReadStreamUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace P2PNET.TransportLayer
9 | {
10 | class ReadStreamUtil : AbstractStreamUtil
11 | {
12 | //constructor
13 | public ReadStreamUtil(Stream mReadStream) : base(mReadStream)
14 | {
15 |
16 | }
17 |
18 | public async Task ReadBytesAsync()
19 | {
20 | //read the first 4 bytes = sizeof(int)
21 | const int intSize = sizeof(int);
22 | Byte[] lengthBin = await ReadBytesAsync(intSize);
23 | int msgSize = BinaryToInt(lengthBin);
24 |
25 | //read message
26 | byte[] messageBin = await ReadBytesAsync(msgSize);
27 | return messageBin;
28 | }
29 |
30 | private async Task ReadBytesAsync(int bytesToRead)
31 | {
32 | Byte[] msgBin = new Byte[bytesToRead];
33 | int totalBytesRd = 0;
34 | while (totalBytesRd < bytesToRead)
35 | {
36 | //ReadAsync() can return less then intSize therefore keep on looping until intSize is reached
37 | byte[] tempMsgBin = new Byte[bytesToRead];
38 | int bytesRead = await base.ActiveStream.ReadAsync(tempMsgBin, 0, bytesToRead - totalBytesRd);
39 | Array.Copy(tempMsgBin, 0, msgBin, totalBytesRd, bytesRead);
40 | totalBytesRd += bytesRead;
41 | }
42 | return msgBin;
43 | }
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/P2PNET/ObjectLayer/BObject.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json.Linq;
2 | using P2PNET.ObjectLayer;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace P2PNET.ObjectLayer
10 | {
11 | public class BObject
12 | {
13 | private byte[] msgBin;
14 | private Serializer serializer;
15 |
16 | //constructor
17 | public BObject(byte[] msg, Serializer mSerializer)
18 | {
19 | this.msgBin = msg;
20 | this.serializer = mSerializer;
21 | }
22 |
23 | //overwrite the GetType method
24 | public new string GetType()
25 | {
26 | string jsonMsg = Encoding.Unicode.GetString(msgBin, 0, msgBin.Length);
27 | JObject jObject = JObject.Parse(jsonMsg);
28 | JToken jToken = jObject["Metadata"];
29 | JToken jObjeType = jToken.SelectToken("ObjectType");
30 | return jObjeType.Value();
31 | }
32 |
33 | public Metadata GetMetadata()
34 | {
35 | ObjPackage