public override async Task <int> ReadAsync(ArraySegment <byte> buffer, CancellationToken cancellationToken = new CancellationToken()) { int len = await WrappedSocket.ReadAsync(buffer, cancellationToken); _data.BytesRead += len; return(len); }
private void Connect() { try { var ipAddress = Global.OSSupportsLocalIPv6 ? IPAddress.IPv6Loopback : IPAddress.Loopback; var remoteEp = new IPEndPoint(ipAddress, _targetPort); _remote = new WrappedSocket(); // Connect to the remote endpoint. _remote.BeginConnect(remoteEp, ConnectCallback, null); } catch (Exception e) { Logging.LogUsefulException(e); Close(); } }
private async Task ReadBytesAsync(ArraySegment <byte> result, CancellationToken cancellationToken = default(CancellationToken)) { int count = result.Count; do { int num = await WrappedSocket.ReadAsync(result, cancellationToken).ConfigureAwait(false); if (num != 0) { count -= num; } else { throw new EndOfStreamException("Unexpected end of stream while trying to read crypto packet!"); } } while (count > 0); }
public void Start(byte[] firstPacket, int length, Socket socket, int targetPort) { _firstPacket = firstPacket; _firstPacketLength = length; _local = socket; try { EndPoint remoteEP = SocketUtil.GetEndPoint("127.0.0.1", targetPort); // 连接到远程端点 _remote = new WrappedSocket(); _remote.BeginConnect(remoteEP, ConnectCallback, null); } catch (Exception e) { Logging.LogUsefulException(e); Close(); } }
public void Start(byte[] firstPacket, int length, Socket socket, int targetPort) { _firstPacket = firstPacket; _firstPacketLength = length; _local = socket; try { // Local Port Forward use IP as is EndPoint remoteEP = SocketUtil.GetEndPoint(_local.AddressFamily == AddressFamily.InterNetworkV6 ? "[::1]" : "127.0.0.1", targetPort); // Connect to the remote endpoint. _remote = new WrappedSocket(); _remote.BeginConnect(remoteEP, ConnectCallback, null); } catch (Exception e) { logger.LogUsefulException(e); Close(); } }
public override Task WriteAsync(ArraySegment <byte> buffer, CancellationToken cancellationToken = new CancellationToken()) { var buf = ArrayPool <byte> .Shared.Rent(buffer.Count + 20); var ctext = new ArraySegment <byte>(buf, 20, buffer.Count); var tag = new ArraySegment <byte>(buf, 4, 16); BitConverter.TryWriteBytes(new ArraySegment <byte>(buf, 0, 4), buffer.Count); lock (_writeNonce) { _aes.Encrypt(_writeNonce, buffer, ctext, tag); IncrementNonce(_writeNonce); } async Task Send() { await WrappedSocket.WriteAsync(new ArraySegment <byte>(buf, 0, buffer.Count + 20), cancellationToken); ArrayPool <byte> .Shared.Return(buf); } return(Send()); }
public override Task WriteAsync(ArraySegment <byte> buffer, CancellationToken cancellationToken = new CancellationToken()) { _data.BytesWritten += buffer.Count; return(WrappedSocket.WriteAsync(buffer, cancellationToken)); }
public override Task CloseAsync() { return(WrappedSocket.CloseAsync()); }
public override Task CloseAsync() { Console.WriteLine("Socket Closed"); return(WrappedSocket.CloseAsync()); }
public HttpHandler(ShadowsocksController controller, Configuration config, TCPRelay tcprelay, Socket socket) : base(controller, config, tcprelay, socket) { _localSocket = new WrappedSocket(socket); }