コード例 #1
0
 public SessionConfirmedState(SSUSession sess, SessionRequestState req)
     : base(sess)
 {
     Request = req;
 }
コード例 #2
0
ファイル: SSUSession.cs プロジェクト: glasgowdev/i2p-cs
        public void Connect()
        {
            // This instance was initiated as an incomming connection.
            // Do not change state as we might be in a handshake.
            if (IntroKey == null)
            {
                return;
            }

            if (ConnectCalled)
            {
                return;
            }
            ConnectCalled = true;

            // TODO: Add introducer request
            if (!RemoteAddr.Options.Contains("host") || !RemoteAddr.Options.Contains("port"))
            {
#if LOG_ALL_TRANSPORT
                DebugUtils.LogDebug("SSUSession: Connect " + DebugId + ": No host info. Trying introducers.");
#endif
                if (!RemoteAddr.Options.Contains("ihost0") || !RemoteAddr.Options.Contains("iport0") || !RemoteAddr.Options.Contains("ikey0"))
                {
#if LOG_ALL_TRANSPORT
                    DebugUtils.LogDebug("SSUSession: Connect +" + TransportInstance.ToString() + "+: No introducers declared.");
#endif
                    throw new FailedToConnectException("SSU Introducer required, but no introducer information available");
                }

                var introducers = new List <IntroducerInfo>();

                for (int i = 0; i < 3; ++i)
                {
                    if (!RemoteAddr.Options.Contains($"ihost{i}"))
                    {
                        break;
                    }
                    if (!RemoteAddr.Options.Contains($"iport{i}"))
                    {
                        break;
                    }
                    if (!RemoteAddr.Options.Contains($"ikey{i}"))
                    {
                        break;
                    }
                    if (!RemoteAddr.Options.Contains($"itag{i}"))
                    {
                        DebugUtils.LogWarning(
                            $"SSUSession: Connect +{TransportInstance}+: itag# not present! {RemoteAddr.Options}");
                        break;
                    }

                    if (!RemoteAddr.Options[$"ihost{i}"].Contains('.'))
                    {
                        break;                                                      // TODO: Support IPV6
                    }
                    //DebugUtils.LogWarning( "SSUSession: Connect " + DebugId + ": " + RemoteAddr.Options.ToString() );

                    var intro = new IntroducerInfo(RemoteAddr.Options[$"ihost{i}"],
                                                   RemoteAddr.Options[$"iport{i}"],
                                                   RemoteAddr.Options[$"ikey{i}"],
                                                   RemoteAddr.Options[$"itag{i}"]);

#if LOG_ALL_TRANSPORT
                    DebugUtils.LogDebug("SSUSession: Connect +" + TransportInstance.ToString() + "+: Adding introducer '" +
                                        intro.EndPoint.ToString() + "'.");
#endif
                    introducers.Add(intro);
                }

                if (introducers.Count == 0)
                {
#if LOG_ALL_TRANSPORT
                    DebugUtils.LogDebug("SSUSession: Connect +" + TransportInstance.ToString() + "+: Ended up with no introducers.");
#endif
                    throw new FailedToConnectException("SSU Introducer required, but no valid introducer information available");
                }

                CurrentState = new RelayRequestState(this, introducers);
            }
            else
            {
                CurrentState = new SessionRequestState(this);
            }

            Host.NeedCpu(this);
        }