Skip to content

Commit

Permalink
initial round of updates. brings c sdk up to 0.34.x. updates to power…
Browse files Browse the repository at this point in the history
…shell setups, etc. will iterate on readmes next
  • Loading branch information
dovholuknf committed Sep 24, 2023
1 parent 2ec0db3 commit 7cc5086
Show file tree
Hide file tree
Showing 40 changed files with 1,560 additions and 1,226 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/native-nuget-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ jobs:
run: |
sudo apt update -y
sudo apt install -y crossbuild-essential-armhf crossbuild-essential-arm64
- uses: lukka/run-vcpkg@v10
with:
vcpkgGitCommitId: '19af97cba8ca48474e4ad15a24ed50271a9ecdac'

- name: setup/build CMake
env:
TOOLCHAIN: ${{ matrix.toolchain && format('{0}/toolchains/{1}.cmake', env.BASEDIR, matrix.toolchain) || '' }}
run: |
echo "build number = ${{ env.buildnum }}"
cmake -E make_directory ${{ env.TARGETDIR }}
cmake -S ${{ env.BASEDIR }} -B ${{ env.TARGETDIR }} ${{ matrix.cmake_arch_flag }} -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN}"
cmake -S ${{ env.BASEDIR }} -B ${{ env.TARGETDIR }} -DCMAKE_BUILD_TYPE=Debug
cmake --build ${{ env.TARGETDIR }} --config Release
- name: upload artifacts
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cmake-build-debug-mingw/
cmake-build-debug-msvc/

*.jwt
Samples/**/*.json
*.snupkg

