Skip to content

Commit

Permalink
New: IPFS.io integration
Browse files Browse the repository at this point in the history
  • Loading branch information
rzander committed Dec 28, 2017
1 parent 0cde4e4 commit fd048fd
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 441 deletions.
67 changes: 42 additions & 25 deletions RZ.Cache/RZCache/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public string get()
{
string sVersion = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;

return "RuckZuck-Proxy (c) 2017 by Roger Zander; Version: " + sVersion;
return "RuckZuck-Proxy (c) 2018 by Roger Zander; Version: " + sVersion;
}


Expand Down Expand Up @@ -69,21 +69,37 @@ public RZController(IConfiguration config, IMemoryCache memoryCache)
RuckZuck_WCF.RZRestProxy.sURL = config.GetSection("ParentServer").Value ?? _config.GetSection("RuckZuck:ParentServer").Value;
RuckZuck_WCF.RZRestProxy.CatalogTTL = int.Parse(_config.GetSection("CatalogTTL").Value ?? _config.GetSection("RuckZuck:CatalogTTL").Value);
RuckZuck_WCF.RZRestProxy.localURL = config.GetSection("localURL").Value ?? _config.GetSection("RuckZuck:localURL").Value;
RuckZuck_WCF.RZRestProxy.ipfs_GW_URL = config.GetSection("IPFS_GW_URL").Value ?? _config.GetSection("RuckZuck:ipfs_GW_URL").Value;
RuckZuck_WCF.RZRestProxy._cache = _cache;
RuckZuck_WCF.RZRestProxy.Proxy = config.GetSection("Proxy").Value ?? _config.GetSection("RuckZuck:Proxy").Value;
RuckZuck_WCF.RZRestProxy.ProxyUserPW = config.GetSection("ProxyUserPW ").Value ?? _config.GetSection("RuckZuck:ProxyUserPW").Value;
RuckZuck_WCF.RZRestProxy.ProxyUserPW = config.GetSection("ProxyUserPW").Value ?? _config.GetSection("RuckZuck:ProxyUserPW").Value;
if (RuckZuck_WCF.RZRestProxy.RedirectToIPFS == false)
{
RuckZuck_WCF.RZRestProxy.UseIPFS = int.Parse(_config.GetSection("UseIPFS").Value ?? _config.GetSection("RuckZuck:UseIPFS").Value);
}

}

[Route("AuthenticateUser")]
public ActionResult AuthenticateUser()
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
if(RuckZuck_WCF.RZRestProxy.contentType == "*/*")
{
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
}
string Username = _config.GetSection("RZUser").Value ?? Request.Headers["Username"];
string Password = _config.GetSection("RZPW").Value ?? Request.Headers["Password"];

if (string.IsNullOrEmpty(Username))
{
return Content("deecdc6b-ad08-42ab-a743-a3c0f9033c80", "text/xml"); ;
Username = Request.Headers["Username"];
Password = Request.Headers["Password"];
}

if (string.IsNullOrEmpty(Username))
{
return Content("", "text/xml");
}
else
{
Expand All @@ -107,7 +123,7 @@ public ActionResult AuthenticateUser()
}
else
{
return Content(RuckZuck_WCF.RZRestProxy.GetAuthToken(Username, Password), "text/xml") ;
return Content(RuckZuck_WCF.RZRestProxy.GetAuthToken(Username, Password), "text/xml"); ;
}
}

Expand All @@ -118,7 +134,9 @@ public ActionResult AuthenticateUser()
[Route("SWResults/{search}")]
public ActionResult SWResults(string search = "")
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
//RuckZuck_WCF.RZRestProxy.contentType = "application/json";

string sRes = RuckZuck_WCF.RZRestProxy.SWResults(search);
return Content(sRes, "text/xml");
}
Expand All @@ -128,7 +146,8 @@ public ActionResult SWResults(string search = "")
[Route("SWGetShort/{name}")]
public ActionResult SWGet(string name = "")
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
return Content(RuckZuck_WCF.RZRestProxy.SWGet(name), "text/xml");
}

Expand All @@ -137,7 +156,8 @@ public ActionResult SWGet(string name = "")
[Route("SWGet/{name}/{ver}")]
public ActionResult SWGet(string name = "", string ver = "")
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
return Content(RuckZuck_WCF.RZRestProxy.SWGet(name, ver), "text/xml");
}

