├── .gitignore
├── LICENSE
├── P2PNET.Test
├── Cat.cs
├── Dog.cs
├── FilePart.cs
├── Fish.cs
├── ObjectTests.cs
├── P2PNET.Test.csproj
├── Person.cs
├── Pet.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── TransportTests.cs
├── app.config
└── packages.config
├── P2PNET.sln
├── P2PNET
├── Exceptions.cs
├── FileLayer
│ ├── EventArgs
│ │ ├── DebugInfoEventArgs.cs
│ │ ├── FileReceivedEventArgs.cs
│ │ └── FileTransferEventArgs.cs
│ ├── FileManager.cs
│ ├── FileReceivedReq.cs
│ ├── FileSentReq.cs
│ ├── FileTransReq.cs
│ └── SendableObjects
│ │ ├── FileAck.cs
│ │ ├── FileMeta.cs
│ │ ├── FilePartObj.cs
│ │ ├── FileReqMeta.cs
│ │ └── ReqAck.cs
├── ILogger.cs
├── ObjectLayer
│ ├── BObject.cs
│ ├── EventArgs
│ │ └── ObjReceivedEventArgs.cs
│ ├── Metadata.cs
│ ├── ObjPackage.cs
│ ├── ObjectManager.cs
│ └── Serializer.cs
├── P2PNET.csproj
├── P2PNET.nuspec
├── Properties
│ └── AssemblyInfo.cs
├── TransportLayer
│ ├── AbstractStreamUtil.cs
│ ├── BaseStation.cs
│ ├── BufferedUDPStream.cs
│ ├── EventArgs
│ │ ├── MsgReceivedEventArgs.cs
│ │ ├── PeerChangeEventArgs.cs
│ │ └── PeerEventArgs.cs
│ ├── Listener.cs
│ ├── Peer.cs
│ ├── ReadStreamUtil.cs
│ ├── TransportManager.cs
│ ├── TransportType.cs
│ └── WriteStreamUtil.cs
└── packages.config
├── README.md
└── Samples
├── ObjectSamples
└── ObjectSender
│ ├── App.config
│ ├── Cat.cs
│ ├── Dog.cs
│ ├── Fish.cs
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── ObjectSender.csproj
│ ├── Person.cs
│ ├── Pet.cs
│ ├── Program.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ └── packages.config
├── TransportSamples
├── AutoDiscovery
│ ├── App.config
│ ├── AutoDiscovery.csproj
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── HeartBeatManager.cs
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── packages.config
├── MessageProgram
│ ├── App.config
│ ├── BroadcastProgram.csproj
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ └── packages.config
└── MessageSender
│ ├── App.config
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── MessageSender.csproj
│ ├── Program.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ └── packages.config
└── WorkSpace
├── App.config
├── Cat.cs
├── Dog.cs
├── Fish.cs
├── Form1.Designer.cs
├── Form1.cs
├── Form1.resx
├── Person.cs
├── Pet.cs
├── Program.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── WorkSpace.csproj
└── packages.config
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
--------------------------------------------------------------------------------
/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.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/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.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 |
--------------------------------------------------------------------------------
/P2PNET.Test/P2PNET.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {067456C0-086C-46A8-B37F-1405717B7BFC}
7 | Library
8 | Properties
9 | P2PNET.Test
10 | P2PNET.Test
11 | v4.5.2
12 | 512
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 | true
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
36 | True
37 |
38 |
39 | ..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll
40 | True
41 |
42 |
43 | ..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll
44 | True
45 |
46 |
47 | ..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll
48 | True
49 |
50 |
51 | ..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.dll
52 | True
53 |
54 |
55 | ..\packages\rda.SocketsForPCL.2.0.2\lib\net45\Sockets.Plugin.Abstractions.dll
56 | True
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | True
69 | True
70 | Settings.settings
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | SettingsSingleFileGenerator
81 | Settings.Designer.cs
82 |
83 |
84 |
85 |
86 | {196653e2-638f-4590-82e6-79387f5b2fb9}
87 | P2PNET
88 |
89 |
90 |
91 |
98 |
--------------------------------------------------------------------------------
/P2PNET.Test/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 | public class Person : Object
10 | {
11 | public string FirstName { get; set; }
12 | public string LastName { get; set; }
13 |
14 | public int Age { get; set; }
15 |
16 | public List OwnedPets { get; set; }
17 |
18 | public Person(string firstName, string lastName, int age)
19 | {
20 | this.FirstName = firstName;
21 | this.LastName = lastName;
22 | this.Age = age;
23 |
24 | OwnedPets = new List();
25 | }
26 |
27 | public void AddPet(Pet newPet)
28 | {
29 | OwnedPets.Add(newPet);
30 | }
31 |
32 | public bool Equals(Person secPerson)
33 | {
34 | if(secPerson == null)
35 | {
36 | Console.WriteLine("person is null");
37 | return false;
38 | }
39 | if(secPerson.OwnedPets.Count != this.OwnedPets.Count)
40 | {
41 | Console.WriteLine("num of pets different");
42 | return false;
43 | }
44 |
45 |
46 | for(int i = 0; i < OwnedPets.Count; i++)
47 | {
48 | if(!this.OwnedPets[i].Equals(secPerson.OwnedPets[i]))
49 | {
50 | Console.WriteLine("pet have different values");
51 | return false;
52 | }
53 | }
54 |
55 | if(secPerson.Age != this.Age || secPerson.FirstName != this.FirstName || secPerson.LastName != this.LastName)
56 | {
57 | Console.WriteLine("people have different values");
58 | return false;
59 | }
60 |
61 | return true;
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/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.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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/P2PNET.Test/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/P2PNET.Test/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/P2PNET.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/P2PNET.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P2PNET", "P2PNET\P2PNET.csproj", "{196653E2-638F-4590-82E6-79387F5B2FB9}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{AF8CE42B-D862-4FE8-8D10-2BC1985F4224}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TransportSamples", "TransportSamples", "{5B3B5569-0CC6-4AFA-9AD0-2944912203E2}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ObjectSamples", "ObjectSamples", "{910C45DF-8B68-4660-B1A7-24FF59B497FA}"
13 | EndProject
14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P2PNET.Test", "P2PNET.Test\P2PNET.Test.csproj", "{067456C0-086C-46A8-B37F-1405717B7BFC}"
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObjectSender", "Samples\ObjectSamples\ObjectSender\ObjectSender.csproj", "{DEC94D14-4588-4558-93D2-CA04CFF85799}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoDiscovery", "Samples\TransportSamples\AutoDiscovery\AutoDiscovery.csproj", "{C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}"
19 | EndProject
20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BroadcastProgram", "Samples\TransportSamples\MessageProgram\BroadcastProgram.csproj", "{D415DD7F-5517-46CB-898B-95387248F33D}"
21 | EndProject
22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessageSender", "Samples\TransportSamples\MessageSender\MessageSender.csproj", "{6464DA1F-347C-4F10-BA92-E1E441B7AAA7}"
23 | EndProject
24 | Global
25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
26 | Debug|Any CPU = Debug|Any CPU
27 | Release|Any CPU = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
30 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {196653E2-638F-4590-82E6-79387F5B2FB9}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {067456C0-086C-46A8-B37F-1405717B7BFC}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {DEC94D14-4588-4558-93D2-CA04CFF85799}.Release|Any CPU.Build.0 = Release|Any CPU
42 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
44 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
45 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5}.Release|Any CPU.Build.0 = Release|Any CPU
46 | {D415DD7F-5517-46CB-898B-95387248F33D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 | {D415DD7F-5517-46CB-898B-95387248F33D}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 | {D415DD7F-5517-46CB-898B-95387248F33D}.Release|Any CPU.ActiveCfg = Release|Any CPU
49 | {D415DD7F-5517-46CB-898B-95387248F33D}.Release|Any CPU.Build.0 = Release|Any CPU
50 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
52 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
53 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7}.Release|Any CPU.Build.0 = Release|Any CPU
54 | EndGlobalSection
55 | GlobalSection(SolutionProperties) = preSolution
56 | HideSolutionNode = FALSE
57 | EndGlobalSection
58 | GlobalSection(NestedProjects) = preSolution
59 | {5B3B5569-0CC6-4AFA-9AD0-2944912203E2} = {AF8CE42B-D862-4FE8-8D10-2BC1985F4224}
60 | {910C45DF-8B68-4660-B1A7-24FF59B497FA} = {AF8CE42B-D862-4FE8-8D10-2BC1985F4224}
61 | {DEC94D14-4588-4558-93D2-CA04CFF85799} = {910C45DF-8B68-4660-B1A7-24FF59B497FA}
62 | {C6FB1278-F3C4-49F3-9838-E449DAB2F4B5} = {5B3B5569-0CC6-4AFA-9AD0-2944912203E2}
63 | {D415DD7F-5517-46CB-898B-95387248F33D} = {5B3B5569-0CC6-4AFA-9AD0-2944912203E2}
64 | {6464DA1F-347C-4F10-BA92-E1E441B7AAA7} = {5B3B5569-0CC6-4AFA-9AD0-2944912203E2}
65 | EndGlobalSection
66 | EndGlobal
67 |
--------------------------------------------------------------------------------
/P2PNET/Exceptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace P2PNET
4 | {
5 | public class PeerNotKnown : Exception
6 | {
7 | public PeerNotKnown(string message) : base(message)
8 | {
9 | }
10 | }
11 | public class StreamCannotWrite : Exception
12 | {
13 | public StreamCannotWrite(string message) : base(message)
14 | {
15 |
16 | }
17 | }
18 |
19 | public class NoNetworkInterface : Exception
20 | {
21 | public NoNetworkInterface(string message) : base(message)
22 | {
23 |
24 | }
25 | }
26 |
27 | public class FileNotFound: Exception
28 | {
29 | public FileNotFound(string message) : base(message)
30 | {
31 |
32 | }
33 | }
34 |
35 | public class FileTransitionError : Exception
36 | {
37 | public FileTransitionError(string message) : base(message)
38 | {
39 |
40 | }
41 | }
42 |
43 | public class LowLevelTransitionError : Exception
44 | {
45 | public LowLevelTransitionError(string message) : base(message)
46 | {
47 |
48 | }
49 | }
50 |
51 | public class FileBoundaryException : Exception
52 | {
53 | public FileBoundaryException(string message) : base(message)
54 | {
55 |
56 | }
57 | }
58 |
59 | public class InvalidMessage : Exception
60 | {
61 | public InvalidMessage(string message) : base(message)
62 | {
63 |
64 | }
65 | }
66 |
67 | public class DeserializingException : Exception
68 | {
69 | public DeserializingException(string message) : base(message)
70 | {
71 |
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/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/FileLayer/FileReceivedReq.cs:
--------------------------------------------------------------------------------
1 | using P2PNET.FileLayer.SendableObjects;
2 | using PCLStorage;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace P2PNET.FileLayer
11 | {
12 | public class FileReceiveReq
13 | {
14 | //for identification FileReceiveReq
15 | public string SenderIpAddress { get; }
16 |
17 | private List fileTransReqs;
18 |
19 |
20 | //constructor
21 | public FileReceiveReq(List mFileTransReqs, string mIpAddress)
22 | {
23 | this.fileTransReqs = mFileTransReqs;
24 | this.SenderIpAddress = mIpAddress;
25 | }
26 |
27 |
28 | public async Task WriteFilePartToFile(FilePartObj receivedFilePart)
29 | {
30 | FileTransReq fileTrans = GetFileTransReqFromFileMeta(receivedFilePart.FileMetadata);
31 |
32 | //validate packet recieved
33 | bool isValid = ValidFilePart(receivedFilePart);
34 | if(!isValid)
35 | {
36 | throw new FileTransitionError("file part received is not valided for this peer.");
37 | }
38 |
39 | //valid file part
40 | byte[] buffer = receivedFilePart.FileData;
41 | await fileTrans.WriteBytes(buffer);
42 | }
43 |
44 | public FileTransReq GetFileTransReqFromFileMeta(FileMeta mFileMeta)
45 | {
46 | //collect info to identify file transfer object
47 | string fileName = mFileMeta.FileName;
48 | string filePath = mFileMeta.FilePath;
49 | foreach(FileTransReq fileTrans in fileTransReqs)
50 | {
51 | if(fileTrans.FileDetails.FileName == fileName && fileTrans.FileDetails.FilePath == filePath)
52 | {
53 | return fileTrans;
54 | }
55 |
56 | }
57 |
58 | //can't find file transfer object
59 | return null;
60 | }
61 |
62 | private bool ValidFilePart(FilePartObj filePart)
63 | {
64 | if(filePart == null)
65 | {
66 | return false;
67 | }
68 |
69 | //TODO
70 | return true;
71 | }
72 |
73 | public async Task CloseRequest()
74 | {
75 | foreach (FileTransReq fileTrans in fileTransReqs)
76 | {
77 | await fileTrans.CloseFileStream();
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/FileSentReq.cs:
--------------------------------------------------------------------------------
1 | using P2PNET.FileLayer.EventArgs;
2 | using P2PNET.FileLayer.SendableObjects;
3 | using P2PNET.ObjectLayer;
4 | using PCLStorage;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace P2PNET.FileLayer
13 | {
14 | public class FileSentReq
15 | {
16 | //for identification FileSentReq
17 | public string targetIpAddress { get; }
18 |
19 | public List FileTransReqs { get; }
20 | private int bufferSize;
21 |
22 | //constructor
23 | public FileSentReq(List mFileTransReqs, int mBufferSize, string mIpAddress)
24 | {
25 | this.bufferSize = mBufferSize;
26 | this.FileTransReqs = mFileTransReqs;
27 | this.targetIpAddress = mIpAddress;
28 | }
29 |
30 |
31 | public FileReqMeta GenerateMetadataRequest()
32 | {
33 | //collect details from all fileTransRequests
34 | List fileDetails = new List();
35 | foreach(FileTransReq fileTransReq in FileTransReqs)
36 | {
37 | fileDetails.Add(fileTransReq.FileDetails);
38 | }
39 | FileReqMeta fileSendMetadata = new FileReqMeta(fileDetails, bufferSize, targetIpAddress);
40 | return fileSendMetadata;
41 | }
42 |
43 | public bool FileHasMoreParts(FileTransReq fileTrans)
44 | {
45 | if(fileTrans.curFilePartNum < fileTrans.TotalPartNum)
46 | {
47 | return true;
48 | }
49 | else
50 | {
51 | return false;
52 | }
53 | }
54 |
55 | public async Task GetNextFilePart(FileTransReq mCurFileTrans)
56 | {
57 | //set buffer lengths
58 | int bufferLen = (int)Math.Min(mCurFileTrans.FileDetails.FileSize - mCurFileTrans.BytesProcessed, this.bufferSize);
59 | if(bufferLen <= 0)
60 | {
61 | //nothing more to be sent
62 | return null;
63 | }
64 | FileMeta fileMetadata = mCurFileTrans.FileDetails;
65 | byte[] fileData = await mCurFileTrans.ReadBytes(bufferLen);
66 |
67 |
68 | //populate File part object
69 | FilePartObj filePart = new FilePartObj(fileMetadata, fileData, mCurFileTrans.curFilePartNum, mCurFileTrans.TotalPartNum);
70 |
71 | return filePart;
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/P2PNET/FileLayer/FileTransReq.cs:
--------------------------------------------------------------------------------
1 | using P2PNET.FileLayer.SendableObjects;
2 | using PCLStorage;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace P2PNET.FileLayer
11 | {
12 | public class FileTransReq
13 | {
14 | //file details
15 | public FileMeta FileDetails { get; }
16 |
17 | public int curFilePartNum
18 | {
19 | get
20 | {
21 | return (int)Math.Ceiling((float)BytesProcessed / bufferSize);
22 | }
23 | }
24 | public int TotalPartNum
25 | {
26 | get
27 | {
28 | return (int)Math.Ceiling((float)FileDetails.FileSize / bufferSize);
29 | }
30 | }
31 |
32 | //transmittion details
33 | public long BytesProcessed
34 | {
35 | get
36 | {
37 | return bytesProccessed;
38 | }
39 | }
40 | private long bytesProccessed;
41 |
42 | //buffer size is only for file parts calculations
43 | private int bufferSize;
44 |
45 | private Stream fileDataStream;
46 |
47 | //constructor
48 | public FileTransReq(IFile mFileDetails, Stream mFileStream, int mBufferSize)
49 | {
50 | this.FileDetails = new FileMeta(mFileDetails.Name, mFileDetails.Path, mFileStream.Length);
51 | this.bufferSize = mBufferSize;
52 | this.bytesProccessed = 0;
53 | this.fileDataStream = mFileStream;
54 | }
55 |
56 | //constructor
57 | public FileTransReq(FileMeta fileDetails, Stream mFileStream, int mBufferSize)
58 | {
59 | this.FileDetails = new FileMeta(fileDetails.FileName, fileDetails.FilePath, fileDetails.FileSize);
60 | this.bufferSize = mBufferSize;
61 | this.bytesProccessed = 0;
62 | this.fileDataStream = mFileStream;
63 | }
64 |
65 | //deconstructor
66 |
67 | public async Task ReadBytes(int numOfBytes)
68 | {
69 | byte[] fileData = new byte[numOfBytes];
70 |
71 | await this.fileDataStream.ReadAsync(fileData, 0, numOfBytes);
72 |
73 | this.bytesProccessed += numOfBytes;
74 |
75 | return fileData;
76 | }
77 |
78 | public async Task WriteBytes(byte[] data)
79 | {
80 | await this.fileDataStream.WriteAsync(data, 0, data.Length);
81 | this.bytesProccessed += data.Length;
82 | }
83 |
84 | public async Task CloseFileStream()
85 | {
86 | await this.fileDataStream.FlushAsync();
87 | this.fileDataStream.Dispose();
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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 |
--------------------------------------------------------------------------------
/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