private NodesGroup CreateNodeGroup(NodeConnectionParameters cloneParameters, NodeServices requiredServices) { return(new NodesGroup(this.Network, cloneParameters, new NodeRequirement() { MinVersion = this.NodeSettings.ProtocolVersion, RequiredServices = requiredServices, })); }
private NodesGroup CreateNodeGroup(NodeConnectionParameters cloneParameters, NodeServices requiredServices) { return(new NodesGroup(Network, cloneParameters, new NodeRequirement() { MinVersion = ProtocolVersion.SENDHEADERS_VERSION, RequiredServices = requiredServices, })); }
/// <summary> /// Return false if peer doesn't offer required services. /// </summary> /// <param name="peerVersion">The peer version.</param> /// <returns><see langword="false"/> if peer doesn't offer required service, <see langword="true"/> otherwise.</returns> private bool PeerDoesntOfferRequiredServices(VersionMessage peerVersion) { NodeServices requiredServices = _initialBlockDownloadState.IsDownloadingBlocks() ? (NodeServices.Network | NodeServices.Witness) : (NodeServices.NetworkLimited | NodeServices.Witness); var peerServices = (NodeServices)peerVersion.Services; return(!peerServices.HasFlag(requiredServices)); }
private NodesGroup CreateNodeGroup(NodeConnectionParameters cloneParameters, NodeServices requiredServices) { this.logger.LogTrace("({0}:{1})", nameof(requiredServices), requiredServices); var res = new NodesGroup(this.Network, cloneParameters, new NodeRequirement { MinVersion = this.NodeSettings.ProtocolVersion, RequiredServices = requiredServices, }); this.logger.LogTrace("(-)"); return(res); }
public StakingService(WalletManager walletManager, string passphrase, NodeServices nodeServices) { this.walletManager = walletManager; this.passphrase = passphrase; this.nodeServices = nodeServices; this.cts = new CancellationTokenSource(); this.stakingTask = new Task(StakingLoop, this.cts.Token); this.stopwatch = Stopwatch.StartNew(); this.Status = new StakingStatus { StartedUtc = DateTimeOffset.UtcNow.ToUnixTimeSeconds() }; this.PosV3 = new PosV3 { SearchInterval = 64, BlockInterval = 4 * 64 }; this.LastStakedBlock = new StakedBlock(); }
public void AddDiscoveredNodesRequirement(NodeServices services) { this.discoveredNodeRequiredService |= services; NodesGroup group = this.DiscoveredNodeGroup; if (group != null && !group.Requirements.RequiredServices.HasFlag(services)) { group.Requirements.RequiredServices |= NodeServices.NODE_WITNESS; foreach (Node node in group.ConnectedNodes) { if (!node.PeerVersion.Services.HasFlag(services)) { node.DisconnectAsync("The peer does not support the required services requirement"); } } } }
public void AddDiscoveredNodesRequirement(NodeServices services) { this.logger.LogTrace("({0}:{1})", nameof(services), services); this.discoveredNodeRequiredService |= services; NodesGroup group = this.DiscoveredNodeGroup; if ((group != null) && !group.Requirements.RequiredServices.HasFlag(services)) { group.Requirements.RequiredServices |= NodeServices.NODE_WITNESS; foreach (Node node in group.ConnectedNodes) { if (!node.PeerVersion.Services.HasFlag(services)) { node.DisconnectAsync("The peer does not support the required services requirement."); } } } this.logger.LogTrace("(-)"); }
public FakeFactory(ITestOutputHelper testOutputHelper) { this.testOutputHelper = testOutputHelper; this.Network = ObsidianXNetworksSelector.Obsidian.Mainnet(); this.loggerFactory = new TestLoggerFactory(testOutputHelper); this.nodeSettings = Obsidian.x1d.Util.Init.GetNodeSettings(new string[0]); this.DataFolder = this.nodeSettings.DataFolder; this.InitialBlockDownloadState = new TestInitialBlockDownloadState() { IBD = true }; this.ChainIndexer = new ChainIndexer(this.Network); this.Signals = new Signals(this.loggerFactory, new DefaultSubscriptionErrorHandler(this.loggerFactory)); this.NodeLifetime = new NodeLifetime(); this.BlockStore = new TestBlockStore(); this.NodeServices = new NodeServices(dataFolder: this.DataFolder, chainIndexer: this.ChainIndexer, network: this.Network, broadcasterManager: new TestBroadcastManager(), this.loggerFactory, nodeLifetime: this.NodeLifetime, signals: this.Signals, blockStore: this.BlockStore, timeSyncBehaviorState: null, initialBlockDownloadState: this.InitialBlockDownloadState, blockProvider: null, consensusManager: null, stakeChain: null, coinView: null, dateTimeProvider: null, chainState: null); this.WalletManagerFactory = new WalletManagerFactory(this.NodeServices); }
private IPeerConnector CreatePeerConnector( NodeConnectionParameters parameters, NodeServices requiredServices, Func <IPEndPoint, byte[]> peerSelector, PeerIntroductionType peerIntroductionType, int?maximumNodeConnections = 8) { this.logger.LogTrace("({0}:{1})", nameof(requiredServices), requiredServices); var nodeRequirement = new NodeRequirement { MinVersion = this.NodeSettings.ProtocolVersion, RequiredServices = requiredServices, }; var peerConnector = new PeerConnector(this.Network, this.nodeLifetime, parameters, nodeRequirement, peerSelector, this.asyncLoopFactory, this.peerAddressManager, peerIntroductionType) { MaximumNodeConnections = maximumNodeConnections.Value }; this.logger.LogTrace("(-)"); return(peerConnector); }
private async Task <DM.Citation> CreateCitationAsync(DE.Style style, DE.Format format, DM.ContentItem contentItem) { ExpandoObject request = new ExpandoObject(); List <PM.ContentItem> requestList = new List <PM.ContentItem>(); requestList.Add(PF.CiteProcFactory.Build("0", contentItem)); requestList = _overrideManager.PreProcessCitation(style, requestList); requestList.ForEach(x => request.TryAdd(x.ID, x)); using (StringAsTempFile file = new StringAsTempFile(GetContents(), CancellationToken.None)) { string result = await NodeServices.InvokeAsync <string>(file.FileName, GetLibrary(), PL.Locale.GetLocale(), PD.Definition.GetDefinition(style), PF.CiteProcFactory.Build(format), JObject.Parse(request.ToSerializedJSON())); PM.Citation citation = JsonConvert.DeserializeObject <PM.Citation>(result); citation.ProcessExceptions(); citation = _overrideManager.PostProcessCitation(style, citation); DM.Citation response = PF.CiteProcFactory.Build(citation); return(response); } }
/// <summary> /// Executes the processor on the specified configuration. /// </summary> public override async Task ExecuteAsync(IAssetContext context) { var env = (IHostingEnvironment)context.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)); var fileProvider = context.Asset.GetFileProvider(env); var content = new Dictionary <string, byte[]>(); if (!EnsureNodeFiles("WebOptimizer.TypeScript.node_files.zip")) { return; } string module = Path.Combine(InstallDirectory, "typescript.js"); foreach (string route in context.Content.Keys) { var file = fileProvider.GetFileInfo(route); var input = context.Content[route].AsString(); var result = await NodeServices.InvokeAsync <string>(module, input, file.PhysicalPath); content[route] = result.AsByteArray(); } context.Content = content; }
private async Task <DM.Bibliography> CreateBibliographyAsync(DE.Style style, DE.Format format, List <DM.ContentItem> contentItems) { ExpandoObject request = new ExpandoObject(); List <PM.ContentItem> requestList = new List <PM.ContentItem>(); requestList.AddRange(contentItems.Select((x, i) => PF.CiteProcFactory.Build(i.ToString(), x))); requestList = _overrideManager.PreProcessBibliography(style, requestList); requestList.ForEach(x => request.TryAdd(x.ID, x)); using (StringAsTempFile file = new StringAsTempFile(GetContents(), CancellationToken.None)) { string result = await NodeServices.InvokeAsync <string>(file.FileName, GetLibrary(), PL.Locale.GetLocale(), PD.Definition.GetDefinition(style), PF.CiteProcFactory.Build(format), JObject.Parse(request.ToSerializedJSON())); PM.Bibliography bibliography = JsonConvert.DeserializeObject <PM.Bibliography>(result); bibliography.ProcessExceptions(); bibliography = _overrideManager.PostProcessBibliography(style, bibliography); DM.Bibliography response = PF.CiteProcFactory.Build(bibliography); return(response); } }
public void AddServices(NodeServices services) { _logger.LogDebug("Adding services {NodeServices}", services); _availableServices |= services; }
public void RemoveServices(NodeServices services) { _logger.LogDebug("Removing services {NodeServices}", services); _availableServices &= ~services; }
static void Main(string[] args) { baseAddress = args[0]; if (!baseAddress.EndsWith("/")) { baseAddress += "/"; } // Start OWIN host using (WebApp.Start <Startup>(url: baseAddress)) { Console.WriteLine(""); Console.WriteLine("CSharpChain Blockchain // [email protected] // www.mauer.si"); Console.WriteLine("----------------------------------------"); Console.WriteLine("This CSharpChain node is running on " + baseAddress); Console.WriteLine("Type 'help' if you are not sure what to do ;)"); blockchainServices = new BlockchainServices(); nodeServices = new NodeServices(blockchainServices.Blockchain); string commandLine; do { ShowCommandLine(); commandLine = Console.ReadLine().ToLower(); commandLine += " "; var command = commandLine.Split(' '); switch (command[0]) { case "quit": case "q": commandLine = "q"; break; case "help": case "?": CommandHelp(); break; case "node-add": case "na": // if param1 is numeric then translate to localhost port if (command[1].All(char.IsDigit)) { command[1] = "http://localhost:" + command[1]; } CommandNodeAdd(command[1]); break; case "node-remove": case "nr": // if param1 is numeric then translate to localhost port if (command[1].All(char.IsDigit)) { command[1] = "http://localhost:" + command[1]; } CommandNodeRemove(command[1]); break; case "nodes-list": case "nl": CommandListNodes(nodeServices.Nodes); break; case "transactions-add": case "ta": CommandTransactionsAdd(command[1], command[2], command[3], command[4]); break; case "transactions-pending": case "tp": CommandListPendingTransactions(blockchainServices.Blockchain.PendingTransactions); break; case "blockchain-mine": case "bm": CommandBlockchainMine(command[1]); break; case "bv": case "blockchain-valid": CommandBlockchainValidity(); break; case "blockchain-length": case "bl": CommandBlockchainLength(); break; case "block": case "b": CommandBlock(int.Parse(command[1])); break; case "balance-get": case "bal": CommandBalance(command[1]); break; case "blockchain-update": case "update": case "bu": CommandBlockchainUpdate(); break; default: Console.WriteLine("Ups! I don't understand..."); Console.WriteLine(""); break; } } while (commandLine != "q"); } }
static void Main(string[] args) { //Console.OutputEncoding = Encoding.UTF8; //if(args.Length == 0) //{ //args = new string[1]; //Random rnd = new Random(); //args[0] = @"http://*****:*****@"http://localhost:44312"; //} //baseAddress = args[0]; //if (!baseAddress.EndsWith("/")) baseAddress += "/"; // // Start OWIN host baseAddress = "http://localhost:8080/"; using (WebApp.Start <Startup>(url: baseAddress)) { Console.WriteLine("This CSharpChain node is running on " + baseAddress); Console.WriteLine("Nhận 'trogiup' nếu bạn không chắc phải làm gì ;)"); blockchainServices = new BlockchainServices(); nodeServices = new NodeServices(blockchainServices.Blockchain); string commandLine; do { ShowCommandLine(); commandLine = Console.ReadLine().ToLower(); commandLine += " "; var command = commandLine.Split(' '); switch (command[0]) { case "quit": case "q": commandLine = "q"; break; case "trogiup": case "?": CommandHelp(); break; case "node-add": case "na": // if param1 is numeric then translate to localhost port //if (command[1].All(char.IsDigit)) command[1] = "http://localhost:" + command[1]; //CommandNodeAdd(command[1]); CommandNodeAdd("http://localhost:" + command[1].ToString()); break; case "node-remove": case "nr": // if param1 is numeric then translate to localhost port //if (command[1].All(char.IsDigit)) command[1] = "http://localhost:" + command[1]; //CommandNodeRemove(command[1]); CommandNodeRemove("http://localhost:" + command[1].ToString()); break; case "nodes-list": case "nl": CommandListNodes(nodeServices.Nodes); break; case "transactions-add": case "ta": CommandTransactionsAdd(command[1], command[2], command[3], command[4]); break; case "transactions-pending": case "tp": CommandListPendingTransactions(blockchainServices.Blockchain.PendingTransactions); break; case "blockchain-mine": case "bm": CommandBlockchainMine(command[1]); break; case "bv": case "blockchain-valid": CommandBlockchainValidity(); break; case "blockchain-length": case "bl": CommandBlockchainLength(); break; case "block": case "b": CommandBlock(int.Parse(command[1])); break; case "balance-get": case "bal": CommandBalance(command[1]); break; case "blockchain-update": case "update": case "bu": CommandBlockchainUpdate(); break; default: Console.WriteLine("Ups! I don't understand..."); Console.WriteLine(""); break; } } while (commandLine != "q"); } }
public bool HasServices(NodeServices service) { return(_availableServices.HasFlag(service)); }