Expand All @@ -146,7 +166,8 @@ public ActionResult SWGet(string name = "", string ver = "")
[Route("SWGet/{name}/{manuf}/{ver}")]
public ActionResult SWGet(string name = "", string manuf = "", string ver = "")
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
return Content(RuckZuck_WCF.RZRestProxy.SWGet(name, manuf, ver), "text/xml");
}

Expand All @@ -155,7 +176,8 @@ public ActionResult SWGet(string name = "", string manuf = "", string ver = "")
[Route("GetSWDefinition/{name}/{ver}/{man}")]
public ActionResult GetSWDefinition(string name = "", string ver = "", string man = "")
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
return Content(RuckZuck_WCF.RZRestProxy.GetSWDefinitions(name, ver, man), "text/xml");
}

Expand All @@ -164,7 +186,8 @@ public ActionResult GetSWDefinition(string name = "", string ver = "", string ma
[Route("Feedback/{name}/{ver}/{man}/{arch}/{ok}/{user}/{text}")]
public ActionResult Feedback(string name, string ver, string man = "", string arch = "", string ok = "", string user = "", string text = "")
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
return Content(RuckZuck_WCF.RZRestProxy.Feedback(name, ver, man, arch, ok, user, text).Result, "text/xml");
}

Expand All @@ -176,30 +199,22 @@ public Stream GetIcon(Int32 id = 575633)
return RuckZuck_WCF.RZRestProxy.GetIcon(id);
}


[HttpGet]
[Route("TrackDownloads")]
[Route("TrackDownloads/{id}")]
public void TrackDownloads(string id)
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
RuckZuck_WCF.RZRestProxy.TrackDownloads(id);
}

[HttpGet]
[Route("TrackDownloadsNew")]
[Route("TrackDownloadsNew/{SWId}/{arch}")]
public void TrackDownloadsNew(string SWId, string arch)
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
RuckZuck_WCF.RZRestProxy.TrackDownloadsNew(SWId, arch);
}

[HttpPost]
[Route("CheckForUpdateXml")]
public ActionResult CheckForUpdateXml()
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
var oGet = new StreamReader(Request.Body).ReadToEndAsync();

return Content(RuckZuck_WCF.RZRestProxy.CheckForUpdate(oGet.Result.ToString()), "text/xml");
Expand All @@ -209,7 +224,8 @@ public ActionResult CheckForUpdateXml()
[Route("CheckForUpdate")]
public ActionResult CheckForUpdate()
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
var oGet = new StreamReader(Request.Body).ReadToEndAsync();