weather.demo.json
62 changes: 30 additions & 32 deletions OpenZiti.NET/OpenZiti.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<CurrentYear>$([System.DateTime]::UtcNow.Year.ToString().Substring(2,2))</CurrentYear>
<UtcDayOfYear>$([System.DateTime]::UtcNow.DayOfYear)</UtcDayOfYear>
<SecondsOfDay>$([MSBuild]::Divide($([System.DateTime]::get_Now().get_TimeOfDay().get_TotalSeconds()), 2).ToString('F0'))</SecondsOfDay>
<UtcSecondsOfDay>$([MSBuild]::Divide($([System.DateTime]::get_UtcNow().get_TimeOfDay().get_TotalSeconds()), 2).ToString('F0'))</UtcSecondsOfDay>
<UtcSecondsOfDay>$([MSBuild]::Divide($([System.DateTime]::UtcNow.TimeOfDay.TotalSeconds), 2).ToString('F0'))</UtcSecondsOfDay>
<major>0</major>
<minor>8</minor>
<Version>$(major).$(minor).$(UtcDayOfYear).$(UtcSecondsOfDay)</Version>
<minor>9</minor>
<Version>$(major).$(minor).$(CurrentYear)$(UtcDayOfYear).$(UtcSecondsOfDay)</Version>
<Authors>OpenZiti</Authors>
<Company>NetFoundry</Company>
<Description>A .NET standard library which wraps the C SDK and is consumable from .NET</Description>
<Copyright>© NetFoundry Inc. All rights reserved.</Copyright>
<PackageLicenseFile>2019_NF TCL EULA.txt</PackageLicenseFile>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://openziti.github.io/</PackageProjectUrl>
<PackageProjectUrl>https://openziti.io/</PackageProjectUrl>
<RepositoryUrl>https://github.com/openziti/ziti-sdk-csharp</RepositoryUrl>
<RootNamespace></RootNamespace>
<Platforms>AnyCPU;x86;x64;ARM64</Platforms>
<PackageIcon>ziti.png</PackageIcon>
<icon>..\ziti-v2.png</icon>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(Platform)'=='x64'">
<PlatformTarget>x64</PlatformTarget>
<DefineConstants>ZITI_X64;$(DefinedConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='ARM64'">
<PlatformTarget>arm64</PlatformTarget>
<DefineConstants>ZITI_X64;$(DefinedConstants)</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>TRACE;$(DefinedConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='x64'">
<PlatformTarget>x64</PlatformTarget>
<DefineConstants>ZITI_X64;$(DefinedConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='ARM64'">
<PlatformTarget>arm64</PlatformTarget>
<DefineConstants>ZITI_X64;$(DefinedConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>TRACE;$(DefinedConstants)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NLog" Version="5.0.4" />
<PackageReference Include="OpenZiti.NET.native" Version="0.30.8.22" />
<PackageReference Include="OpenZiti.NET.native" Version="2023.9.23.1954" />
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Text.Json" Version="6.0.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand All @@ -61,18 +59,18 @@
<Message Text="RUNNING: nuget pack OpenZiti.NET.nuspec -Version $(PackageVersion) -Symbols -SymbolPackageFormat snupkg" Importance="high" />
<Exec Command="nuget pack OpenZiti.NET.nuspec -Version $(PackageVersion) -Symbols -SymbolPackageFormat snupkg"></Exec>
</Target>
<Target Name="NugetPush" DependsOnTargets="NugetPack">
<Message Text="RUNNING: dotnet nuget push $(MSBuildProjectDirectory)/$(PackageId).$(PackageVersion).nupkg --source $(NUGET_SOURCE)" Importance="high" />
<Message Text="Push NuGet Package to NuGet Feed $(MSBuildProjectDirectory)/bin/Release/$(PackageId).$(PackageVersion).nupkg" Importance="high" />
<Exec Command="dotnet nuget push $(MSBuildProjectDirectory)/$(PackageId).$(PackageVersion).nupkg --source $(NUGET_SOURCE) --api-key $(API_KEY)"></Exec>
<ItemGroup>
<FilesToDelete Include="$(MSBuildProjectDirectory)/$(PackageId).$(PackageVersion).*nupkg" />
</ItemGroup>
<Delete Files="@(FilesToDelete)">
<Output TaskParameter="DeletedFiles" ItemName="DeletedList" />
</Delete>
<Message Text="Deleted files: '@(DeletedList)'" Importance="high" />
</Target>
<Target Name="NugetPush" DependsOnTargets="NugetPack">
<Message Text="RUNNING: dotnet nuget push $(MSBuildProjectDirectory)/$(PackageId).$(PackageVersion).nupkg --source $(NUGET_SOURCE)" Importance="high" />
<Message Text="Push NuGet Package to NuGet Feed $(MSBuildProjectDirectory)/bin/Release/$(PackageId).$(PackageVersion).nupkg" Importance="high" />
<Exec Command="dotnet nuget push $(MSBuildProjectDirectory)/$(PackageId).$(PackageVersion).nupkg --source $(NUGET_SOURCE) --api-key $(API_KEY)"></Exec>
<ItemGroup>
<FilesToDelete Include="$(MSBuildProjectDirectory)/$(PackageId).$(PackageVersion).*nupkg" />
</ItemGroup>
<Delete Files="@(FilesToDelete)">
<Output TaskParameter="DeletedFiles" ItemName="DeletedList" />
</Delete>
<Message Text="Deleted files: '@(DeletedList)'" Importance="high" />
</Target>
<Target Name="Buildx64">
<Message Text="BUILDING x64: dotnet build $(MSBuildProjectFullPath) --configuration Release /p:Platform=x64" Importance="high" />
<Exec Command="dotnet build $(MSBuildProjectFullPath) --configuration Release /p:PackageVersion=$(PackageVersion) /p:Platform=x64"></Exec>
Expand Down
22 changes: 9 additions & 13 deletions OpenZiti.NET/src/OpenZiti/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public static string EnrollIdentity(string jwtFile) {
public static string EnrollIdentity(byte[] jwt, string key, string cert) {
var rtn = nAPI.Ziti_enroll_identity(jwt, key, cert, out var id_json_ptr, out var id_json_len);
ZitiStatus status = (ZitiStatus)rtn;
if (status != ZitiStatus.OK) {
throw new ZitiException(status);
if (status != ZitiStatus.ZITI_OK) {
throw ZitiException.Create(rtn);
}
var id_json = Marshal.PtrToStringUTF8(id_json_ptr);
return id_json;
Expand All @@ -153,7 +153,7 @@ public static int CheckSocket(ZitiSocket socket) {
public static ZitiSocket Connect(ZitiSocket socket, ZitiContext ztx, string service, string terminator) {
var rtn = nAPI.Ziti_connect(socket.NativeSocket, ztx.NativeContext, service, terminator);
if (rtn < 0) {
ZitiStatus s = (ZitiStatus)rtn;
string s = Marshal.PtrToStringAnsi(Native.API.ziti_errorstr(rtn));
throw new ZitiException(s);
}
return socket;
Expand All @@ -162,7 +162,7 @@ public static ZitiSocket Connect(ZitiSocket socket, ZitiContext ztx, string serv
public static ZitiSocket ConnectByAddress(ZitiSocket socket, string host, UInt16 port) {
var rtn = nAPI.Ziti_connect_addr(socket.NativeSocket, host, port);
if (rtn < 0) {
ZitiStatus s = (ZitiStatus)rtn;
string s = Marshal.PtrToStringAnsi(Native.API.ziti_errorstr(rtn));
throw new ZitiException(s);
}
return socket;
Expand All @@ -171,18 +171,16 @@ public static ZitiSocket ConnectByAddress(ZitiSocket socket, string host, UInt16
public static void Bind(ZitiSocket socket, ZitiContext ztx, string service, string terminator) {
var rtn = nAPI.Ziti_bind(socket.NativeSocket, ztx.NativeContext, service, terminator);
if (rtn < 0) {
int be = LastError();
ZitiStatus s = (ZitiStatus)be;
throw new ZitiException(s);
int errNo = LastError();
throw ZitiException.Create(errNo);
}
}

public static void Listen(ZitiSocket socket, int backlog) {
var rtn = nAPI.Ziti_listen(socket.NativeSocket, backlog);
if (rtn < 0) {
int le = LastError();
ZitiStatus s = (ZitiStatus)le;
throw new ZitiException(s);
int errNo = LastError();
throw ZitiException.Create(errNo);
}
}

Expand All @@ -200,9 +198,7 @@ public static ZitiSocket Accept(ZitiSocket socket, out string caller) {

if (client_sock.ToInt64() < 0) {
int errNo = LastError();
//string err = Marshal.PtrToStringUTF8(NAPI.ziti_errorstr(errNo));
ZitiStatus s = (ZitiStatus)errNo;
throw new ZitiException(s);
throw ZitiException.Create(errNo);
}

caller = Marshal.PtrToStringUTF8(callerBuff);
Expand Down
4 changes: 2 additions & 2 deletions OpenZiti.NET/src/OpenZiti/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace OpenZiti {
/// A class which provides an extension method to get a Description from an enum. The enum must be
/// decorated with a <see cref="DescriptionAttribute"/>
/// </summary>
public static class EnumHelper {
public const string NO_DESC = "__NO DESCRIPTOIN AVAILABLE__";
public static class EnumHelpera {
public const string NO_DESC = "__NO DESCRIPTION AVAILABLE__";

/// <summary>
/// Extension method to return the <see cref="DescriptionAttribute"/> of the enum.
Expand Down
8 changes: 6 additions & 2 deletions OpenZiti.NET/src/OpenZiti/ZitiException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ You may obtain a copy of the License at
limitations under the License.
*/
using System;
using System.Runtime.InteropServices;

namespace OpenZiti {
/// <summary>
Expand All @@ -27,9 +28,12 @@ public class ZitiException : Exception {
public ZitiException(string message) : base(message) { }

/// <summary>
/// The basic constructor for creating a ZitiException
/// A method to create an exception from a Native SDK response code
/// </summary>
/// <param name="message">The message</param>
public ZitiException(ZitiStatus status) : base(status.GetDescription()) { }
public static ZitiException Create(int code) {
string desc = Marshal.PtrToStringAnsi(Native.API.ziti_errorstr(code));
return new ZitiException(desc);
}
}
}
Loading

0 comments on commit 7cc5086

Please sign in to comment.