Skip to content

Commit

Permalink
ipv6 support; multi fairy server support
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Feb 9, 2023
1 parent 4930e68 commit b84b365
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 37 deletions.
96 changes: 59 additions & 37 deletions FairyPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Neo.ConsoleService;
using Neo.SmartContract.Native;
using Microsoft.Extensions.Configuration;
using System.Runtime.Serialization.Formatters;

namespace Neo.Plugins
{
Expand All @@ -21,7 +22,7 @@ public Settings(IConfigurationSection section)

Settings settings;
NeoSystem system;
Fairy fairy;
List<Fairy> fairyServers = new();

protected override void Configure()
{
Expand All @@ -31,58 +32,79 @@ protected override void Configure()

protected override void OnSystemLoaded(NeoSystem system)
{
RpcServerSettings s = settings.Servers.FirstOrDefault(p => p.Network == system.Settings.Network);
this.system = system;
fairy = new(system, s);
fairy.StartRpcServer();
fairy.StartWebsocketServer();
bool hasServer = false;
foreach (RpcServerSettings s in settings.Servers)
{
if (s.Network == system.Settings.Network)
{
hasServer = true;
Fairy fairy = new(system, s);
fairy.StartRpcServer();
fairy.StartWebsocketServer();
fairyServers.Add(fairy);
}
}
if (hasServer == false)
{
ConsoleHelper.Warning("No valid server from config. Using default!");
RpcServerSettings s = RpcServerSettings.Default;
Fairy fairy = new(system, s);
fairy.StartRpcServer();
fairy.StartWebsocketServer();
fairyServers.Add(fairy);
}
}

[ConsoleCommand("fairy", Category = "Fairy Commands", Description = "List Fairy snapshots")]
private void OnFairyCommand()
{
ConsoleHelper.Info("Test snapshots:");
if (fairy.sessionStringToFairySession.Keys.Count > 0)
foreach (Fairy fairy in fairyServers)
{
Console.WriteLine("session name:\t\t\t");
foreach (string k in fairy.sessionStringToFairySession.Keys)
Console.WriteLine($">>> Fairy@{fairy.settings.BindAddress}:{fairy.settings.Port}");
ConsoleHelper.Info("Test snapshots:");
if (fairy.sessionStringToFairySession.Keys.Count > 0)
{
ConsoleHelper.Info($"{k}\t\t\t{fairy.sessionStringToFairySession[k].ToString()}");
Console.WriteLine("session name:\t\t\t");
foreach (string k in fairy.sessionStringToFairySession.Keys)
{
ConsoleHelper.Info($"{k}\t\t\t{fairy.sessionStringToFairySession[k].ToString()}");
}
}
}
else
{
ConsoleHelper.Warning($"No test snapshot created!");
}
Console.WriteLine("------");
else
{
ConsoleHelper.Warning($"No test snapshot created!");
}
Console.WriteLine("------");

ConsoleHelper.Info("DebugInfo registration:");
if (fairy.contractScriptHashToSourceLineFilenames.Keys.Count > 0)
{
Console.Error.WriteLine($"test snapshot\t\t\tcontract name\t\t\tscript hash");
foreach (UInt160 k in fairy.contractScriptHashToSourceLineFilenames.Keys)
ConsoleHelper.Info("DebugInfo registration:");
if (fairy.contractScriptHashToSourceLineFilenames.Keys.Count > 0)
{
string? contractName = null;
string? testSession = null;
foreach (string s in fairy.sessionStringToFairySession.Keys)
Console.Error.WriteLine($"test snapshot\t\t\tcontract name\t\t\tscript hash");
foreach (UInt160 k in fairy.contractScriptHashToSourceLineFilenames.Keys)
{
contractName = NativeContract.ContractManagement.GetContract(fairy.sessionStringToFairySession[s].engine.Snapshot, k)?.Manifest.Name;
if (contractName != null)
string? contractName = null;
string? testSession = null;
foreach (string s in fairy.sessionStringToFairySession.Keys)
{
testSession = s;
break;
contractName = NativeContract.ContractManagement.GetContract(fairy.sessionStringToFairySession[s].engine.Snapshot, k)?.Manifest.Name;
if (contractName != null)
{
testSession = s;
break;
}
}
if (contractName == null)
contractName = "Unknown Contract";
ConsoleHelper.Info($"{testSession}\t\t\t\t{contractName}\t\t\t{k}");
ConsoleHelper.Info(String.Join(", ", fairy.contractScriptHashToSourceLineFilenames[k]));
Console.WriteLine("---");
}
if (contractName == null)
contractName = "Unknown Contract";
ConsoleHelper.Info($"{testSession}\t\t\t\t{contractName}\t\t\t{k}");
ConsoleHelper.Info(String.Join(", ", fairy.contractScriptHashToSourceLineFilenames[k]));
Console.WriteLine("---");
}
}
else
{
ConsoleHelper.Warning($"No DebugInfo registration!");
else
{
ConsoleHelper.Warning($"No DebugInfo registration!");
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@
"DisabledMethods": [],
"SessionEnabled": true,
"SessionExpirationTime": 86400
},
{ // ipv6 server
"Network": 860833102,
"BindAddress": "::",
"Port": 16868,
"SslCert": "",
"SslCertPassword": "",
"TrustedAuthorities": [],
"RpcUser": "",
"RpcPass": "",
"MaxGasInvoke": 200,
"MaxFee": 0.1,
"MaxConcurrentConnections": 40,
"MaxIteratorResultItems": 100,
"DisabledMethods": [],
"SessionEnabled": true,
"SessionExpirationTime": 86400
}
]
}
Expand Down

0 comments on commit b84b365

Please sign in to comment.