예제 #1
0
 public ThinClientConnection(WtcSocket socket, PipeStream stream, ThinSvcType svcType, int svcPort, bool isShareDisabled, ThinServerCaps caps, bool runInspect, string otpTicket, string inspectTicket,
                             string watermarkStr1, string watermarkStr2, ThinClientMiscParams misc)
 {
     Socket          = socket;
     Stream          = stream;
     SvcType         = svcType;
     SvcPort         = svcPort;
     IsShareDisabled = isShareDisabled;
     Caps            = caps;
     RunInspect      = runInspect;
     OtpTicket       = otpTicket;
     InspectTicket   = inspectTicket;
     WatermarkStr1   = watermarkStr1._NonNull();
     WatermarkStr2   = watermarkStr2._NonNull();
     this.Misc       = misc;
 }
예제 #2
0
    public async Task <WtcSocket> WideClientConnectAsync(string pcid, WideTunnelClientOptions clientOptions, bool noCache, CancellationToken cancel = default)
    {
        bool retryFlag = false;

L_RETRY:
        WtConnectParam connectParam = await WideClientConnectInnerAsync(pcid, clientOptions, noCache, cancel);

        $"WideClientConnect: pcid {pcid}: Redirecting to {connectParam.HostName}:{connectParam.Port} (CacheUsed = {connectParam.CacheUsed}) ..."._Debug();

        try
        {
            ConnSock tcpSock = await this.TcpIp.ConnectAsync(new TcpConnectParam(connectParam.HostName, connectParam.Port, AddressFamily.InterNetwork, connectTimeout : CoresConfig.WtcConfig.WpcTimeoutMsec, dnsTimeout : CoresConfig.WtcConfig.WpcTimeoutMsec), cancel);

            try
            {
                ConnSock targetSock = tcpSock;

                try
                {
                    PalSslClientAuthenticationOptions sslOptions = new PalSslClientAuthenticationOptions(connectParam.HostName, false, (cert) => this.CheckValidationCallback(this, cert.NativeCertificate, null, SslPolicyErrors.None));

                    SslSock sslSock = new SslSock(tcpSock);
                    try
                    {
                        await sslSock.StartSslClientAsync(sslOptions, cancel);

                        targetSock = sslSock;
                    }
                    catch
                    {
                        await sslSock._DisposeSafeAsync();

                        throw;
                    }

                    WtcSocket wtcSocket = new WtcSocket(targetSock, new WtcOptions(this, connectParam));

                    await wtcSocket.StartWtcAsync(cancel);

                    return(wtcSocket);
                }
                catch
                {
                    await targetSock._DisposeSafeAsync();

                    throw;
                }
            }
            catch
            {
                await tcpSock._DisposeSafeAsync();

                throw;
            }
        }
        catch
        {
            if (connectParam.CacheUsed && retryFlag == false)
            {
                retryFlag = true;

                // 接続キャッシュを使用して接続することに失敗した
                // 場合はキャッシュを消去して再試行する
                WideTunnel.ConnectParamCache.Delete(pcid);

                $"WideClientConnect: pcid {pcid}: Connect with Session Cache Failed. Retrying..."._Debug();
                goto L_RETRY;
            }

            throw;
        }
    }