Ejemplo n.º 1
0
    public void Insert(IntroducerInfo info)
    {
        db.Open();

        string query = "INSERT INTO [dbo].[Introducer] ( [IntroducerCode] "
                       + ",[IntroducerName] "
                       + ",[IntroducerWorkerID] "
                       + ",[CreateUser] "
                       + ",[CreateDate] "
                       + ",[LastModifyUser] "
                       + ",[LastModifyDate] "
                       + ") "
                       + "VALUES ( @IntroducerCode "
                       + ",@IntroducerName "
                       + ",@IntroducerWorkerID "
                       + ",@CreateUser "
                       + ",@CreateDate "
                       + ",@LastModifyUser "
                       + ",@LastModifyDate "
                       + ") ";


        db.Execute(query, info);
        db.Close();
    }
Ejemplo n.º 2
0
        internal void IntroductionRelayOffered(IntroducerInfo intro)
        {
            if (!RouterContext.Inst.IsFirewalled)
            {
                return;
            }

            Logging.LogTransport($"SSU Introduction: Added introducer {intro.Host}, {intro.IntroKey}, {intro.IntroTag}, {intro.EndPoint}");

            switch (GatherIntroducersState)
            {
            case GatherIntroducersStates.Startup:
                ConsiderUpdateIntroducers.Do(() =>
                {
                    var intros = SelectIntroducers()
                                 .Select(p => p.Left.RemoteIntroducerInfo);

                    if (intros.Any())
                    {
                        SetIntroducers(intros);
                        ConsiderUpdateIntroducers.Frequency = TickSpan.Minutes(10);
                        GatherIntroducersState = GatherIntroducersStates.Established;
                    }
                });
                break;

            case GatherIntroducersStates.Established:
                ConsiderUpdateIntroducers.Do(() =>
                {
                    SetIntroducers(SelectIntroducers()
                                   .Select(p => p.Left.RemoteIntroducerInfo));
                });
                break;
            }
        }
Ejemplo n.º 3
0
        // Session to introducer
        internal SSUSession(SSUHost owner, IPEndPoint remoteep, IntroducerInfo ii, IMTUProvider mtup, RouterContext rc)
        {
            Host            = owner;
            RemoteEP        = remoteep;
            MTUProvider     = mtup;
            MyRouterContext = rc;

            RemoteAddr = new I2PRouterAddress(ii.Host, ii.Port, 0, "SSU");

            // TODO: This is what PurpleI2P does. Seems strange... But there is no RouterInfo available for introducer sessions.
            RemoteRouter = MyRouterContext.MyRouterIdentity;

            TransportInstance = Interlocked.Increment(ref NTCPClient.TransportInstanceCounter);

#if LOG_ALL_TRANSPORT
            DebugUtils.LogDebug("SSUSession: " + DebugId + " Introducer instance created.");
#endif

            Fragmenter = new DataFragmenter();

            if (RemoteAddr == null)
            {
                throw new NullReferenceException("SSUSession needs an address");
            }

            IntroKey = ii.IntroKey;

            MTU = MTUProvider.GetMTU(remoteep);
        }
Ejemplo n.º 4
0
    public bool IsExisted(IntroducerInfo info)
    {
        db.Open();
        String query = "select count(*)  from Introducer "
                       + " where IntroducerCode = @IntroducerCode ";
        var obj = (List <int>)db.Query <int>(query, info);

        db.Close();
        return(obj[0] > 0);
    }
Ejemplo n.º 5
0
 public void Save(IntroducerInfo info)
 {
     if (this.IsExisted(info))
     {
         this.Update(info);
     }
     else
     {
         this.Insert(info);
     }
 }
Ejemplo n.º 6
0
        internal RelayRequestState(SSUSession sess, IList <IntroducerInfo> introducers) : base(sess)
        {
            Introducers = introducers;

            if (Introducers.Count == 0)
            {
                throw new FailedToConnectException("SSU +{Session.TransportInstance}+ Failed to find a non established introducer");
            }
            else
            {
                CurrentIntroducer = Introducers[0];
                Introducers.RemoveAt(0);

                Session.Host.RelayResponseReceived += new SSUHost.RelayResponseInfo(Host_RelayResponseReceived);
            }
        }
Ejemplo n.º 7
0
    public void Update(IntroducerInfo info)
    {
        db.Open();

        string query = " UPDATE [dbo].[Introducer] SET  "
                       + " [IntroducerName] = @IntroducerName "
                       + ", [IntroducerWorkerID] = @IntroducerWorkerID "
                       + ", [CreateUser] = @CreateUser "
                       + ", [CreateDate] = @CreateDate "
                       + ", [LastModifyUser] = @LastModifyUser "
                       + ", [LastModifyDate] = @LastModifyDate "
                       + " where IntroducerCode = @IntroducerCode ";


        db.Execute(query, info);
        db.Close();
    }
Ejemplo n.º 8
0
        public override SSUState Run()
        {
            if (NextState != null)
            {
                Session.Host.RelayResponseReceived -= Host_RelayResponseReceived;
                return(NextState);
            }

            if (Timeout(HandshakeStateTimeoutSeconds))
            {
                Session.Host.RelayResponseReceived -= Host_RelayResponseReceived;
                throw new FailedToConnectException("SSU RelayRequestState {Session.DebugId} Failed to connect. Timeout.");
            }

            ResendRelayRequestAction.Do(() =>
            {
                if (++Retries > RelayRequestStateMaxRetries)
                {
                    Logging.LogTransport($"SSU RelayRequestState: {Session.DebugId}" +
                                         $" Using introducer '{CurrentIntroducer.EndPoint}' timed out.");

                    if (Introducers.Count == 0)
                    {
                        Session.Host.RelayResponseReceived -= Host_RelayResponseReceived;
                        throw new FailedToConnectException($"SSU +{Session.TransportInstance}+ Failed to find a non established introducer");
                    }
                    else
                    {
                        CurrentIntroducer = Introducers[0];
                        Introducers.RemoveAt(0);

                        Logging.LogTransport($"SSU RelayRequestState: +{Session.TransportInstance}+ " +
                                             $"Trying introducer '{CurrentIntroducer.EndPoint}' next.");

                        Retries = 0;
                    }
                }

                SendRelayRequest();
            });

            return(this);
        }
Ejemplo n.º 9
0
        internal void IntroductionRelayOffered(IntroducerInfo intro)
        {
            if (!RouterContext.Inst.IsFirewalled)
            {
                if (CurrentIntroducers.Count() == 0)
                {
                    MyRouterContext.NoIntroducers();
                }
                return;
            }

            if (CurrentIntroducers.Count() >= 3)
            {
                return;
            }

            CurrentIntroducers.Set(intro.Host, intro);
            MyRouterContext.SetIntroducers(CurrentIntroducers.Select(i => i.Value));
        }
Ejemplo n.º 10
0
        internal void IntroductionRelayOffered(IntroducerInfo intro)
        {
            if (!RouterContext.Inst.IsFirewalled)
            {
                if (!CurrentIntroducers.Any())
                {
                    MyRouterContext.NoIntroducers();
                }
                return;
            }

            if (CurrentIntroducers.Count() >= 5)
            {
                return;
            }

            Logging.LogTransport($"SSU Introduction: Added introducer {intro.Host}, {intro.IntroKey}, {intro.IntroTag}, {intro.EndPoint}");
            CurrentIntroducers.Set(intro.Host, intro);
            MyRouterContext.SetIntroducers(CurrentIntroducers.Select(i => i.Value));
        }
Ejemplo n.º 11
0
        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);
        }