示例#1
0
        protected override Task OnConnectionResult(ConnectResultBase resultBase)
        {
            if (!resultBase.Ok)
            {
                SetConnectResponse(new ConnectResult(resultBase.Adapter, ConnectResultEnum.Failed)
                {
                    FailedReason = resultBase.FailedReason
                });
                return(NaiveUtils.CompletedTask);
            }
            var result = (ConnectResult)resultBase;

            if (result.Stream == null)
            {
                var lo = new LoopbackStream();
                DataStream    = lo;
                result.Stream = lo.Another;
                SetConnectResponse(result);
                return(NaiveUtils.CompletedTask);
            }
            else
            {
                SetConnectResponse(result);
                tcsConnectionFinish = new TaskCompletionSource <VoidType>();
                return(tcsConnectionFinish.Task);
            }
        }
示例#2
0
 protected override async Task OnConnectionResult(ConnectResultBase result)
 {
     if (socks5svr != null)
     {
         var tmp = socks5svr;
         socks5svr = null;
         await tmp.WriteConnectionResult(new IPEndPoint(0, Dest.Port), (result.Ok)?Socks5Server.Rep.succeeded : Socks5Server.Rep.Connection_refused);
     }
     await base.OnConnectionResult(result);
 }
示例#3
0
 protected override async Task OnConnectionResult(ConnectResultBase result)
 {
     if (result is ConnectResult cr)
     {
         DataStream = await _onConnectionCallback(cr);
     }
     else
     {
         await _onConnectionCallback(new ConnectResult(null, ConnectResultEnum.Failed));
     }
     await base.OnConnectionResult(result);
 }
示例#4
0
        public virtual Task SetResult(ConnectResultBase result)
        {
            if (IsHandled)
            {
                throw new InvalidOperationException("the Connection has been already handled.");
            }
            IsHandled = true;
            var handlingAdapter = result.Adapter?.GetAdapter();

            if (handlingAdapter != null)
            {
                System.Threading.Interlocked.Increment(ref handlingAdapter.HandledConnections);
            }
            this.ConnectResult = result;
            return(OnConnectionResult(result));
        }
示例#5
0
 protected override async Task OnConnectionResult(ConnectResultBase result)
 {
     if (result.Ok)
     {
         var r = (ConnectResult)result;
         if (r.Stream != null)
         {
             var handler = r.Adapter;
             var copier  = new MyStream.TwoWayCopier(r.Stream, DataStream)
             {
                 WhenCanReadFromLeft = r.WhenCanRead,
                 Logger = new Logger("->" + handler.Name, InAdapter.GetAdapter().Logger)
             };
             copier.SetCounters(handler.GetAdapter().BytesCountersRW, this.BytesCountersRW);
             EnsureSniffer();
             Sniffer.ListenToCopier(copier.CopierFromRight, copier.CopierFromLeft);
             await copier.Run();
         }
     }
 }
示例#6
0
 protected virtual Task OnConnectionResult(ConnectResultBase result)
 {
     return(NaiveUtils.CompletedTask);
 }