public Client(Bytes <Address> address, IPEndPoint endPoint, string baseDirectory, string?networkPrefix = null, IEnumerable <IPEndPoint>?seeds = null, SuperNodeConfig?superConfig = null, string?name = null) { Name = name ?? endPoint.ToString(); Address = address; NetworkPrefix = networkPrefix; SuperConfig = superConfig; EndPoint = endPoint; BindEndPoint = new IPEndPoint(IPAddress.Any, endPoint.Port); string chainName = networkPrefix ?? "main"; System = new BlockChainSystem(this, Path.Combine(baseDirectory, $"{address}-{chainName}"), chainName); P2P = new P2P(this); if (superConfig is not null) { ProducerSystem = new ProducerSystem(this); } Nodes = new KBucket(16, address, P2P.Ping); P2P.Init(); Random random = new Random(); refreshKBucketTimeSpan = TimeSpan.FromSeconds(random.NextDouble() * 5 + 60); refreshKBucketTimer = new Timer(async delegate { if (closeCancelTokenSource.IsCancellationRequested) { return; } var randomAddress = Bytes <Address> .Random(); var neighborNodes = Nodes.FindNode(randomAddress, 10); var tasks = Array.ConvertAll(neighborNodes, node => P2P.FindNode(randomAddress, Nodes.K, node.IPEndPoint, hasRemoteNode: false, refreshKBucket: true)); var now = DateTime.UtcNow; lock (broadcastIdRecord) { var removeKeys = new List <Bytes <Hash160> >(); foreach (var(id, time) in broadcastIdRecord) { if (now - time >= broadcastTimeout) { removeKeys.Add(id); } else { break; } } foreach (var id in removeKeys) { broadcastIdRecord.Remove(id); } } await tasks.WhenAll(); }, null, refreshKBucketTimeSpan, refreshKBucketTimeSpan);
public KafkaController(ProducerSystem _producerSystem) { producerSystem = _producerSystem; producerActor = AkkaLoad.ActorSelect("producerActor"); }