Exemplo n.º 1
0
        internal MeshServer(MeshSettings settings, string ip, int port, bool ssl, string pfxCertFile, string pfxCertPass)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (String.IsNullOrEmpty(ip))
            {
                throw new ArgumentNullException(nameof(ip));
            }
            if (port < 0)
            {
                throw new ArgumentException("Port must be zero or greater.");
            }

            _Settings               = settings;
            _Ip                     = ip;
            _Port                   = port;
            _IpPort                 = ip + ":" + port;
            _Ssl                    = ssl;
            _PfxCertificateFile     = pfxCertFile;
            _PfxCertificatePassword = pfxCertPass;

            List <string> localIpAddresses = GetLocalIpAddresses();

            if (_Ip.Equals("127.0.0.1"))
            {
                Logger?.Invoke("[MeshServer] Loopback IP address detected; only connections from local machine will be accepted");
            }
            else
            {
                if (!localIpAddresses.Contains(_Ip))
                {
                    Logger?.Invoke("[MeshServer] Specified IP address '" + _Ip + "' not found in local IP address list:");
                    foreach (string curr in localIpAddresses)
                    {
                        Logger?.Invoke("  " + curr);
                    }
                    throw new ArgumentException("IP address must either be 127.0.0.1 or the IP address of a local network interface.");
                }
            }

            if (_Ssl)
            {
                Logger?.Invoke("[MeshServer] Initialized TCP server with SSL on IP:port " + _IpPort);
            }
            else
            {
                Logger?.Invoke("[MeshServer] Initialized TCP server on IP:port " + _IpPort);
            }
        }
Exemplo n.º 2
0
        internal MeshClient(MeshSettings settings, MeshPeer peer)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (peer == null)
            {
                throw new ArgumentNullException(nameof(peer));
            }

            _Settings = settings;
            PeerNode  = peer;

            Logger?.Invoke("[MeshClient] Initialized to connect to " + PeerNode.IpPort);
        }