Example #1
0
        public void Modify()
        {
            TunnelInfo model = new TunnelInfo()
            {
                Id                  = new Guid("2801AF69-57DD-4AF0-8206-CDEE68ACE2F1"),
                TunnelCode          = "111",
                EntranceStation     = "111",
                TunnelLength        = "212",
                TunnelHeight        = "12",
                HoleType            = "212",
                HighwayGrade        = "121",
                CompletionTime      = DateTime.Now,
                RodeType            = "666",
                TunnelVentilation   = "666",
                ConstructionCompany = "66",
                DesignSpeed         = "66",
                TunnelName          = "66",
                TunnelType          = 3,
                TunnelWidth         = "66",
                AddTime             = DateTime.Now
            };
            var result = tunnelInfoService.Modify(model);

            Assert.True(result);
        }
Example #2
0
 public TunnelConfig(TunnelDirection dir, TunnelRole role, TunnelPool pool, TunnelInfo hops)
 {
     Direction = dir;
     Role      = role;
     Pool      = pool;
     Info      = hops;
 }
Example #3
0
        public void Add()
        {
            TunnelInfo model = new TunnelInfo()
            {
                Id                  = Guid.NewGuid(),
                TunnelCode          = "111",
                EntranceStation     = "111",
                TunnelLength        = "212",
                TunnelHeight        = "12",
                HoleType            = "212",
                HighwayGrade        = "121",
                RodeType            = "666",
                TunnelVentilation   = "666",
                CompletionTime      = DateTime.Now,
                ConstructionCompany = "66",
                DesignSpeed         = "66",
                TunnelName          = "66",
                TunnelType          = 3,
                TunnelWidth         = "66",
                AddTime             = DateTime.Now
            };
            var result = tunnelInfoService.Add(model);

            Assert.True(result);
        }
        public TunnelViewModel(TunnelInfo tunnel)
        {
            if (tunnel == null)
            {
                throw new ArgumentNullException("tunnel");
            }

            this.Tunnel = tunnel;
        }
        private void PublishTunnelFailure(TunnelInfo tunnel, string errorMessage)
        {
            this.HasForwardingFailures = true;

            if (this.Observer != null)
            {
                this.Observer.HandleForwardingError(this, tunnel, errorMessage);
            }
        }
Example #6
0
        public OutboundTunnel(TunnelConfig config, int replytunnelhops) : base(config)
        {
            TunnelSetup = config.Info;

            var outtunnel = TunnelSetup.Hops[0];

            NextHop         = outtunnel.Peer.IdentHash;
            SendTunnelId    = outtunnel.TunnelId;
            ReplyTunnelHops = replytunnelhops;
        }
