示例#1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ConnectionKey"/> class.
 /// </summary>
 /// <param name="username">The username associated with the connection.</param>
 /// <param name="ipAddress">The IP address of the connection.</param>
 /// <param name="port">The port of the connection.</param>
 /// <param name="type">The connection type.</param>
 public ConnectionKey(string username, IPAddress ipAddress, int port, MessageConnectionType type)
 {
     Username  = username;
     IPAddress = ipAddress;
     Port      = port;
     Type      = type;
 }
示例#2
0
        internal void GetMessageConneciton_Returns_The_Expected_Connection(MessageConnectionType type, string username, IPAddress ipAddress, int port, ConnectionOptions options)
        {
            var c = new ConnectionFactory().GetMessageConnection(type, username, ipAddress, port, options);

            Assert.Equal(ipAddress, c.IPAddress);
            Assert.Equal(port, c.Port);
            Assert.Equal(options, c.Options);
        }
        public void GetConnection_Returns_Expected_IConnection(MessageConnectionType type, string username, IPAddress ip, int port, ConnectionOptions options)
        {
            var f = new MessageConnectionFactory();

            var c = f.GetMessageConnection(type, username, ip, port, options);

            Assert.Equal(type, c.Type);
            Assert.Equal(username, c.Username);
            Assert.Equal(ip, c.IPAddress);
            Assert.Equal(port, c.Port);
            Assert.Equal(options, c.Options);
        }
示例#4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MessageConnection"/> class.
        /// </summary>
        /// <param name="type">The connection type (Peer, Server)</param>
        /// <param name="ipAddress">The remote IP address of the connection.</param>
        /// <param name="port">The remote port of the connection.</param>
        /// <param name="options">The optional options for the connection.</param>
        /// <param name="tcpClient">The optional TcpClient instance to use.</param>
        internal MessageConnection(MessageConnectionType type, IPAddress ipAddress, int port, ConnectionOptions options = null, ITcpClient tcpClient = null)
            : base(ipAddress, port, options, tcpClient)
        {
            Type = type;

            // circumvent the inactivity timer for server connections; this connection is expected to idle.
            if (Type == MessageConnectionType.Server)
            {
                InactivityTimer = null;
            }

            Connected += async(sender, e) =>
            {
                Task.Run(() => ReadContinuouslyAsync()).ForgetButThrowWhenFaulted <ConnectionException>();
                await SendDeferredMessages().ConfigureAwait(false);
            };
        }
示例#5
0
 /// <summary>
 ///     Gets a <see cref="MessageConnection"/> instance.
 /// </summary>
 /// <param name="type">The connection type (Peer, Server)</param>
 /// <param name="username">The username of the peer associated with the connection, if applicable.</param>
 /// <param name="ipAddress">The remote IP address of the connection.</param>
 /// <param name="port">The remote port of the connection.</param>
 /// <param name="options">The optional options for the connection.</param>
 /// <returns>The created Connection.</returns>
 public IMessageConnection GetMessageConnection(MessageConnectionType type, string username, IPAddress ipAddress, int port, ConnectionOptions options = null) => new MessageConnection(type, username, ipAddress, port, options);
示例#6
0
        public void GetHashCode_Matches(string username, IPAddress ipAddress, int port, MessageConnectionType type)
        {
            var a = new ConnectionKey(username, ipAddress, port, type);
            var b = new ConnectionKey(username, ipAddress, port, type);

            Assert.Equal(a.GetHashCode(), b.GetHashCode());
        }
示例#7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MessageConnection"/> class.
 /// </summary>
 /// <param name="type">The connection type (Peer, Server)</param>
 /// <param name="username">The username of the peer associated with the connection, if applicable.</param>
 /// <param name="ipAddress">The remote IP address of the connection.</param>
 /// <param name="port">The remote port of the connection.</param>
 /// <param name="options">The optional options for the connection.</param>
 /// <param name="tcpClient">The optional TcpClient instance to use.</param>
 internal MessageConnection(MessageConnectionType type, string username, IPAddress ipAddress, int port, ConnectionOptions options = null, ITcpClient tcpClient = null)
     : this(type, ipAddress, port, options, tcpClient)
 {
     Username = username;
 }