return Content(RuckZuck_WCF.RZRestProxy.CheckForUpdate(oGet.Result.ToString()), "text/xml");
Expand All @@ -219,7 +235,8 @@ public ActionResult CheckForUpdate()
[Route("UploadSWEntry")]
public bool UploadSWEntry()
{
RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/xml";
//RuckZuck_WCF.RZRestProxy.contentType = (string)Request.Headers["Accept"] ?? "application/json";
RuckZuck_WCF.RZRestProxy.contentType = "application/json";
var oGet = new StreamReader(Request.Body).ReadToEndAsync();

return RuckZuck_WCF.RZRestProxy.UploadSWEntry(oGet.Result.ToString());
Expand Down
16 changes: 15 additions & 1 deletion RZ.Cache/RZCache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@ ARG source
WORKDIR /app
EXPOSE 5000:5000/tcp
EXPOSE 5001:5001/udp
EXPOSE 4001:4001
EXPOSE 4002:4002/udp
EXPOSE 5002:5002/tcp
EXPOSE 8080:8080
EXPOSE 8081:8081
ENTRYPOINT ["dotnet", "RZCache.dll"]
COPY ${source:-obj/Docker/publish} .
#RUN tar xvfz /app/wwwroot/go-ipfs_v0.4.13_linux-amd64.tar.gz
#RUN mv go-ipfs/ipfs /usr/local/bin/ipfs
RUN rm /app/wwwroot/go-ipfs_v0.4.13_linux-amd64.tar.gz
ENV localURL "https://rzproxy.azurewebsites.net"
ENV RZUser ""
ENV RZPW ""
ENV ParentServer "https://ruckzuck.azurewebsites.net/wcf/RZService.svc"
ENV CatalogTTL "4"
ENV Proxy ""
ENV ProxyUserPW ""
ENV ProxyUserPW ""
ENV UseIPFS "0"
ENV WebPort "5000"
ENV UDPPort "5001"
ENV IPFS_PATH "/app/.ipfs"
ENV IPFS_LOGGING ""
#ENV IPFS_GW_URL "https://gateway.ipfs.io/ipfs"
39 changes: 37 additions & 2 deletions RZ.Cache/RZCache/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,49 @@
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace RZWCF
{
public class Program
{
public static void Main(string[] args)
{
var Server = new UdpClient(5001);
var Server = new UdpClient(int.Parse(Environment.GetEnvironmentVariable("UDPPort") ?? "5001"));

if (Environment.GetEnvironmentVariable("UseIPFS") == "1")
{
try
{
if (!Directory.Exists("/app/.ipfs"))
{
var oInit = Process.Start("ipfs", @"init"); //>/dev/null 2>/dev/null
oInit.StartInfo.RedirectStandardOutput = false;
oInit.WaitForExit(5000);
Thread.Sleep(3000);
}
Process.Start("ipfs", "config --json Experimental.FilestoreEnabled true").WaitForExit();
Process.Start("ipfs", "config Addresses.API /ip4/0.0.0.0/tcp/5002").WaitForExit();
Process.Start("ipfs", "config Addresses.Gateway /ip4/0.0.0.0/tcp/8080").WaitForExit();
//Process.Start("ipfs", "config --json API.HTTPHeaders.Access-Control-Allow-Origin '[\"*\"]'").WaitForExit(); ;
//Process.Start("ipfs", "config --json API.HTTPHeaders.Access-Control-Allow-Methods '[\"PUT\",\"GET\",\"POST\"]'").WaitForExit();
//Process.Start("ipfs", "add -r --nocopy /app/wwwroot/files").WaitForExit();

Thread.Sleep(2000);
Process.Start("ipfs", "daemon").WaitForExit(7000);
Thread.Sleep(2000);

RuckZuck_WCF.RZRestProxy.IPFSAdd("/app/RZCache.dll");

}
catch (Exception ex)
{
RuckZuck_WCF.RZRestProxy.RedirectToIPFS = true;
RuckZuck_WCF.RZRestProxy.UseIPFS = 0;
Console.WriteLine("IPFS ERROR:" + ex.Message);
}
}

if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("localURL")))
{
Expand All @@ -42,7 +77,7 @@ public static void Main(string[] args)
.UseStartup<Startup>()
//.UseApplicationInsights()
.UseWebRoot("wwwroot")
.UseUrls("http://*:5000")
.UseUrls("http://*:" + Environment.GetEnvironmentVariable("WebPort") ?? "5000")
.Build();
host.Run();
}
Expand Down
15 changes: 10 additions & 5 deletions RZ.Cache/RZCache/RZCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<FileVersion>1.0.1.0</FileVersion>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.3.0</FileVersion>
<AssemblyVersion>1.0.3.0</AssemblyVersion>
<Authors>Roger Zander</Authors>
<Company>Zander Tools</Company>
<Product>RZWCF Proxy Service</Product>
<Description>RuckZuck.tool Proxy and Caching Service</Description>
<Copyright>Copyright (c) 2017 by Roger Zander</Copyright>
<Copyright>Copyright (c) 2018 by Roger Zander</Copyright>
<PackageProjectUrl>https://github.com/rzander/ruckzuck</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/rzander/ruckzuck/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageTags>software package manager windows cache proxy</PackageTags>
<UserSecretsId>3d943e5a-c0e9-40f0-b91e-9ab682223099</UserSecretsId>
<Version>1.0.1</Version>
<Version>1.0.3</Version>
<SignAssembly>false</SignAssembly>
<StartupObject>RZWCF.Program</StartupObject>
<ApplicationIcon />
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
Expand All @@ -33,7 +36,9 @@
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
<Folder Include="wwwroot\files\" />
<Folder Include="wwwroot\icons\" />
<Folder Include="wwwroot\rzsw\" />
</ItemGroup>

</Project>
Loading

0 comments on commit fd048fd

Please sign in to comment.