Example #7
0
        private void AddTunnelToList(TunnelInfo tunnel)
        {
            string tunnelTypeAbbr;
            var    remotePort = tunnel.RemotePort.ToString(CultureInfo.InvariantCulture);

            switch (tunnel.Type)
            {
            case TunnelType.Local:
                tunnelTypeAbbr = "L";
                break;

            case TunnelType.Remote:
                tunnelTypeAbbr = "R";
                break;

            case TunnelType.Dynamic:
                tunnelTypeAbbr = "D";
                remotePort     = "";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var row = new DataGridViewRow();

            row.Cells.Add(
                new DataGridViewTextBoxCell
            {
                Value = tunnel.Name
            });
            row.Cells.Add(
                new DataGridViewTextBoxCell
            {
                Value = tunnelTypeAbbr
            });
            row.Cells.Add(
                new DataGridViewTextBoxCell
            {
                Value = tunnel.LocalPort
            });
            row.Cells.Add(
                new DataGridViewTextBoxCell
            {
                Value = tunnel.RemoteHostName
            });
            row.Cells.Add(
                new DataGridViewTextBoxCell
            {
                Value = remotePort
            });
            row.Tag = tunnel;
            this.tunnelsGridView.Rows.Add(row);
        }
Example #8
0
        public ResultModel <string> Modify(TunnelInfo model)
        {
            var result = new ResultModel <string>();

            result.Success = tunnelInfoService.Modify(model);
            if (result.Success)
            {
                result.Msg = "修改成功";
            }
            else
            {
                result.Msg = "修改失败";
            }
            return(result);
        }
Example #9
0
        public ResultModel <string> Add(TunnelInfo model)
        {
            model.AddTime = DateTime.Now;
            model.IsDel   = false;
            var result = new ResultModel <string>();

            result.Success = tunnelInfoService.Add(model);
            if (result.Success)
            {
                result.Msg = "添加成功";
            }
            else
            {
                result.Msg = "添加失败";
            }
            return(result);
        }
Example #10
0
        private OutboundTunnel CreateOutboundTunnel(IClient client, TunnelInfo prototype)
        {
            var config = new TunnelConfig(
                TunnelConfig.TunnelDirection.Outbound,
                TunnelConfig.TunnelPool.Client,
                prototype ?? CreateOutgoingTunnelChain(client));

            var tunnel = (OutboundTunnel)TunnelMgr.CreateTunnel(this, config);

            if (tunnel != null)
            {
                TunnelMgr.AddTunnel(tunnel);
                client.AddOutboundPending(tunnel);
                PendingTunnels[tunnel] = client;
            }
            return(tunnel);
        }
Example #11
0
        private OutboundTunnel CreateOutboundTunnel(ClientDestination dest, TunnelInfo prototype)
        {
            var config = new TunnelConfig(
                TunnelConfig.TunnelDirection.Outbound,
                TunnelConfig.TunnelPool.Client,
                prototype == null ? CreateOutgoingTunnelChain(dest): prototype);

            var tunnel = (OutboundTunnel)TunnelMgr.CreateTunnel(config);

            if (tunnel != null)
            {
                TunnelMgr.AddTunnel(tunnel);
                dest.AddOutboundPending(tunnel);
                lock (Destinations) Destinations[tunnel] = dest;
            }
            return(tunnel);
        }
        void IConnectionManagerObserver.HandleForwardingError(ConnectionInfo sender, TunnelInfo tunnel, string errorMessage)
        {
            if (!this.IsActiveConnection(sender))
            {
                return;
            }

            var message = string.Format(
                @"Local port {0} forwarding to {1}:{2} failed: {3}",
                tunnel.LocalPort,
                tunnel.RemoteHostName,
                tunnel.RemotePort,
                errorMessage);

            this.viewModel.AddLogMessage(MessageSeverity.Warn, message);
            this.View.AddLogMessage(MessageSeverity.Warn, message);
            this.View.RenderTunnelError(tunnel, errorMessage);
        }
Example #13
0
        private InboundTunnel CreateInboundTunnel(ClientDestination dest, TunnelInfo prototype)
        {
            var config = new TunnelConfig(
                TunnelConfig.TunnelDirection.Inbound,
                TunnelConfig.TunnelPool.Client,
                prototype == null ? CreateIncommingTunnelChain(dest): prototype);

            var tunnel = (InboundTunnel)TunnelMgr.CreateTunnel(config);

            if (tunnel != null)
            {
                tunnel.GarlicMessageReceived += new Action <GarlicMessage>(tunnel_GarlicMessageReceived);
                TunnelMgr.AddTunnel(tunnel);
                dest.AddInboundPending(tunnel);
                lock (Destinations) Destinations[tunnel] = dest;
            }
            return(tunnel);
        }
Example #14
0
        private InboundTunnel CreateInboundTunnel(IClient client, TunnelInfo prototype)
        {
            var config = new TunnelConfig(
                TunnelConfig.TunnelDirection.Inbound,
                TunnelConfig.TunnelPool.Client,
                prototype ?? CreateIncommingTunnelChain(client));

            var tunnel = (InboundTunnel)TunnelMgr.CreateTunnel(this, config);

            if (tunnel != null)
            {
                tunnel.GarlicMessageReceived += new Action <GarlicMessage>(GarlicMessageReceived);
                TunnelMgr.AddTunnel(tunnel);
                client.AddInboundPending(tunnel);
                PendingTunnels[tunnel] = client;
            }
            return(tunnel);
        }
Example #15
0
        public InboundTunnel(TunnelConfig config, int outtunnelhops) : base(config)
        {
            if (config != null)
            {
                Fake0HopTunnel = false;
                TunnelSetup    = config.Info;
                OutTunnelHops  = outtunnelhops;

                var gw = TunnelSetup.Hops[0];
                RemoteGateway   = gw.Peer.IdentHash;
                GatewayTunnelId = gw.TunnelId;

                ReceiveTunnelId = TunnelSetup.Hops.Last().TunnelId;

#if LOG_ALL_TUNNEL_TRANSFER
                Logging.LogDebug($"InboundTunnel: Tunnel {Destination.Id32Short} created.");
#endif
            }
            else
            {
                Fake0HopTunnel = true;

                var hops = new List <HopInfo>
                {
                    new HopInfo(RouterContext.Inst.MyRouterIdentity, new I2PTunnelId())
                };
                TunnelSetup = new TunnelInfo(hops);

                Config = new TunnelConfig(
                    TunnelConfig.TunnelDirection.Inbound,
                    TunnelConfig.TunnelPool.Exploratory,
                    TunnelSetup);

                ReceiveTunnelId = TunnelSetup.Hops.Last().TunnelId;
                RemoteGateway   = RouterContext.Inst.MyRouterIdentity.IdentHash;
                GatewayTunnelId = ReceiveTunnelId;

#if LOG_ALL_TUNNEL_TRANSFER
                Logging.LogDebug($"InboundTunnel {TunnelDebugTrace}: 0-hop tunnel {Destination.Id32Short} created.");
#endif
            }
        }
        public static string PuttyTunnelArguments(TunnelInfo tunnel)
        {
            if (tunnel == null)
            {
                throw new ArgumentNullException("tunnel");
            }
            switch (tunnel.Type)
            {
            case TunnelType.Local:
                return(String.Format(@"-L {0}:{1}:{2}", tunnel.LocalPort, tunnel.RemoteHostname, tunnel.RemotePort));

            case TunnelType.Remote:
                throw new NotImplementedException();

            case TunnelType.Dynamic:
                return(String.Format(@"-D {0}", tunnel.LocalPort));

            default:
                throw new FormatException(Resources.ConsoleTools_Error_InvalidTunnelType);
            }
        }
Example #17
0
        private static string tunnelArguments(TunnelInfo tunnel)
        {
            if (tunnel == null)
            {
                throw new ArgumentNullException("tunnel");
            }
            switch (tunnel.Type)
            {
            case TunnelType.Local:
                return($@" -L {tunnel.GetLocalHostWithSeparator()}{tunnel.LocalPort}:{tunnel.RemoteHostname}:{tunnel.RemotePort}");

            case TunnelType.Remote:
                return($@" -R {tunnel.GetLocalHostWithSeparator()}{tunnel.LocalPort}:{tunnel.RemoteHostname}:{tunnel.RemotePort}");

            case TunnelType.Dynamic:
                return($@" -D {tunnel.LocalPort}");

            default:
                throw new FormatException(Resources.ConsoleTools_Error_InvalidTunnelType);
            }
        }
Example #18
0
        private void addTunnel(TunnelInfo tunnel)
        {
            var row = new DataGridViewRow();

            row.Cells.Add(new DataGridViewTextBoxCell {
                Value = tunnel.Name
            });
            row.Cells.Add(new DataGridViewTextBoxCell {
                Value = tunnel.Type.ToString()[0]
            });
            row.Cells.Add(new DataGridViewTextBoxCell {
                Value = tunnel.LocalPort
            });
            row.Cells.Add(new DataGridViewTextBoxCell {
                Value = tunnel.RemoteHostname
            });
            row.Cells.Add(new DataGridViewTextBoxCell {
                Value = tunnel.RemotePort
            });
            row.Tag = tunnel;
            tunnelsGridView.Rows.Add(row);
        }
        private static string BuildPuttyTunnelArguments(TunnelInfo tunnel)
        {
            if (tunnel == null)
            {
                throw new ArgumentNullException("tunnel");
            }

            switch (tunnel.Type)
            {
            case TunnelType.Local:
                return(String.Format(@" -L {0}:{1}:{2}", tunnel.LocalPort, tunnel.RemoteHostName, tunnel.RemotePort));

            case TunnelType.Remote:
                return(String.Format(@" -R {0}:{1}:{2}", tunnel.LocalPort, tunnel.RemoteHostName, tunnel.RemotePort));

            case TunnelType.Dynamic:
                return(String.Format(@" -D {0}", tunnel.LocalPort));

            default:
                throw new ArgumentOutOfRangeException("tunnel");
            }
        }
Example #20
0
        private void LoadTunnelInfoInText(TunnelInfo tunnel)
        {
            textBoxTunnelName.Text = tunnel.Name;
            textBoxSourceHost.Text = tunnel.LocalHost;
            textBoxSourcePort.Text = tunnel.LocalPort;
            textBoxDestHost.Text   = tunnel.RemoteHostname;
            textBoxDestPort.Text   = tunnel.RemotePort;
            switch (tunnel.Type)
            {
            case TunnelType.Local:
                radioButtonLocal.Checked = true;
                break;

            case TunnelType.Remote:
                radioButtonRemote.Checked = true;
                break;

            case TunnelType.Dynamic:
                radioButtonDynamic.Checked = true;
                break;
            }
        }
Example #21
0
        private void buttonAddTunnel_Click(object sender, EventArgs e)
        {
            if (!_tunnelValidator.ValidateControls())
            {
                return;
            }

            var name       = textBoxTunnelName.Text;
            var srcPort    = textBoxSourcePort.Text;
            var dstHost    = textBoxDestHost.Text;
            var dstPort    = textBoxDestPort.Text;
            var tunnelType = radioButtonLocal.Checked
                                 ? TunnelType.Local
                                 : (radioButtonRemote.Checked ? TunnelType.Remote : TunnelType.Dynamic);

            var tunnel = new TunnelInfo {
                Name = name, LocalHost = textBoxSourceHost.Text, LocalPort = srcPort, RemoteHostname = dstHost, RemotePort = dstPort, Type = tunnelType
            };

            addTunnel(tunnel);
            Modified = true;
            resetAddTunnelGroup();
        }
Example #22
0
        public void AddTunnel()
        {
            if (!this.tunnelValidator.Validate())
            {
                return;
            }

            var name = this.tunnelNameTextBox.Text;

            var    srcPort    = int.Parse(this.tunnelSrcPortTextBox.Text);
            string dstHost    = null;
            int    dstPort    = 0;
            var    tunnelType = this.tunnelTypeLocalRadioButton.Checked
                ? TunnelType.Local
                : (this.tunnelTypeRemoteRadioButton.Checked
                    ? TunnelType.Remote
                    : TunnelType.Dynamic);

            if (tunnelType != TunnelType.Dynamic)
            {
                dstHost = this.tunnelDstHostTextBox.Text;
                dstPort = int.Parse(this.tunnelDstPortTextBox.Text);
            }

            var tunnel = new TunnelInfo
            {
                Name           = name,
                LocalPort      = srcPort,
                RemoteHostName = dstHost,
                RemotePort     = dstPort,
                Type           = tunnelType
            };

            this.AddTunnelToList(tunnel);
            this.Modified = true;
            this.ResetAddTunnelGroup();
        }
Example #23
0
        public InboundTunnel(TunnelConfig config, int outtunnelhops) : base(config)
        {
            if (config != null)
            {
                Fake0HopTunnel = false;
                TunnelSetup    = config.Info;
                OutTunnelHops  = outtunnelhops;

                var gw = TunnelSetup.Hops[0];
                RemoteGateway   = gw.Peer.IdentHash;
                GatewayTunnelId = gw.TunnelId;

                ReceiveTunnelId = TunnelSetup.Hops.Last().TunnelId;

                DebugUtils.LogDebug("InboundTunnel: Tunnel " + Destination.Id32Short + " created.");
            }
            else
            {
                Fake0HopTunnel = true;

                var hops = new List <HopInfo>();
                hops.Add(new HopInfo(RouterContext.Inst.MyRouterIdentity, new I2PTunnelId()));
                TunnelSetup = new TunnelInfo(hops);

                Config = new TunnelConfig(
                    TunnelConfig.TunnelDirection.Inbound,
                    TunnelConfig.TunnelRole.Endpoint,
                    TunnelConfig.TunnelPool.Exploratory,
                    TunnelSetup);

                ReceiveTunnelId = TunnelSetup.Hops.Last().TunnelId;
                RemoteGateway   = RouterContext.Inst.MyRouterIdentity.IdentHash;
                GatewayTunnelId = ReceiveTunnelId;

                DebugUtils.LogDebug("InboundTunnel " + TunnelDebugTrace + ": 0-hop tunnel " + Destination.Id32Short + " created.");
            }
        }
Example #24
0
        private bool LoadAllInformation()
        {
            bool result;
            try
            {
                if (!ApplicationInfo.IsLoadInformation)
                {
                    this.ShowSpashForm("Loading Information ...");
                    ApplicationInfo.IndexStatInfo.ResetData();
                    string data = ApplicationInfo.WebService.LoadAllInformation();
                    using (DataSet dataSet = new DataSet())
                    {
                        MyDataHelper.StringToDataSet(data, dataSet);
                        if (dataSet != null)
                        {
                            this.LoadStockInfomation(dataSet);
                            this.LoadIndustrialInfomation(dataSet);
                            this.LoadSectorInfomation(dataSet);
                            this.LoadMarketInformation(dataSet);
                            this.LoadDWInformation(dataSet);
                            dataSet.Clear();
                        }
                    }

                    if (ApplicationInfo.AutoTradeType > 0)
                    {
                        ApplicationInfo.IsAutoTradeAccepted = (ApplicationInfo.WebAlertService.StopOrderCheckDisclaimer(ApplicationInfo.UserLoginID) == ApplicationInfo.UserLoginID);
                    }

                    data = string.Empty;
                    if (ApplicationInfo.IsSupportTfex)
                    {
                        this.SectorBox.DisplayType = 3;
                        this.SectorBox.Width = 430;
                        this.ShowSpashForm("Loading TFEX Information ...");
                        try
                        {
                            this.LoadTFEXInfomation();
                            this.LoadTFEXMarketstate();
                        }
                        catch (Exception ex)
                        {
                            this.DisplayMessageBox("Load TFEX Information Error!!!\r\n" + ex.Message);
                        }
                        if (ApplicationInfo.MultiAutoComp == null)
                        {
                            ApplicationInfo.MultiAutoComp = new AutoCompleteStringCollection();
                        }
                        else
                        {
                            ApplicationInfo.MultiAutoComp.Clear();
                        }
                        if (ApplicationInfo.StockAutoComp == null)
                        {
                            ApplicationInfo.StockAutoComp = new AutoCompleteStringCollection();
                        }
                        else
                        {
                            ApplicationInfo.StockAutoComp.Clear();
                        }
                        if (ApplicationInfo.SeriesAutoComp == null)
                        {
                            ApplicationInfo.SeriesAutoComp = new AutoCompleteStringCollection();
                        }
                        else
                        {
                            ApplicationInfo.SeriesAutoComp.Clear();
                        }
                        foreach (KeyValuePair<int, StockList.StockInformation> current in ApplicationInfo.StockInfo.Items)
                        {
                            if (!current.Value.IsOddLot)
                            {
                                ApplicationInfo.MultiAutoComp.Add(current.Value.Symbol);
                                ApplicationInfo.StockAutoComp.Add(current.Value.Symbol);
                            }
                        }
                        ApplicationInfo.StockAutoCompStringArr.Initialize();
                        foreach (KeyValuePair<int, SeriesList.SeriesInformation> current2 in ApplicationInfo.SeriesInfo.Items)
                        {
                            if (current2.Value.Group != 5)
                            {
                                ApplicationInfo.MultiAutoComp.Add(current2.Value.Symbol);
                                ApplicationInfo.SeriesAutoComp.Add(current2.Value.Symbol);
                            }
                        }
                    }
                    else
                    {
                        this.SectorBox.DisplayType = 2;
                        this.SectorBox.Width = 270;
                        if (ApplicationInfo.StockAutoComp == null)
                        {
                            ApplicationInfo.StockAutoComp = new AutoCompleteStringCollection();
                        }
                        else
                        {
                            ApplicationInfo.StockAutoComp.Clear();
                        }
                        foreach (KeyValuePair<int, StockList.StockInformation> current in ApplicationInfo.StockInfo.Items)
                        {
                            if (!current.Value.IsOddLot)
                            {
                                ApplicationInfo.StockAutoComp.Add(current.Value.Symbol);
                            }
                        }
                        ApplicationInfo.StockAutoCompStringArr.Initialize();
                    }
                    string text = string.Empty;
                    text = ApplicationInfo.WebService.GetTunnel(ApplicationInfo.IsSupportTfex);
                    if (text != string.Empty)
                    {
                        string[] array = text.Trim().Split(new char[]
                        {
                            '|'
                        });
                        int num;
                        int.TryParse(array[1], out num);
                        string[] array2 = array[0].Trim().Split(new char[]
                        {
                            ';'
                        });
                        if (ApplicationInfo.TunnelHosts == null)
                        {
                            ApplicationInfo.TunnelHosts = new List<TunnelInfo>();
                        }
                        else
                        {
                            ApplicationInfo.TunnelHosts.Clear();
                        }
                        string[] array3 = array2;
                        for (int i = 0; i < array3.Length; i++)
                        {
                            string text2 = array3[i];
                            if (!string.IsNullOrEmpty(text2))
                            {
                                string[] array4 = text2.Trim().Split(new char[]
                                {
                                    ':'
                                });
                                TunnelInfo tunnelInfo = new TunnelInfo();
                                tunnelInfo.HostIP = array4[0].Trim();
                                tunnelInfo.Port = (string.IsNullOrEmpty(array4[1]) ? 27000 : Convert.ToInt32(array4[1].Trim()));
                                tunnelInfo.EnableSSL = (array4[2].Trim().ToUpper() == "Y");
                                tunnelInfo.IsAlreadyStart = false;
                                ApplicationInfo.TunnelHosts.Add(tunnelInfo);
                            }
                        }
                        int tunnelCounter = num % ApplicationInfo.TunnelHosts.Count;
                        ApplicationInfo.TunnelCounter = tunnelCounter;
                    }
                    ApplicationInfo.UrlSyncHandler = ApplicationInfo.WebService.GetCometInfo();
                    ApplicationInfo.IsLoadInformation = true;
                }
            }
            catch (Exception ex2)
            {
                this.ShowError("LoadAllInformation", ex2);
                this.DisplayMessageBox(ex2.ToString());
                result = false;
                return result;
            }
            this.ShowSpashForm("");
            result = true;
            return result;
        }
Example #25
0
 public void HandleForwardingError(IConnection sender, TunnelInfo tunnel, string errorMessage)
 {
     Console.WriteLine("Forwarding error for the tunnel {0}: {1}", tunnel.DisplayText, errorMessage);
 }
        public static VariableTunnelBuildMessage BuildOutboundTunnel(
            TunnelInfo setup,
            I2PIdentHash replyaddr, I2PTunnelId replytunnel,
            uint replymessageid)
        {
            byte usehops = (byte)(setup.Hops.Count > 5 ? 8 : 5);
            //byte usehops = 7; // 8 makes the response "TunnelBuildReply"
            var result = new VariableTunnelBuildMessage(usehops);

            // Hop sort order
            var requests = new List <BuildRequestRecord>();

            for (int i = 0; i < setup.Hops.Count; ++i)
            {
                // Hop order: Our out dest -> Endpoint
                var endpoint = i == setup.Hops.Count - 1;
                var gateway  = i == 0;

                var rec = new BuildRequestRecord();

                rec.Data.Randomize();
                rec.Flag = 0;

                var hop = setup.Hops[i];

                rec.OurIdent      = hop.Peer.IdentHash;
                rec.ReceiveTunnel = hop.TunnelId;

                if (!endpoint)
                {
                    var nexthop = setup.Hops[i + 1];

                    rec.NextIdent  = nexthop.Peer.IdentHash;
                    rec.NextTunnel = nexthop.TunnelId;
                }
                else
                {
                    rec.SendMessageId = replymessageid;

                    rec.NextIdent  = replyaddr;
                    rec.NextTunnel = replytunnel;
                }

                rec.RequestTime = DateTime.UtcNow;
                rec.ToAnyone    = endpoint;

                hop.LayerKey = new I2PSessionKey(rec.LayerKey.Clone());
                hop.IVKey    = new I2PSessionKey(rec.IVKey.Clone());

                requests.Add(rec);

#if LOG_ALL_TUNNEL_TRANSFER
                Logging.Log(rec.ToString());
#endif
            }

            // Physical record sort order
            var order = new List <AesEGBuildRequestRecord>(result.Records);
            order.Shuffle();

            // Scramble the rest
            for (int i = setup.Hops.Count; i < usehops; ++i)
            {
                order[i].Data.Randomize();
            }

            // ElGamal encrypt all of the non random records
            // and place them in shuffled order.
            for (int i = 0; i < setup.Hops.Count; ++i)
            {
                var hop   = setup.Hops[i];
                var egrec = new EGBuildRequestRecord(order[i].Data, requests[i], hop.Peer.IdentHash, hop.Peer.PublicKey);
            }

            var cipher = new CbcBlockCipher(new AesEngine());

            // Dont Aes the first destination
            for (int i = setup.Hops.Count - 2; i >= 0; --i)
            {
                var prevhop = requests[i];

                cipher.Init(false, prevhop.ReplyKeyBuf.ToParametersWithIV(prevhop.ReplyIV));

                for (int j = i + 1; j < setup.Hops.Count; ++j)
                {
                    cipher.Reset();
                    cipher.ProcessBytes(order[j].Data);
                }
            }

            for (int i = 0; i < setup.Hops.Count; ++i)
            {
                setup.Hops[i].ReplyProcessing = new ReplyProcessingInfo()
                {
                    BuildRequestIndex = result.Records.IndexOf(order[i]),
                    ReplyIV           = requests[i].ReplyIV.Clone(),
                    ReplyKey          = new I2PSessionKey(requests[i].ReplyKeyBuf.Clone())
                };
            }

            return(result);
        }
        public static VariableTunnelBuildMessage BuildInboundTunnel(
            TunnelInfo setup)
        {
            byte usehops = (byte)(setup.Hops.Count > 5 ? 8 : 5);
            var  result  = new VariableTunnelBuildMessage(usehops);

            // Hop sort order
            var requests = new List <BuildRequestRecord>();

            for (int i = 0; i < setup.Hops.Count; ++i)
            {
                // Hop order: GW -> us
                var endpoint = i == setup.Hops.Count - 1;
                var gateway  = i == 0;

                var rec = new BuildRequestRecord();

                rec.Data.Randomize();
                rec.Flag = 0;

                var hop = setup.Hops[i];

                rec.OurIdent      = hop.Peer.IdentHash;
                rec.ReceiveTunnel = hop.TunnelId;

                if (!endpoint)
                {
                    var nexthop = setup.Hops[i + 1];

                    rec.NextIdent  = nexthop.Peer.IdentHash;
                    rec.NextTunnel = nexthop.TunnelId;
                }
                else
                {
                    // Used to identify the record as the last in an inbound tunnel to us
                    rec.NextIdent  = hop.Peer.IdentHash;
                    rec.NextTunnel = hop.TunnelId;
                }

                rec.RequestTime = DateTime.UtcNow;
                rec.FromAnyone  = gateway;

                hop.LayerKey = new I2PSessionKey(rec.LayerKey.Clone());
                hop.IVKey    = new I2PSessionKey(rec.IVKey.Clone());

                requests.Add(rec);

#if LOG_ALL_TUNNEL_TRANSFER
                Logging.Log(rec.ToString());
#endif
            }

            // Physical record sort order
            var order = new List <AesEGBuildRequestRecord>(result.Records);
            order.Shuffle();

            // Scramble the rest
            for (int i = setup.Hops.Count; i < usehops; ++i)
            {
                order[i].Data.Randomize();
            }

            // ElGamal encrypt all of the non random records
            // and place them in shuffled order.
            for (int i = 0; i < setup.Hops.Count; ++i)
            {
                var hop   = setup.Hops[i];
                var egrec = new EGBuildRequestRecord(order[i].Data, requests[i], hop.Peer.IdentHash, hop.Peer.PublicKey);
            }

            var cipher = new BufferedBlockCipher(new CbcBlockCipher(new AesEngine()));

            // Dont Aes the first block
            for (int i = setup.Hops.Count - 2; i >= 0; --i)
            {
                var prevhop = requests[i];

                cipher.Init(false, new ParametersWithIV(new KeyParameter(prevhop.ReplyKey.ToByteArray()), prevhop.ReplyIV.ToByteArray()));

                for (int j = i + 1; j < setup.Hops.Count; ++j)
                {
                    cipher.Reset();
                    order[j].Process(cipher);
                }
            }

            for (int i = 0; i < setup.Hops.Count; ++i)
            {
                setup.Hops[i].ReplyProcessing = new ReplyProcessingInfo()
                {
                    BuildRequestIndex = result.Records.IndexOf(order[i]),
                    ReplyIV           = requests[i].ReplyIV.Clone(),
                    ReplyKey          = new I2PSessionKey(requests[i].ReplyKeyBuf.Clone())
                };
            }

            return(result);
        }
Example #28
0
        public void RenderTunnelError(TunnelInfo tunnel, string errorMessage)
        {
            var viewModel = this.tunnelViewModels.First(t => t.Tunnel.Equals(tunnel));

            viewModel.ErrorText = errorMessage;
        }
Example #29
0
 public bool Modify(TunnelInfo model)
 {
     return(tunnelInfoRepository.Update(model));
 }
Example #30
0
 public bool Delete(TunnelInfo model)
 {
     return(tunnelInfoRepository.Delete(model));
 }
Example #31
0
 public bool Add(TunnelInfo model)
 {
     return(tunnelInfoRepository.Add(model));
 }