public override TokenReassignResponse Receive(object anything) { if (!IsMyProcessRunning(ProcessId)) { throw new RahRowRagee($"The process by id [{ProcessId}] has exited"); } if (!NfNet.IsValidPortNumber(SocketPort)) { throw new ItsDeadJim("The assigned socket port is not valid " + SocketPort); } var rqst = Request ?? anything as TokenReassignRequest; if (rqst == null) { throw new ItsDeadJim("The request object is not assigned."); } var json = JsonConvert.SerializeObject(rqst); var bufferIn = Encoding.UTF8.GetBytes(json); var bufferOut = NfNet.SendToLocalhostSocket(bufferIn, SocketPort); if (bufferOut == null || bufferOut.Length <= 0) { throw new ItsDeadJim( $"The remote process by id [{ProcessId}] did not return anything on port [{SocketPort}]"); } json = ConvertJsonFromBuffer(bufferOut); return(JsonConvert.DeserializeObject <TokenReassignResponse>(json, JsonSerializerSettings)); }
public override TokenPageRankResponse Receive(object anything) { if (anything == null) { throw new ArgumentNullException(nameof(anything)); } if (!IsMyProcessRunning(ProcessId)) { throw new RahRowRagee($"The process by id [{ProcessId}] has exited"); } if (!NfNet.IsValidPortNumber(SocketPort)) { throw new ItsDeadJim("The assigned socket port is not valids " + SocketPort); } var pageRank = anything as TokenIdResponse; if (pageRank == null) { throw new InvalidCastException("Was expecting the 'anything' arg to be castable " + "to " + typeof(TokenIdResponse).Name); } var json = JsonConvert.SerializeObject(pageRank); var bufferIn = Encoding.UTF8.GetBytes(json); var bufferOut = NfNet.SendToLocalhostSocket(bufferIn, SocketPort); if (bufferOut == null || bufferOut.Length <= 0) { throw new ItsDeadJim( $"The remote process by id [{ProcessId}] did not return anything on port [{SocketPort}]"); } json = ConvertJsonFromBuffer(bufferOut); return(JsonConvert.DeserializeObject <TokenPageRankResponse>(json, JsonSerializerSettings)); }
public override FlattenAssembly Receive(object anything) { if (anything == null) { throw new ArgumentNullException(nameof(anything)); } if (String.IsNullOrWhiteSpace(anything.ToString()) || !File.Exists(anything.ToString())) { throw new ItsDeadJim("This isn't a valid assembly path " + anything); } if (!IsMyProcessRunning(ProcessId)) { throw new ItsDeadJim("The NoFuture.Tokens.Gia.InvokeFlatten.exe is either dead or was never started."); } if (!NfNet.IsValidPortNumber(SocketPort)) { throw new ItsDeadJim("The assigned socket port is not valids " + SocketPort); } var bufferOut = NfNet.SendToLocalhostSocket(Encoding.UTF8.GetBytes(anything.ToString()), SocketPort); if (bufferOut == null || bufferOut.Length <= 0) { throw new ItsDeadJim( $"The remote process by id [{ProcessId}] did not return anything on port [{SocketPort}]"); } return(JsonConvert.DeserializeObject <FlattenAssembly>(ConvertJsonFromBuffer(bufferOut), JsonSerializerSettings)); }
//launch a socket listener on each specified port protected override void LaunchListeners() { _taskFactory = new TaskFactory(); _tasks = new List <Task>(); if (NfNet.IsValidPortNumber(MyHostParameters.SjclBulkKeyToPlainTextPort)) { _tasks.Add(_taskFactory.StartNew( () => HostCmd(new BkToPlainTextCommand(_bulkKey), MyHostParameters.SjclBulkKeyToPlainTextPort))); Thread.Sleep(BRING_ONLINE_DEFAULT_WAIT_MS); PrintToConsole("Sjcl Bulk Key To Plain Text is online."); } if (NfNet.IsValidPortNumber(MyHostParameters.SjclBulkKeyToCipherTextPort)) { _tasks.Add(_taskFactory.StartNew( () => HostCmd(new BkToCipherTextCommand(_bulkKey), MyHostParameters.SjclBulkKeyToCipherTextPort))); Thread.Sleep(BRING_ONLINE_DEFAULT_WAIT_MS); PrintToConsole("Sjcl Bulk Key To Cipher Text is online."); } if (NfNet.IsValidPortNumber(MyHostParameters.SjclSha256HashPort)) { _tasks.Add(_taskFactory.StartNew( () => HostCmd(new Sha256HashCommand(_hashSalt), MyHostParameters.SjclSha256HashPort))); Thread.Sleep(BRING_ONLINE_DEFAULT_WAIT_MS); PrintToConsole("Sjcl Sha256 Hash is online."); } }
public void TestGetNetStatUri() { var testResult = NfNet.GetNetStatIp("23.235.44.133:443 "); Assert.IsNotNull(testResult); Assert.IsFalse(testResult.Equals(System.Net.IPAddress.Loopback)); Assert.AreEqual("23.235.44.133", testResult.ToString()); Console.WriteLine(testResult.ToString()); testResult = NfNet.GetNetStatIp("[::]:0 "); Assert.IsNotNull(testResult); Assert.IsTrue(testResult.Equals(System.Net.IPAddress.IPv6Loopback)); testResult = NfNet.GetNetStatIp("*:* "); Assert.IsNotNull(testResult); Assert.IsTrue(testResult.Equals(System.Net.IPAddress.Loopback)); testResult = NfNet.GetNetStatIp("0.0.0.0:0 "); Assert.IsNotNull(testResult); Assert.IsTrue(testResult.Equals(System.Net.IPAddress.Loopback)); testResult = NfNet.GetNetStatIp("[::1]:1900 "); Assert.IsNotNull(testResult); Assert.IsTrue(testResult.Equals(System.Net.IPAddress.IPv6Loopback)); testResult = NfNet.GetNetStatIp("0.0.0.0:57077 "); Assert.IsNotNull(testResult); Assert.IsTrue(testResult.Equals(System.Net.IPAddress.Loopback)); testResult = NfNet.GetNetStatIp("127.0.0.1:62522 "); Assert.IsNotNull(testResult); Assert.IsTrue(testResult.Equals(System.Net.IPAddress.Loopback)); }
public TagsetBase[][] Receive(object anything) { if (anything == null) { throw new ArgumentNullException(nameof(anything)); } if (!IsMyProcessRunning(ProcessId)) { throw new RahRowRagee($"The process by id [{ProcessId}] has exited"); } if (!NfNet.IsValidPortNumber(SocketPort)) { throw new ItsDeadJim("The assigned socket port is not valids " + SocketPort); } var bufferOut = NfNet.SendToLocalhostSocket(Encoding.UTF8.GetBytes(anything.ToString()), SocketPort); var taggedText = Encoding.UTF8.GetString(bufferOut); TagsetBase[][] tagsOut; if (!PtTagset.TryParse(taggedText, out tagsOut)) { throw new RahRowRagee("was unable to parse the tagged string sent back from the" + $"remote process [{ProcessId}] on port [{SocketPort}]"); } return(tagsOut); }
protected override void LaunchListeners() { if (!NfNet.IsValidPortNumber(GetTokenIdsCmdPort) || !NfNet.IsValidPortNumber(GetTokenNamesCmdPort) || !NfNet.IsValidPortNumber(GetAsmIndicesCmdPort) || !NfNet.IsValidPortNumber(GetTokenPageRankCmdPort) || !NfNet.IsValidPortNumber(GetTokenTypesCmdPort) || !NfNet.IsValidPortNumber(ReassignTokenNamesCmdPort)) { throw new RahRowRagee("the command's ports are either null or invalid " + $" {nameof(GetAsmIndicesCmdPort)} is port [{GetAsmIndicesCmdPort}]" + $" {nameof(GetTokenIdsCmdPort)} is port [{GetTokenIdsCmdPort}]" + $" {nameof(GetTokenNamesCmdPort)} is port [{GetTokenNamesCmdPort}]" + $" {nameof(GetTokenPageRankCmdPort)} is port [{GetTokenPageRankCmdPort}]" + $" {nameof(GetTokenTypesCmdPort)} is port [{GetTokenPageRankCmdPort}]" + $" {nameof(ReassignTokenNamesCmdPort)} is port [{ReassignTokenNamesCmdPort}]"); } _taskFactory = new TaskFactory(); _taskFactory.StartNew(() => HostCmd(new GetAsmIndices(this), GetAsmIndicesCmdPort.Value)); _taskFactory.StartNew(() => HostCmd(new GetTokenIds(this), GetTokenIdsCmdPort.Value)); _taskFactory.StartNew(() => HostCmd(new GetTokenNames(this), GetTokenNamesCmdPort.Value)); _taskFactory.StartNew(() => HostCmd(new GetTokenPageRank(this), GetTokenPageRankCmdPort.Value)); _taskFactory.StartNew(() => HostCmd(new GetTokenTypes(this), GetTokenTypesCmdPort.Value)); _taskFactory.StartNew(() => HostCmd(new ReassignTokenNames(this), ReassignTokenNamesCmdPort.Value)); }
protected override void LaunchListeners() { if (!NfNet.IsValidPortNumber(GetNfTypeNamePort)) { throw new RahRowRagee("the command's ports are either null or invalid " + $" GetFlattenAssemblyCmdPort is port [{GetNfTypeNamePort}]"); } _taskFactory = new TaskFactory(); _taskFactory.StartNew(() => HostCmd(new GetNfTypeName(this), GetNfTypeNamePort.Value)); }
protected override void LaunchListeners() { if (!NfNet.IsValidPortNumber(GetFlattenAssemblyCmdPort)) { throw new RahRowRagee("the command's ports are either null or invalid " + String.Format(" GetFlattenAssemblyCmdPort is port [{0}]", GetFlattenAssemblyCmdPort)); } _taskFactory = new TaskFactory(); _taskFactory.StartNew(() => HostCmd(new GetFlattenAssembly(this, GetMaxDepth), GetFlattenAssemblyCmdPort.Value)); }
public void TestGetProxyAuthHeaderValue() { var username = "******"; var pwd = "open sesame"; var testResult = NfNet.GetAuthHeaderValue(username, pwd); Assert.AreEqual("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", testResult); testResult = NfNet.GetAuthHeaderValue(null, pwd); Assert.IsNotNull(testResult); }
public override TokenIdResponse Receive(object anything) { int asmIdx; if (anything == null) { throw new ArgumentNullException(nameof(anything)); } if (!IsMyProcessRunning(ProcessId)) { throw new RahRowRagee($"The process by id [{ProcessId}] has exited"); } if (!NfNet.IsValidPortNumber(SocketPort)) { throw new ItsDeadJim("The assigned socket port is not valid " + SocketPort); } if (!int.TryParse(anything.ToString(), out asmIdx)) { throw new ArgumentException("Was expected an Assembly index Id"); } if (AsmIndices == null) { throw new RahRowRagee("In a chain of responsibility - this type requires " + "an instance of AsmIndices."); } if (AsmIndices.Asms.All(x => x.IndexId != asmIdx)) { throw new RahRowRagee($"No matching index found for {asmIdx}"); } var asmName = AsmIndices.Asms.First(x => x.IndexId == asmIdx).AssemblyName; var rqst = new TokenIdRequest { AsmName = asmName, ResolveAllNamedLike = RecurseAnyAsmNamedLike }; var json = JsonConvert.SerializeObject(rqst); var bufferIn = Encoding.UTF8.GetBytes(json); var bufferOut = NfNet.SendToLocalhostSocket(bufferIn, SocketPort); if (bufferOut == null || bufferOut.Length <= 0) { throw new ItsDeadJim( $"The remote process by id [{ProcessId}] did not return anything on port [{SocketPort}]"); } json = ConvertJsonFromBuffer(bufferOut); return(JsonConvert.DeserializeObject <TokenIdResponse>(json, JsonSerializerSettings)); }
protected override void LaunchListeners() { if (!NfNet.IsValidPortNumber(CmdPort)) { throw new RahRowRagee("the command's ports are either null or invalid " + $"[{CmdPort}]."); } _taskFactory.StartNew( () => HostCmd(new PosParserCmd(this), CmdPort.GetValueOrDefault(NfConfig.NfDefaultPorts.PartOfSpeechPaserHost))); //print settings PrintToConsole($"{MyName} listening on port [{CmdPort}]"); }
public override TokenNameResponse Receive(object anything) { if (anything == null) { throw new ArgumentNullException(nameof(anything)); } if (!IsMyProcessRunning(ProcessId)) { throw new RahRowRagee($"The process by id [{ProcessId}] has exited"); } if (!NfNet.IsValidPortNumber(SocketPort)) { throw new ItsDeadJim("The assigned socket port is not valid " + SocketPort); } var metadataTokenIds = anything as MetadataTokenId[]; if (metadataTokenIds == null) { throw new InvalidCastException("Was expecting the 'anything' arg to be cast-able " + "to an array of " + typeof(MetadataTokenId).FullName); } var rqst = new TokenNameRequest { Tokens = metadataTokenIds, MapFullCallStack = this.MapFullCallStack }; var json = JsonConvert.SerializeObject(rqst); var bufferIn = Encoding.UTF8.GetBytes(json); var bufferOut = NfNet.SendToLocalhostSocket(bufferIn, SocketPort); if (bufferOut == null || bufferOut.Length <= 0) { throw new ItsDeadJim( $"The remote process by id [{ProcessId}] did not return anything on port [{SocketPort}]"); } json = ConvertJsonFromBuffer(bufferOut); return(JsonConvert.DeserializeObject <TokenNameResponse>(json, JsonSerializerSettings)); }
public void TestGetNetStatServiceByPort() { var testResult = NfNet.GetNetStatServiceByPort("tcp", "127.0.0.1:563"); Assert.AreEqual("nntps", testResult.Item1); testResult = NfNet.GetNetStatServiceByPort("tcp", "127.0.0.1:563 "); Assert.AreEqual("nntps", testResult.Item1); testResult = NfNet.GetNetStatServiceByPort("tcp", "*:*"); Assert.AreEqual(string.Empty, testResult.Item1); testResult = NfNet.GetNetStatServiceByPort("udp", "[::1]:1900 "); Assert.AreEqual("ssdp", testResult.Item1); testResult = NfNet.GetNetStatServiceByPort("udp", "[::]:0 "); Assert.AreEqual(string.Empty, testResult.Item1); testResult = NfNet.GetNetStatServiceByPort("udp", "[::]:3540 "); Assert.AreEqual("pnrp-port", testResult.Item1); Assert.AreEqual("PNRP User Port", testResult.Item2); }
public override AsmIndexResponse Receive(object anything) { if (anything == null) { throw new ArgumentNullException(nameof(anything)); } if (String.IsNullOrWhiteSpace(anything.ToString()) || !File.Exists(anything.ToString())) { throw new ItsDeadJim("This isn't a valid assembly path"); } if (!IsMyProcessRunning(ProcessId)) { throw new RahRowRagee($"The process by id [{ProcessId}] has exited"); } if (!NfNet.IsValidPortNumber(SocketPort)) { throw new ItsDeadJim("The assigned socket port is not valid " + SocketPort); } var rqst = new AsmIndexRequest { AssemblyFilePath = anything.ToString() }; var json = JsonConvert.SerializeObject(rqst); var bufferIn = Encoding.UTF8.GetBytes(json); var bufferOut = NfNet.SendToLocalhostSocket(bufferIn, SocketPort); if (bufferOut == null || bufferOut.Length <= 0) { throw new ItsDeadJim( $"The remote process by id [{ProcessId}] did not return anything on port [{SocketPort}]"); } json = ConvertJsonFromBuffer(bufferOut); return(JsonConvert.DeserializeObject <AsmIndexResponse>(json, JsonSerializerSettings)); }
internal bool IsValid() { return(NfNet.IsValidPortNumber(SjclBulkKeyToCipherTextPort) && NfNet.IsValidPortNumber(SjclBulkKeyToPlainTextPort) && NfNet.IsValidPortNumber(SjclSha256HashPort)); }