public NetworkPoolDecrypt(NetworkPoolListener listener, long identifier, NetworkIncomingBuffer buffer, NetworkIncomingMessageHandler handler, int count) { this.listener = listener; this.identifier = identifier; this.buffer = buffer; this.handler = handler; this.count = count; }
/// <summary> /// Creates a new instance of the network incoming buffer relying on the already /// connected socket instance. The buffer does not decrypt anything. /// </summary> /// <param name="listener">The listener who knows the pool.</param> /// <param name="socket">The already connected socket.</param> /// <param name="identifier">The unique connection identifier.</param> public NetworkIncomingBuffer(NetworkPoolListener listener, TcpSocket socket, long identifier) { this.listener = listener; this.socket = socket; this.identifier = identifier; memory = listener.Allocate(); }
/// <summary> /// Creates a new instance of the network outgoing buffer relying on the already /// connected socket instance. The buffer does not encrypt anything. /// </summary> /// <param name="listener">The listener who knows the pool.</param> /// <param name="socket">The already connected socket.</param> /// <param name="identifier">The unique connection identifier.</param> public NetworkOutgoingBuffer(NetworkPoolListener listener, TcpSocket socket, long identifier) { this.listener = listener; this.socket = socket; this.identifier = identifier; memory = listener.Allocate(); parts = new HashSet <int>(); }
/// <summary> /// Creates a new instance of the network connection from the existing /// instance. The inner socket and direction will copied, but the caller /// can decide how the encryption and decryption will work. /// </summary> /// <param name="connection">The existing instance of the connection.</param> /// <param name="configurer">The new configuration.</param> public NetworkPoolConnection(NetworkPoolConnection connection, NetworkConfiguration configurer) { listener = connection.listener; socket = connection.socket; remote = connection.remote; direction = connection.direction; identifier = connection.identifier; incoming = new NetworkIncomingBuffer(connection.incoming, configurer.Decryptor); outgoing = new NetworkOutgoingBuffer(connection.outgoing, configurer.Encryptor); }
/// <summary> /// Creates a new instance of the network connection relying on the /// already connected socket instance and direction value indicating /// who is the initiator of the connection. /// </summary> /// <param name="listener"></param> /// <param name="socket">The already connected socket.</param> /// <param name="direction">The direction indicating who initiated the connection.</param> /// <param name="identifier"></param> public NetworkPoolConnection(NetworkPoolListener listener, TcpSocket socket, NetworkDirection direction, long identifier, IPEndPoint remote) { this.listener = listener; this.socket = socket; this.direction = direction; this.identifier = identifier; this.remote = NetworkAddress.Parse(remote); incoming = new NetworkIncomingBuffer(listener, socket, identifier); outgoing = new NetworkOutgoingBuffer(listener, socket, identifier); }
/// <summary> /// Creates a new instance of the network outgoing buffer from the existing instance. /// The inner socket and the already downloaded and waiting data will be /// copied, but the caller can change the encryption algorithm. /// </summary> /// <param name="buffer">The existing instance of the newtwork buffer.</param> /// <param name="encryptor">The new encryptor.</param> public NetworkOutgoingBuffer(NetworkOutgoingBuffer buffer, NetworkOutgoingEncryptor encryptor) { this.encryptor = encryptor; listener = buffer.listener; socket = buffer.socket; identifier = buffer.identifier; memory = buffer.memory; offset = buffer.offset; parts = buffer.parts; encryptor?.Encrypt(memory.Data, 0, offset); }
/// <summary> /// Creates a new instance of the network incoming buffer from the existing instance. /// The inner socket and the already downloaded and waiting data will be /// copied, but the caller can change the decryption algorithm. /// </summary> /// <param name="buffer">The existing instance of the newtwork buffer.</param> /// <param name="decryptor">The new decryptor.</param> public NetworkIncomingBuffer(NetworkIncomingBuffer buffer, NetworkIncomingDecryptor decryptor) { this.decryptor = decryptor; listener = buffer.listener; socket = buffer.socket; identifier = buffer.identifier; memory = buffer.memory; length = buffer.length; offset = buffer.offset; Decrypt(offset, length); }
public NetworkConnection Create(TcpSocket socket, NetworkDirection direction, IPEndPoint remote) { long identifier = Interlocked.Increment(ref sequence); NetworkPoolListener listener = new NetworkPoolListener(items, queue, hooks, configuration, dependencies); NetworkPoolConnection connection = new NetworkPoolConnection(listener, socket, direction, identifier, remote); lock (items) { items.Add(identifier, new NetworkPoolEntry { Connection = connection, IsAvailable = true }); } hooks.CallConnectionAttached(connection); return(connection); }