예제 #1
0
        public LocalNode(INetworkListenerLoop networkListenerLoop,
                         IUPnPPortForwarder portForwarder,
                         ILocalIpAddressDiscoverer localIpAddressDiscoverer,
                         RemoteNode.Factory remoteNodeFactory,
                         IPeerTracker peerTracker,
                         ClientSettings clientSettings)
        {
            _uPnPPortForwarder = portForwarder;
            _peerTracker       = peerTracker;

            _networkListenerLoop = networkListenerLoop;
            _networkListenerLoop.ConnectionEstablished += HandleConnectionEstablished;

            _clientSettings    = clientSettings;
            _remoteNodeFactory = remoteNodeFactory;

            if (_clientSettings.BlockChainNetSettings.Net == "LocalNet")
            {
                _seedNodeEndPoint = new IPEndPoint(IPAddress.Parse(localIpAddressDiscoverer.GetLocalIpAddress()), _clientSettings.ListenPort);
            }
            int port = _clientSettings.BlockChainNetSettings?.ListenPortOverride ?? _clientSettings.ListenPort;

            LocalAddress = new IPEndPoint(IPAddress.Parse(localIpAddressDiscoverer.GetLocalIpAddress()), port);

            Console.WriteLine($"Started Listening on {LocalAddress.Address}:{LocalAddress.Port}");
            Console.WriteLine();
        }
예제 #2
0
        public PeerTracker(ILocalIpAddressDiscoverer localIpAddressDiscoverer, ClientSettings clientSettings, RemoteNode.Factory remoteNodeFactory, ILoggerFactory loggerFactory)
        {
            _random            = new Random();
            _clientSettings    = clientSettings;
            _localIpEndpoint   = new IPEndPoint(IPAddress.Parse(localIpAddressDiscoverer.GetLocalIpAddress()), _clientSettings.BlockChainNetSettings.UdpPort);
            _trackedPeers      = new ConcurrentDictionary <string, IRemoteNode>();
            _remoteNodeFactory = remoteNodeFactory;
            _logger            = loggerFactory.CreateLogger <PeerTracker>();

            foreach (var peer in _clientSettings.BlockChainNetSettings.SeedPeers)
            {
                IPAddress[] addresslist = Dns.GetHostAddresses(peer);
                TryAddPeer(new IPEndPoint(addresslist[0], 7075));
            }
        }
예제 #3
0
        public LocalNode(
            INetworkListenerLoop networkListenerLoop,
            IUPnPPortForwarder portForwarder,
            ILocalIpAddressDiscoverer localIpAddressDiscoverer,
            RemoteNode.Factory remoteNodeFactory,
            IPeerTracker peerTracker,
            IPacketSender packetSender,
            ILoggerFactory loggerFactory,
            IMessageDispatcher messageDispatcher,
            ClientSettings clientSettings)
        {
            _logger = loggerFactory.CreateLogger <LocalNode>();

            _uPnPPortForwarder = portForwarder;
            _peerTracker       = peerTracker;

            _packetSender = packetSender;

            _networkListenerLoop = networkListenerLoop;
            //_networkListenerLoop.TcpConnectionEstablished += HandleConnectionEstablished;
            _networkListenerLoop.DatagramReceived += HandleDatagramReceived;

            _messageDispatcher = messageDispatcher;

            _clientSettings    = clientSettings;
            _remoteNodeFactory = remoteNodeFactory;

            int port = _clientSettings.BlockChainNetSettings.TcpPort;

            LocalAddress = new IPEndPoint(IPAddress.Parse(localIpAddressDiscoverer.GetLocalIpAddress()), port);

            _logger.LogInformation($"Started Listening on {LocalAddress.Address}:{LocalAddress.Port}");

            _keepAliveTimer = new Timer(BroadcastKeepAliveMessages, null, 0, _clientSettings.KeepAliveTimeout * 1000);


            _messageHeader              = new MessageHeader();
            _messageHeader.Extensions   = new byte[2];
            _messageHeader.VersionMax   = 5;
            _messageHeader.VersionMin   = 1;
            _messageHeader.VersionUsing = 5;
            _messageHeader.Type         = MessageType.Keepalive;
        }