├── .gitattributes
├── .github
└── workflows
│ ├── generated-pr.yml
│ └── stale.yml
├── .gitignore
├── .travis.yml
├── LICENSE
├── LibP2P.Peer.sln
├── NuGet.config
├── README.md
├── appveyor.yml
├── build.sh
├── src
└── LibP2P.Peer
│ ├── LibP2P.Peer.csproj
│ └── PeerId.cs
└── test
└── LibP2P.Peer.Tests
├── LibP2P.Peer.Tests.csproj
└── PeerIdTests.cs
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/workflows/generated-pr.yml:
--------------------------------------------------------------------------------
1 | name: Close Generated PRs
2 |
3 | on:
4 | schedule:
5 | - cron: '0 0 * * *'
6 | workflow_dispatch:
7 |
8 | permissions:
9 | issues: write
10 | pull-requests: write
11 |
12 | jobs:
13 | stale:
14 | uses: ipdxco/unified-github-workflows/.github/workflows/reusable-generated-pr.yml@v1
15 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | name: Close Stale Issues
2 |
3 | on:
4 | schedule:
5 | - cron: '0 0 * * *'
6 | workflow_dispatch:
7 |
8 | permissions:
9 | issues: write
10 | pull-requests: write
11 |
12 | jobs:
13 | stale:
14 | uses: ipdxco/unified-github-workflows/.github/workflows/reusable-stale-issue.yml@v1
15 |
--------------------------------------------------------------------------------
/.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 | [Xx]64/
19 | [Xx]86/
20 | [Bb]uild/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
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 |
85 | # Visual Studio profiler
86 | *.psess
87 | *.vsp
88 | *.vspx
89 | *.sap
90 |
91 | # TFS 2012 Local Workspace
92 | $tf/
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 | *.DotSettings.user
101 |
102 | # JustCode is a .NET coding add-in
103 | .JustCode
104 |
105 | # TeamCity is a build add-in
106 | _TeamCity*
107 |
108 | # DotCover is a Code Coverage Tool
109 | *.dotCover
110 |
111 | # NCrunch
112 | _NCrunch_*
113 | .*crunch*.local.xml
114 | nCrunchTemp_*
115 |
116 | # MightyMoose
117 | *.mm.*
118 | AutoTest.Net/
119 |
120 | # Web workbench (sass)
121 | .sass-cache/
122 |
123 | # Installshield output folder
124 | [Ee]xpress/
125 |
126 | # DocProject is a documentation generator add-in
127 | DocProject/buildhelp/
128 | DocProject/Help/*.HxT
129 | DocProject/Help/*.HxC
130 | DocProject/Help/*.hhc
131 | DocProject/Help/*.hhk
132 | DocProject/Help/*.hhp
133 | DocProject/Help/Html2
134 | DocProject/Help/html
135 |
136 | # Click-Once directory
137 | publish/
138 |
139 | # Publish Web Output
140 | *.[Pp]ublish.xml
141 | *.azurePubxml
142 |
143 | # TODO: Un-comment the next line if you do not want to checkin
144 | # your web deploy settings because they may include unencrypted
145 | # passwords
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # NuGet Packages
150 | *.nupkg
151 | # The packages folder can be ignored because of Package Restore
152 | **/packages/*
153 | # except build/, which is used as an MSBuild target.
154 | !**/packages/build/
155 | # Uncomment if necessary however generally it will be regenerated when needed
156 | #!**/packages/repositories.config
157 | # NuGet v3's project.json files produces more ignoreable files
158 | *.nuget.props
159 | *.nuget.targets
160 |
161 | # Microsoft Azure Build Output
162 | csx/
163 | *.build.csdef
164 |
165 | # Microsoft Azure Emulator
166 | ecf/
167 | rcf/
168 |
169 | # Windows Store app package directory
170 | AppPackages/
171 | BundleArtifacts/
172 |
173 | # Visual Studio cache files
174 | # files ending in .cache can be ignored
175 | *.[Cc]ache
176 | # but keep track of directories ending in .cache
177 | !*.[Cc]ache/
178 |
179 | # Others
180 | ClientBin/
181 | [Ss]tyle[Cc]op.*
182 | ~$*
183 | *~
184 | *.dbmdl
185 | *.dbproj.schemaview
186 | *.pfx
187 | *.publishsettings
188 | node_modules/
189 | orleans.codegen.cs
190 |
191 | # RIA/Silverlight projects
192 | Generated_Code/
193 |
194 | # Backup & report files from converting an old project file
195 | # to a newer Visual Studio version. Backup files are not needed,
196 | # because we have git ;-)
197 | _UpgradeReport_Files/
198 | Backup*/
199 | UpgradeLog*.XML
200 | UpgradeLog*.htm
201 |
202 | # SQL Server files
203 | *.mdf
204 | *.ldf
205 |
206 | # Business Intelligence projects
207 | *.rdl.data
208 | *.bim.layout
209 | *.bim_*.settings
210 |
211 | # Microsoft Fakes
212 | FakesAssemblies/
213 |
214 | # GhostDoc plugin setting file
215 | *.GhostDoc.xml
216 |
217 | # Node.js Tools for Visual Studio
218 | .ntvs_analysis.dat
219 |
220 | # Visual Studio 6 build log
221 | *.plg
222 |
223 | # Visual Studio 6 workspace options file
224 | *.opt
225 |
226 | # Visual Studio LightSwitch build output
227 | **/*.HTMLClient/GeneratedArtifacts
228 | **/*.DesktopClient/GeneratedArtifacts
229 | **/*.DesktopClient/ModelManifest.xml
230 | **/*.Server/GeneratedArtifacts
231 | **/*.Server/ModelManifest.xml
232 | _Pvt_Extensions
233 |
234 | # LightSwitch generated files
235 | GeneratedArtifacts/
236 | ModelManifest.xml
237 |
238 | # Paket dependency manager
239 | .paket/paket.exe
240 |
241 | # FAKE - F# Make
242 | .fake/
243 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: csharp
2 | sudo: required
3 | dist: trusty
4 | env:
5 | - CLI_VERSION=latest
6 |
7 | addons:
8 | apt:
9 | packages:
10 | - gettext
11 | - libcurl4-openssl-dev
12 | - libicu-dev
13 | - libssl-dev
14 | - libunwind8
15 | - zlib1g
16 | mono:
17 | - latest
18 | os:
19 | - linux
20 | - osx
21 |
22 | notifications:
23 | email:
24 | on_success: change
25 | on_failure: always
26 |
27 | branches:
28 | only:
29 | - master
30 |
31 | cache:
32 | bundler: true
33 | directories:
34 | - ./packages
35 | - /.dotnetcli
36 | - $HOME/Library/Caches/Homebrew
37 |
38 | before_install:
39 | - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi
40 |
41 | install:
42 | - export DOTNET_INSTALL_DIR="$PWD/.dotnetcli"
43 | - export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
44 | - export DOTNET_CLI_TELEMETRY_OPTOUT=1
45 | - curl -sSL https://raw.githubusercontent.com/dotnet/cli/rel/1.0.1/scripts/obtain/dotnet-install.sh | bash /dev/stdin --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR"
46 | - git config --global core.autocrlf input
47 | - chmod +x ./build.sh
48 | - export PATH="$DOTNET_INSTALL_DIR:$PATH"
49 |
50 | script:
51 | - ./build.sh
52 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libp2p/cs-libp2p-peer/6b54c5c82fd5003e5ec7a0798cebb3116b4d318e/LICENSE
--------------------------------------------------------------------------------
/LibP2P.Peer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26124.0
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5073FB14-219B-42B2-8D2F-5FB700D7BA64}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibP2P.Peer", "src\LibP2P.Peer\LibP2P.Peer.csproj", "{537C6DEB-7D45-474E-A557-63E1D1CA3429}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6DD31636-6472-4054-B85E-BAAE9AE5FF38}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibP2P.Peer.Tests", "test\LibP2P.Peer.Tests\LibP2P.Peer.Tests.csproj", "{680E076A-C3EA-4F2C-921B-2C8C5A25979B}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Debug|x64 = Debug|x64
18 | Debug|x86 = Debug|x86
19 | Release|Any CPU = Release|Any CPU
20 | Release|x64 = Release|x64
21 | Release|x86 = Release|x86
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
27 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Debug|x64.ActiveCfg = Debug|x64
30 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Debug|x64.Build.0 = Debug|x64
31 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Debug|x86.ActiveCfg = Debug|x86
32 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Debug|x86.Build.0 = Debug|x86
33 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Release|Any CPU.Build.0 = Release|Any CPU
35 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Release|x64.ActiveCfg = Release|x64
36 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Release|x64.Build.0 = Release|x64
37 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Release|x86.ActiveCfg = Release|x86
38 | {537C6DEB-7D45-474E-A557-63E1D1CA3429}.Release|x86.Build.0 = Release|x86
39 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Debug|Any CPU.Build.0 = Debug|Any CPU
41 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Debug|x64.ActiveCfg = Debug|x64
42 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Debug|x64.Build.0 = Debug|x64
43 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Debug|x86.ActiveCfg = Debug|x86
44 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Debug|x86.Build.0 = Debug|x86
45 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Release|Any CPU.ActiveCfg = Release|Any CPU
46 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Release|Any CPU.Build.0 = Release|Any CPU
47 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Release|x64.ActiveCfg = Release|x64
48 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Release|x64.Build.0 = Release|x64
49 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Release|x86.ActiveCfg = Release|x86
50 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B}.Release|x86.Build.0 = Release|x86
51 | EndGlobalSection
52 | GlobalSection(NestedProjects) = preSolution
53 | {537C6DEB-7D45-474E-A557-63E1D1CA3429} = {5073FB14-219B-42B2-8D2F-5FB700D7BA64}
54 | {680E076A-C3EA-4F2C-921B-2C8C5A25979B} = {6DD31636-6472-4054-B85E-BAAE9AE5FF38}
55 | EndGlobalSection
56 | EndGlobal
57 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LibP2P.Peer (cs-libp2p-peer)
2 |
3 | [](https://travis-ci.org/libp2p/cs-libp2p-peer)
4 | [](https://ci.appveyor.com/project/tabrath/cs-libp2p-peer)
5 | [](https://www.nuget.org/packages/LibP2P.Peer)
6 | [](https://www.nuget.org/packages/LibP2P.Peer)
7 | [](https://codecov.io/gh/libp2p/cs-libp2p-peer)
8 | [](https://libraries.io/github/libp2p/cs-libp2p-peer)
9 |
10 | > Implementation/port of [libp2p/go-libp2p-peer](https://github.com/libp2p/go-libp2p-peer) in C# .NET Standard 1.6 compliant.
11 |
12 | ## Table of Contents
13 |
14 | - [Install](#install)
15 | - [Usage](#usage)
16 | - [Maintainers](#maintainers)
17 | - [Contribute](#contribute)
18 | - [License](#license)
19 |
20 | ## Install
21 |
22 | PM> Install-Package LibP2P.Peer
23 |
24 | --
25 |
26 | dotnet add package LibP2P.Peer
27 |
28 | ## Usage
29 |
30 | TODO
31 |
32 | ## Maintainers
33 |
34 | Captain: [@tabrath](https://github.com/tabrath).
35 |
36 | ## Contribute
37 |
38 | Contributions welcome. Please check out [the issues](https://github.com/libp2p/cs-libp2p-crypto/issues).
39 |
40 | ## License
41 |
42 | [MIT](LICENSE) © 2017 Trond Bråthen
43 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | environment:
2 | PKG_VERSION: 1.1.0
3 | VERSION_SUFFIX: ""
4 | version: ${PKG_VERSION}-{build}
5 | configuration: Release
6 | platform: x64
7 |
8 | skip_commits:
9 | message: /travis/
10 | files:
11 | - '**\*.md'
12 | - LICENSE
13 |
14 | skip_branch_with_pr: true
15 |
16 | matrix:
17 | fast_finish: true
18 |
19 | init:
20 | - git config --global core.autocrlf input
21 | - ps: $env:BUILD_VERSION = "$env:PKG_VERSION-$env:APPVEYOR_BUILD_NUMBER"
22 | - ps: |
23 | if ($env:APPVEYOR_REPO_BRANCH -eq "master")
24 | {
25 | $env:VERSION_SUFFIX = ""
26 | $env:NUGET_VERSION = "$env:PKG_VERSION"
27 | }
28 | else
29 | {
30 | $env:VERSION_SUFFIX = "beta$env:APPVEYOR_BUILD_NUMBER"
31 | $env:NUGET_VERSION = "$env:PKG_VERSION-$env:VERSION_SUFFIX"
32 | }
33 | - ps: Update-AppveyorBuild -Version $env:BUILD_VERSION
34 | - ps: Write-Host "Build version $env:BUILD_VERSION, NuGet version $env:NUGET_VERSION, Version suffix $env:VERSION_SUFFIX"
35 |
36 | install:
37 | - git submodule update --init --recursive
38 |
39 | before_build:
40 | - appveyor-retry dotnet restore -v Minimal
41 |
42 | build_script:
43 | - ps: |
44 | if ($env:APPVEYOR_REPO_BRANCH -eq "master")
45 | {
46 | dotnet build "src\LibP2P.Peer" -c $env:CONFIGURATION
47 | }
48 | else
49 | {
50 | dotnet build "src\LibP2P.Peer" -c $env:CONFIGURATION --version-suffix $env:VERSION_SUFFIX
51 | }
52 |
53 | after_build:
54 | - ps: |
55 | if ($env:APPVEYOR_REPO_BRANCH -eq "master")
56 | {
57 | dotnet pack "src\LibP2P.Peer" -c $env:CONFIGURATION --no-build -o $env:APPVEYOR_BUILD_FOLDER\artifacts
58 | }
59 | else
60 | {
61 | dotnet pack "src\LibP2P.Peer" -c $env:CONFIGURATION --no-build --version-suffix $env:VERSION_SUFFIX -o $env:APPVEYOR_BUILD_FOLDER\artifacts
62 | }
63 |
64 | test: off
65 |
66 | before_test:
67 | - nuget install OpenCover -Version 4.6.519 -OutputDirectory .\tools
68 |
69 | test_script:
70 | - .\tools\OpenCover.4.6.519\tools\OpenCover.Console.exe -register:user -returntargetcode -target:"%ProgramFiles%\dotnet\dotnet.exe" -targetargs:"test %APPVEYOR_BUILD_FOLDER%\test\LibP2P.Peer.Tests\LibP2P.Peer.Tests.csproj -c Debug -f netcoreapp1.1 -l trx;logfilename=TestResult.xml /p:Platform=AnyCPU" -excludebyattribute:*.ExcludeFromCodeCoverage* -filter:"+[LibP2P.Peer]* -[LibP2P.Peer.Tests]*" -hideskipped:All -output:"%APPVEYOR_BUILD_FOLDER%\coverage.xml" -oldStyle
71 |
72 | after_test:
73 | - ps: |
74 | $wc = New-Object 'System.Net.WebClient'
75 | $wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\test\LibP2P.Peer.Tests\TestResults\TestResult.xml))
76 |
77 | on_success:
78 | - "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
79 | - pip install codecov
80 | - codecov -f "%APPVEYOR_BUILD_FOLDER%\coverage.xml" -X gcov
81 |
82 | artifacts:
83 | - path: artifacts\**\*.*
84 |
85 | cache:
86 | - '%USERPROFILE%\.local'
87 | - '%USERPROFILE%\.nuget\packages -> **\project.json'
88 | - '%LocalAppData%\NuGet\Cache'
89 | - '%LocalAppData%\Python'
90 | - '.\packages -> **\project.json'
91 | - '.\tools'
92 | - '\Python34'
93 |
94 | nuget:
95 | account_feed: true
96 |
97 | deploy:
98 | - provider: NuGet
99 | api_key:
100 | secure: WcDqU36pLPvA+s5D4N0VEsi7AZGewvf4croE/D3rh3F+iqiztq9w5gHbrhgoTNS9
101 | on:
102 | branch: master
103 | appveyor_repo_tag: true
104 | - provider: GitHub
105 | description: 'Release description'
106 | auth_token:
107 | secure: nsZHZ5nFBFP4fZoVUEeWeZKx7LUASVqCZ+JblTox+02RfTAOlANdFWeCqOwhu7pk
108 | artifact: /.*\.nupkg/ # upload all NuGet packages to release assets
109 | draft: false
110 | prerelease: false
111 | on:
112 | branch: master # release from master branch only
113 | appveyor_repo_tag: true
114 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -e
4 |
5 | if [ $TRAVIS_OS_NAME = "osx" ]; then
6 | ulimit -n 1024
7 | dotnet restore --disable-parallel --runtime osx-x64
8 | else
9 | dotnet restore --runtime ubuntu-x64
10 | fi
11 |
12 | export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
13 |
14 | dotnet test ./test/LibP2P.Peer.Tests/LibP2P.Peer.Tests.csproj -c Release -f netcoreapp1.1
15 |
16 | # disabled net461 for now as sodium.core does not work with net461, yet
17 | #dotnet build ./test/LibP2P.Crypto.Tests/LibP2P.Crypto.Tests.csproj -c Release -f net461
18 | #mono $HOME/.nuget/packages/xunit.runner.console/2.2.0/tools/xunit.console.exe ./test/LibP2P.Crypto.Tests/bin/Release/net461/LibP2P.Crypto.Tests.dll
19 |
--------------------------------------------------------------------------------
/src/LibP2P.Peer/LibP2P.Peer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard1.6
4 | win7-x64;linux-x64
5 | LibP2P Peer
6 | Copyright © tabrath 2017
7 | LibP2P.Peer
8 | 1.1.0
9 | tabrath
10 | true
11 | LibP2P.Peer
12 | LibP2P.Peer
13 | libp2p peer
14 | https://raw.githubusercontent.com/libp2p/website/0f6f8c7/static/img/favicon.png
15 | https://github.com/libp2p/cs-libp2p-peer/blob/master/LICENSE
16 | https://github.com/libp2p/cs-libp2p-peer
17 | git
18 | https://github.com/libp2p/cs-libp2p-peer
19 | AnyCPU
20 | Library
21 |
22 |
23 |
24 | true
25 | full
26 | false
27 | $(DefineConstants);DEBUG
28 |
29 |
30 |
31 | pdbonly
32 | true
33 | $(DefineConstants)
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/LibP2P.Peer/PeerId.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Text;
4 | using LibP2P.Crypto;
5 | using Multiformats.Base;
6 | using Multiformats.Hash;
7 | using Multiformats.Hash.Algorithms;
8 |
9 | namespace LibP2P.Peer
10 | {
11 | public class PeerId : IComparable, IEquatable
12 | {
13 | private readonly byte[] _value;
14 |
15 | public PeerId(byte[] bytes)
16 | {
17 | _value = bytes;
18 | }
19 |
20 | public PeerId(string s)
21 | : this(Encoding.UTF8.GetBytes(s))
22 | {
23 | }
24 |
25 | public PeerId(Multihash mh)
26 | : this((byte[])mh)
27 | {
28 | }
29 |
30 | public PeerId(PublicKey pk)
31 | : this(Multihash.Sum(pk.Bytes))
32 | {
33 | }
34 |
35 | public PeerId(PrivateKey sk)
36 | : this(sk.GetPublic())
37 | {
38 | }
39 |
40 | public int CompareTo(PeerId other) => string.Compare(ToString(Multibase.Base16), other.ToString(Multibase.Base16), StringComparison.Ordinal);
41 |
42 | public bool Equals(PeerId other) => _value.SequenceEqual(other?._value ?? Array.Empty());
43 |
44 | public override bool Equals(object obj)
45 | {
46 | var other = (PeerId) obj;
47 | return other != null && Equals(other);
48 | }
49 |
50 | public override int GetHashCode() => _value.GetHashCode();
51 |
52 | public override string ToString()
53 | {
54 | var id = ToString(Multibase.Base58);
55 | if (id.StartsWith("Qm"))
56 | id = id.Substring(2);
57 |
58 | var max = Math.Max(6, id.Length);
59 | return $"";
60 | }
61 |
62 | public string ToString(MultibaseEncoding encoding) => Multibase.EncodeRaw(encoding, _value);
63 |
64 | public bool MatchesPrivateKey(PrivateKey sk) => MatchesPublicKey(sk.GetPublic());
65 | public bool MatchesPublicKey(PublicKey pk) => new PeerId(pk).Equals(this);
66 |
67 | public static PeerId Decode(string s)
68 | {
69 | Multihash mh;
70 | return Multihash.TryParse(s, out mh) ? new PeerId(mh) : new PeerId(Multibase.DecodeRaw(s.ToUpper()));
71 | }
72 |
73 | public static implicit operator PeerId(string value) => new PeerId(value);
74 | public static implicit operator string(PeerId id) => Encoding.UTF8.GetString(id._value);
75 | public static implicit operator PeerId(byte[] bytes) => new PeerId(bytes);
76 | public static implicit operator byte[](PeerId id) => id._value;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/test/LibP2P.Peer.Tests/LibP2P.Peer.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp1.1
4 | win7-x64;linux-x64
5 | true
6 | LibP2P.Peer.Tests
7 | LibP2P.Peer.Tests
8 | true
9 |
10 |
11 | true
12 | full
13 | false
14 | $(DefineConstants);DEBUG
15 |
16 |
17 | pdbonly
18 | true
19 | $(DefineConstants)
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/test/LibP2P.Peer.Tests/PeerIdTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using LibP2P.Crypto;
3 | using Multiformats.Base;
4 | using Multiformats.Hash;
5 | using Multiformats.Hash.Algorithms;
6 | using Xunit;
7 |
8 | namespace LibP2P.Peer.Tests
9 | {
10 | public class PeerIdTests
11 | {
12 | private class KeySet
13 | {
14 | public PrivateKey sk { get; protected set; }
15 | public PublicKey pk { get; protected set; }
16 | public string hpk { get; protected set; }
17 | public string hpkp { get; protected set; }
18 |
19 | protected KeySet() { }
20 |
21 | public static KeySet Generate()
22 | {
23 | var pair = KeyPair.Generate(KeyType.RSA, 512);
24 |
25 | var h = Multihash.Sum(pair.PublicKey.Bytes);
26 | var ks = new KeySet
27 | {
28 | sk = pair.PrivateKey,
29 | pk = pair.PublicKey,
30 | hpk = h.ToString(Multibase.Base16),
31 | hpkp = h.ToString(Multibase.Base58)
32 | };
33 | return ks;
34 | }
35 |
36 | public static KeySet Load(string hpkp, string skBytesStr)
37 | {
38 | var skBytes = Convert.FromBase64String(skBytesStr);
39 | var ks = new KeySet {sk = PrivateKey.Unmarshal(skBytes)};
40 | ks.pk = ks.sk.GetPublic();
41 | var h = Multihash.Sum(ks.pk.Bytes);
42 | ks.hpk = h.ToString(Multibase.Base16);
43 | ks.hpkp = h.ToString(Multibase.Base58);
44 | if (ks.hpkp != hpkp)
45 | throw new Exception($"hpkp doesn't match key. want: {hpkp}, got: {ks.hpkp}");
46 |
47 | return ks;
48 | }
49 | }
50 |
51 | private KeySet gen1;
52 | private KeySet gen2;
53 | private KeySet man;
54 | private const string hpkpMan = "QmRK3JgmVEGiewxWbhpXLJyjWuGuLeSTMTndA1coMHEy5o";
55 | private const string skManBytes = "CAAS4AQwggJcAgEAAoGBAL7w+Wc4VhZhCdM/+Hccg5Nrf4q9NXWwJylbSrXz/unFS24wyk6pEk0zi3W7li+vSNVO+NtJQw9qGNAMtQKjVTP+3Vt/jfQRnQM3s6awojtjueEWuLYVt62z7mofOhCtj+VwIdZNBo/EkLZ0ETfcvN5LVtLYa8JkXybnOPsLvK+PAgMBAAECgYBdk09HDM7zzL657uHfzfOVrdslrTCj6p5moDzvCxLkkjIzYGnlPuqfNyGjozkpSWgSUc+X+EGLLl3WqEOVdWJtbM61fewEHlRTM5JzScvwrJ39t7o6CCAjKA0cBWBd6UWgbN/t53RoWvh9HrA2AW5YrT0ZiAgKe9y7EMUaENVJ8QJBAPhpdmb4ZL4Fkm4OKiaNEcjzn6mGTlZtef7K/0oRC9+2JkQnCuf6HBpaRhJoCJYg7DW8ZY+AV6xClKrgjBOfERMCQQDExhnzu2dsQ9k8QChBlpHO0TRbZBiQfC70oU31kM1AeLseZRmrxv9Yxzdl8D693NNWS2JbKOXl0kMHHcuGQLMVAkBZ7WvkmPV3aPL6jnwp2pXepntdVnaTiSxJ1dkXShZ/VSSDNZMYKY306EtHrIu3NZHtXhdyHKcggDXrqkBrdgErAkAlpGPojUwemOggr4FD8sLX1ot2hDJyyV7OK2FXfajWEYJyMRL1Gm9Uk1+Un53RAkJneqpJGAzKpyttXBTIDO51AkEA98KTiROMnnU8Y6Mgcvr68/SMIsvCYMt9/mtwSBGgl80VaTQ5Hpaktl6XbhVUt5Wv0tRxlXZiViCGCD1EtrrwTw==";
56 |
57 | public PeerIdTests()
58 | {
59 | gen1 = KeySet.Generate();
60 | gen2 = KeySet.Generate();
61 | man = KeySet.Load(hpkpMan, skManBytes);
62 | }
63 |
64 | [Fact]
65 | public void TestIdMatchesPublicKey()
66 | {
67 | Action test = (ks) =>
68 | {
69 | var p1 = PeerId.Decode(ks.hpkp);
70 | Assert.Equal(p1.ToString(Multibase.Base16), ks.hpk);
71 | Assert.True(p1.MatchesPublicKey(ks.pk));
72 |
73 | var p2 = new PeerId(ks.pk);
74 | Assert.Equal(p1, p2);
75 | Assert.Equal(p2.ToString(Multibase.Base58), ks.hpkp);
76 | };
77 |
78 | test(gen1);
79 | test(gen2);
80 | test(man);
81 | }
82 |
83 | [Fact]
84 | public void TestIdMatchesPrivateKey()
85 | {
86 | Action test = (ks) =>
87 | {
88 | var p1 = PeerId.Decode(ks.hpkp);
89 | Assert.Equal(p1.ToString(Multibase.Base16), ks.hpk);
90 | Assert.True(p1.MatchesPrivateKey(ks.sk));
91 |
92 | var p2 = new PeerId(ks.sk);
93 | Assert.Equal(p1, p2);
94 | };
95 |
96 | test(gen1);
97 | test(gen2);
98 | test(man);
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------