Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ReserveBlockIO/RBXOSeedv1.0.0
Rbxo seedv1.0.0
- Loading branch information
Showing
24 changed files
with
1,450 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34330.188 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RBXOSeed", "RBXOSeed\RBXOSeed.csproj", "{07E02246-BA43-4572-9625-7F4734933F8B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{07E02246-BA43-4572-9625-7F4734933F8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{07E02246-BA43-4572-9625-7F4734933F8B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{07E02246-BA43-4572-9625-7F4734933F8B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{07E02246-BA43-4572-9625-7F4734933F8B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {D6E9A886-E501-4B1B-B7AC-13EC08D809E4} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-ef": { | ||
"version": "8.0.1", | ||
"commands": [ | ||
"dotnet-ef" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace RBXOSeed.Controllers | ||
{ | ||
public class ActionFilterController : ActionFilterAttribute | ||
{ | ||
public override void OnActionExecuting(ActionExecutingContext filterContext) | ||
{ | ||
try | ||
{ | ||
|
||
} | ||
catch { } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Newtonsoft.Json; | ||
using RBXOSeed.Models; | ||
using RBXOSeed.Utility; | ||
using RBXOSeed.Data; | ||
using System.Xml.Linq; | ||
|
||
namespace RBXOSeed.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class V1Controller : ControllerBase | ||
{ | ||
#region Private Variables | ||
public class JsonResult | ||
{ | ||
public bool Success { get; set; } | ||
|
||
public string Reason { get; set; } | ||
} | ||
|
||
#endregion | ||
|
||
#region Get - Test if Seed node is online | ||
/// <summary> | ||
/// Check Status of API | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet] | ||
public async Task<string> Get([FromQuery]string? walletVersion = null, [FromQuery]bool? isVal = null) | ||
{ | ||
if (!HttpContext.Response.Headers.ContainsKey("Access-Control-Allow-Origin")) | ||
{ | ||
HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); | ||
} | ||
var ip = IPUtility.GetIPAddress(HttpContext); | ||
if (ip == "") | ||
{ | ||
ip = "localhost"; | ||
} | ||
else | ||
{ | ||
if(!Globals.NodeBag.Contains(ip)) | ||
{ | ||
Globals.NodeQueue.Enqueue((ip, isVal != null ? isVal.Value : false)); | ||
Globals.NodeBag.Add(ip); | ||
} | ||
|
||
} | ||
if(walletVersion != null) | ||
return JsonConvert.SerializeObject(new { Name = Globals.SeedName != null ? Globals.SeedName : "RBX One Seed Node", Status = "Online", IP = ip}, Formatting.Indented); | ||
|
||
return $"[\"ReserveBlock Seed Node Status\",\"Online\",\"{ip}\"]"; | ||
} | ||
|
||
#endregion | ||
|
||
#region Gets peers to send out | ||
[HttpGet("GetNodes")] | ||
public IEnumerable<string> GetNodes() | ||
{ | ||
if (!HttpContext.Response.Headers.ContainsKey("Access-Control-Allow-Origin")) | ||
{ | ||
HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); | ||
} | ||
var ip = IPUtility.GetIPAddress(HttpContext); | ||
|
||
var nodes = Nodes.GetAll()?.Query().Where(x => x.NodeIP != ip && x.IsActive == true).ToList(); | ||
|
||
if (nodes.Count() == 0) | ||
{ | ||
return new string[] { "No Nodes" }; | ||
} | ||
if (nodes.Count() <= 20) //users can connect up to 14 outbound connections | ||
{ | ||
var nodeList = nodes.Select(x => x.NodeIP); | ||
return nodeList; | ||
} | ||
else //users can connect up to 14 outbound connections this will get 14 random | ||
{ | ||
var rnd = new Random(); | ||
var nodeList = nodes.Where(x => x.IsPortOpen == true).OrderBy(x => rnd.Next()).Select(x => x.NodeIP).Take(50); | ||
return nodeList; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Gets peers to send out | ||
[HttpGet("GetPeers")] | ||
public ContentResult GetPeers() | ||
{ | ||
if (!HttpContext.Response.Headers.ContainsKey("Access-Control-Allow-Origin")) | ||
{ | ||
HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); | ||
} | ||
|
||
HttpContext.Response.Headers.ContentType = "application/json"; | ||
|
||
var ip = IPUtility.GetIPAddress(HttpContext); | ||
|
||
var nodes = Nodes.GetAll()?.Query().Where(x => x.NodeIP != ip && x.IsActive == true).ToList(); | ||
|
||
if (nodes.Count() == 0) | ||
{ | ||
return Content(JsonConvert.SerializeObject(new { Success = false, Message = "No Nodes", Nodes = new List<string>() }, Formatting.Indented)); | ||
} | ||
if (nodes.Count() <= 20) //users can connect up to 14 outbound connections | ||
{ | ||
var nodeList = nodes.Select(x => x.NodeIP); | ||
return Content(JsonConvert.SerializeObject(new { Success = true, Message = "Nodes Found", Nodes = nodeList.ToList() }, Formatting.Indented)); | ||
} | ||
else //users can connect up to 14 outbound connections this will get 14 random | ||
{ | ||
var rnd = new Random(); | ||
var nodeList = nodes.Where(x => x.IsPortOpen == true).OrderBy(x => rnd.Next()).Select(x => x.NodeIP).Take(50); | ||
return Content(JsonConvert.SerializeObject(new { Success = true, Message = "Nodes Found", Nodes = nodeList.ToList() }, Formatting.Indented)); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Call to Node | ||
[HttpGet("GetCallToNode")] | ||
public async Task<bool> GetCallToNode([FromQuery] bool? isVal) | ||
{ | ||
bool output = true; | ||
if (!HttpContext.Response.Headers.ContainsKey("Access-Control-Allow-Origin")) | ||
{ | ||
HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); | ||
} | ||
|
||
var ip = IPUtility.GetIPAddress(HttpContext); | ||
|
||
var nodeExist = Nodes.GetAll()?.Query().Where(x => x.NodeIP == ip).FirstOrDefault(); | ||
if(nodeExist == null) | ||
{ | ||
var isPortOpen = IPUtility.IsPortOpen(ip, Globals.PortToCheck); | ||
var isValidator = isVal == null ? false : isVal.Value == false ? false : true; | ||
|
||
Nodes node = new Nodes { | ||
Active = true, | ||
CallOuts = 0, | ||
CreateDateTimeUtc = DateTime.UtcNow, | ||
FailureCount = 0, | ||
IsActive = true, | ||
IsPortOpen = isPortOpen, | ||
IsValidator= isValidator, | ||
LastActiveDate= DateTime.UtcNow, | ||
LastPolled = DateTime.UtcNow, | ||
ModifiedDateTimeUtc= DateTime.UtcNow, | ||
NodeIP= ip, | ||
}; | ||
} | ||
|
||
return output; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using LiteDB; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace RBXOSeed.Data | ||
{ | ||
internal static class DbContext | ||
{ | ||
private static string MainFolder = "RBX"; | ||
public static LiteDatabase DB { set; get; }// stores blocks | ||
|
||
//Database names | ||
public const string RSRV_DB_NAME = @"rbxseeddata.db"; | ||
|
||
//Database tables | ||
public const string RSRV_ADJUDICATOR = "rsrv_adjudicator"; | ||
public const string RSRV_BEACON = "rsrv_beacon"; | ||
public const string RSRV_NODES = "rsrv_nodes"; | ||
public const string RSRV_EMAIL = "rsrv_email"; | ||
|
||
internal static void Initialize() | ||
{ | ||
string path = GetDatabasePath(); | ||
|
||
//Only use if you have issues with DateTime/DateTimeOffset | ||
var mapper = new BsonMapper(); | ||
mapper.RegisterType<DateTime>( | ||
value => value.ToString("o", CultureInfo.InvariantCulture), | ||
bson => DateTime.ParseExact(bson, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)); | ||
mapper.RegisterType<DateTimeOffset>( | ||
value => value.ToString("o", CultureInfo.InvariantCulture), | ||
bson => DateTimeOffset.ParseExact(bson, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)); | ||
|
||
DB = new LiteDatabase(new ConnectionString { Filename = path + RSRV_DB_NAME, Connection = ConnectionType.Direct, ReadOnly = false }); | ||
|
||
//Assumes UTC Time for Dates | ||
DB.Pragma("UTC_DATE", true); | ||
} | ||
|
||
public static void CloseDB() | ||
{ | ||
DB.Dispose(); | ||
} | ||
|
||
public static async Task CheckPoint() | ||
{ | ||
try | ||
{ | ||
DB.Checkpoint(); | ||
} | ||
catch { } | ||
} | ||
|
||
public static string GetDatabasePath() | ||
{ | ||
string path = ""; | ||
|
||
var databaseLocation = "Databases"; | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
string homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); | ||
path = homeDirectory + Path.DirectorySeparatorChar + MainFolder.ToLower() + Path.DirectorySeparatorChar + databaseLocation + Path.DirectorySeparatorChar; | ||
} | ||
else | ||
{ | ||
if (Debugger.IsAttached) | ||
{ | ||
path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DBs" + Path.DirectorySeparatorChar + databaseLocation + Path.DirectorySeparatorChar; | ||
} | ||
else | ||
{ | ||
path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + MainFolder + Path.DirectorySeparatorChar + databaseLocation + Path.DirectorySeparatorChar; | ||
} | ||
} | ||
|
||
if (!Directory.Exists(path)) | ||
{ | ||
Directory.CreateDirectory(path); | ||
} | ||
|
||
return path; | ||
} | ||
} | ||
} |
Oops, something went wrong.