Esempio n. 1
0
        private Pen GetSelfPen(FirewallType firewall)
        {
            if (firewall == FirewallType.Open)
            {
                return(OpenPen);
            }

            else if (firewall == FirewallType.NAT)
            {
                return(NATPen);
            }

            return(BlockedPen);
        }
Esempio n. 2
0
        private Color GetStatusColor(FirewallType firewall)
        {
            if (firewall == FirewallType.Open)
            {
                return(Color.FromArgb(0, 192, 0));
            }

            else if (firewall == FirewallType.NAT)
            {
                return(Color.FromArgb(255, 128, 0));
            }

            else
            {
                return(Color.FromArgb(192, 0, 0));
            }
        }
Esempio n. 3
0
        public void ShowNetwork()
        {
            if (GuiUtils.IsRunningOnMono())
            {
                if (CurrentMode == StatusModeType.Network &&
                    PrevOp == Core.Network.Responsive &&
                    PrevFirewall == Core.Firewall &&
                    (Core.Context.Lookup == null || PrevLookup == Core.Context.Lookup.Network.Responsive))
                {
                    return;
                }
            }

            CurrentMode = StatusModeType.Network;
            UserID      = 0;

            UpdateHeader("Green", "Network Status");

            string content = "";

            content += "<div style='padding-left: 10; line-height: 14pt;'>";

            if (Core.Context.Lookup != null)
            {
                string lookup = Core.Context.Lookup.Network.Responsive ? "Connected" : "Connecting";
                content += "<b>Lookup: </b>" + lookup + "<br>";

                PrevLookup = Core.Context.Lookup.Network.Responsive;
            }

            string operation = Core.Network.Responsive ? "Connected" : "Connecting";

            content += "<b>Network: </b>" + operation + "<br>";
            PrevOp   = Core.Network.Responsive;

            content     += "<b>Firewall: </b>" + Core.Firewall.ToString() + "<br>";
            PrevFirewall = Core.Firewall;

            content += "<b><a href='http://settings'>Settings</a></b><br>";

            content += "</div>";

            UpdateContent(content);
        }
Esempio n. 4
0
        // firewall set at core level so that networks can exist on internet and on public LANs simultaneously
        public void SetFirewallType(FirewallType type)
        {
            // check if already set
            if (Firewall == type)
            {
                return;
            }


            // if client previously blocked, cancel any current searches through proxy
            if (Firewall == FirewallType.Blocked)
            {
                lock (Network.Searches.Active)
                    foreach (DhtSearch search in Network.Searches.Active)
                    {
                        search.ProxyTcp = null;
                    }
            }

            Firewall = type;

            if (type == FirewallType.Open)
            {
                Network.FirewallChangedtoOpen();
            }

            if (type == FirewallType.NAT)
            {
                Network.FirewallChangedtoNAT();
            }

            if (type == FirewallType.Blocked)
            {
            }

            string message = "Firewall changed to " + type.ToString();

            Network.UpdateLog("Network", message);
            Network.UpdateLog("general", message);
        }
Esempio n. 5
0
        private void NetView_Paint(object sender, PaintEventArgs e)
        {
            int width  = ClientRectangle.Width;
            int height = ClientRectangle.Height;

            if (width == 0 || height == 0)
            {
                return;
            }

            if (DisplayBuffer == null || ReInitBuffer)
            {
                DisplayBuffer = new Bitmap(width, height);
                ReInitBuffer  = false;
            }

            if (!Redraw)
            {
                e.Graphics.DrawImage(DisplayBuffer, 0, 0);
                return;
            }
            Redraw = false;

            // background
            Graphics buffer = Graphics.FromImage(DisplayBuffer);

            buffer.Clear(Color.White);
            buffer.SmoothingMode = SmoothingMode.AntiAlias;

            // calc radii
            Point centerPoint = new Point(width / 2, height / 2);

            int maxRadius = (height > width) ? width / 2 : height / 2;

            maxRadius -= 15;

            // get node points
            NodePoints.Clear();
            TrackPoints.Clear();
            TransferPoints.Clear();
            Dictionary <ulong, DhtNetwork> networks = new Dictionary <ulong, DhtNetwork>();

            Sim.Instances.SafeForEach(instance =>
            {
                if (OpID == 0)
                {
                    if (instance.Context.Lookup != null)
                    {
                        networks[instance.Context.Lookup.UserID] = instance.Context.Lookup.Network;
                    }
                }
                else
                {
                    instance.Context.Cores.LockReading(delegate()
                    {
                        foreach (OpCore core in instance.Context.Cores)
                        {
                            if (OpID == core.Network.OpID)
                            {
                                networks[core.UserID] = core.Network;
                            }
                        }
                    });
                }
            });


            NodeBitfields.Clear();

            foreach (DhtNetwork network in networks.Values)
            {
                ulong userID     = network.Core.UserID;
                int   nodeRadius = (network.Core.Firewall == FirewallType.Open) ? maxRadius - 30 : maxRadius;

                NodePoints[userID] = GetCircumPoint(centerPoint, nodeRadius, IDto32(userID));

                if (TrackHash != null)
                {
                    if (IsTracked(network.Core))
                    {
                        TrackPoints.Add(GetCircumPoint(centerPoint, nodeRadius + 7, IDto32(userID)));
                    }


                    foreach (OpTransfer transfer in network.Core.Transfers.Transfers.Values)
                    {
                        if (Utilities.MemCompare(transfer.Details.Hash, TrackHash))
                        {
                            TransferPoints.Add(GetCircumPoint(centerPoint, nodeRadius + 7, IDto32(userID)));

                            if (transfer.LocalBitfield != null)
                            {
                                NodeBitfields[userID] = transfer.LocalBitfield;
                            }
                        }
                    }
                }
            }

            // draw lines for tcp between points
            foreach (DhtNetwork network in networks.Values)
            {
                lock (network.TcpControl.SocketList)
                    foreach (TcpConnect connect in network.TcpControl.SocketList)
                    {
                        if (connect.State == TcpState.Connected && NodePoints.ContainsKey(connect.UserID))
                        {
                            buffer.DrawLine(BluePen, NodePoints[network.Local.UserID], NodePoints[connect.UserID]);
                        }
                    }
            }

            // draw traffic lines
            DrawTraffic(buffer);

            // draw nodes
            NodeBoxes.Clear();

            foreach (ulong id in NodePoints.Keys)
            {
                SolidBrush brush = null;

                FirewallType firewall = networks[id].Core.Firewall;
                if (firewall == FirewallType.Open)
                {
                    brush = GreenBrush;
                }
                if (firewall == FirewallType.NAT)
                {
                    brush = OrangeBrush;
                }
                if (firewall == FirewallType.Blocked)
                {
                    brush = RedBrush;
                }

                NodeBoxes[id] = GetBoundingBox(NodePoints[id], 4);
                buffer.FillEllipse(brush, NodeBoxes[id]);
            }

            // draw tracked
            foreach (Point point in TrackPoints)
            {
                buffer.FillEllipse(BlueBrush, GetBoundingBox(point, 3));
            }

            foreach (Point point in TransferPoints)
            {
                buffer.FillEllipse(PurpleBrush, GetBoundingBox(point, 3));
            }

            int barwidth = 150;

            MissingBrush.Color = Color.White;
            int[] popularity = null;
            // popularity is nodes who have the transfer loaded (up/down)
            foreach (ulong user in NodeBitfields.Keys)
            {
                BitArray  bitfield = NodeBitfields[user];
                Rectangle box      = NodeBoxes[user];

                // determine popularity
                if (popularity == null)
                {
                    popularity = new int[bitfield.Length];
                }

                for (int i = 0; i < bitfield.Length; i++)
                {
                    if (bitfield[i])
                    {
                        popularity[i]++;
                    }
                }

                // draw bar
                int x = (box.X < width / 2) ? box.X + box.Width + 1 : // right sie
                        box.X - 1 - barwidth;                         // right side

                Rectangle bar = new Rectangle(x, box.Y, barwidth, box.Height);

                DrawBitfield(buffer, bar, bitfield);
            }

            // draw total completed bar in bottom right
            if (popularity != null)
            {
                int max = popularity.Max();

                Rectangle totalBox = new Rectangle(width - 300 - 5, height - 16 - 5, 300, 16);
                buffer.FillRectangle(CompletedBrush, totalBox);

                for (int i = 0; i < popularity.Length; i++)
                {
                    int brightness = 255 - popularity[i] * 255 / max; // high brighness -> white -> less people have file
                    MissingBrush.Color = Color.FromArgb(brightness, brightness, 255);
                    DrawPiece(buffer, popularity.Length, totalBox, i, i + 1);
                }

                buffer.DrawRectangle(BorderPen, totalBox);
            }

            // mark selected
            if (SelectedID != 0 && NodeBoxes.ContainsKey(SelectedID))
            {
                Rectangle selectBox = NodeBoxes[SelectedID];
                selectBox.Inflate(2, 2);
                buffer.DrawEllipse(BlackPen, selectBox);

                string name = networks[SelectedID].Core.User.Settings.UserName;
                name += " " + Utilities.IDtoBin(networks[SelectedID].Local.UserID);
                name += ShowInbound ? " Inbound Traffic" : " Outbound Traffic";

                buffer.DrawString(name, TahomaFont, BlackBrush, new PointF(3, 37));
            }

            // write hits for global
            if (OpID == 0)
            {
                buffer.DrawString(Sim.WebCacheHits + " WebCache Hits", TahomaFont, BlackBrush, new PointF(3, 25));
            }

            if (TrackString != null)
            {
                buffer.DrawString("Tracking: " + TrackString, TahomaFont, BlackBrush, 3, height - 20);
            }

            // Copy buffer to display
            e.Graphics.DrawImage(DisplayBuffer, ClientRectangle.X, ClientRectangle.Y);
        }
Esempio n. 6
0
File: OpCore.cs Progetto: swax/DeOps
        // firewall set at core level so that networks can exist on internet and on public LANs simultaneously
        public void SetFirewallType(FirewallType type)
        {
            // check if already set
            if (Firewall == type)
                return;

            // if client previously blocked, cancel any current searches through proxy
            if (Firewall == FirewallType.Blocked)
                lock (Network.Searches.Active)
                    foreach (DhtSearch search in Network.Searches.Active)
                        search.ProxyTcp = null;

            Firewall = type;

            if (type == FirewallType.Open)
                Network.FirewallChangedtoOpen();

            if (type == FirewallType.NAT)
                Network.FirewallChangedtoNAT();

            if (type == FirewallType.Blocked)
            {

            }

            string message = "Firewall changed to " + type.ToString();
            Network.UpdateLog("Network", message);
            Network.UpdateLog("general", message);
        }
Esempio n. 7
0
        public void ShowNetwork()
        {
            if (GuiUtils.IsRunningOnMono())
                if(CurrentMode == StatusModeType.Network &&
                    PrevOp ==  Core.Network.Responsive &&
                    PrevFirewall == Core.Firewall &&
                    (Core.Context.Lookup == null || PrevLookup == Core.Context.Lookup.Network.Responsive))
                    return;

            CurrentMode = StatusModeType.Network;
            UserID = 0;

            UpdateHeader("Green", "Network Status");

            string content = "";

            content += "<div style='padding-left: 10; line-height: 14pt;'>";

            if (Core.Context.Lookup != null)
            {
                string lookup = Core.Context.Lookup.Network.Responsive ? "Connected" : "Connecting";
                content += "<b>Lookup: </b>" + lookup + "<br>";

                PrevLookup = Core.Context.Lookup.Network.Responsive;
            }

            string operation = Core.Network.Responsive ? "Connected" : "Connecting";
            content += "<b>Network: </b>" + operation + "<br>";
            PrevOp = Core.Network.Responsive;

            content += "<b>Firewall: </b>" + Core.Firewall.ToString() + "<br>";
            PrevFirewall = Core.Firewall;

            content += "<b><a href='http://settings'>Settings</a></b><br>";

            content += "</div>";

            UpdateContent(content);
        }
Esempio n. 8
0
        private Color GetStatusColor(FirewallType firewall)
        {
            if (firewall == FirewallType.Open)
                return Color.FromArgb(0, 192, 0);

            else if (firewall == FirewallType.NAT)
                return Color.FromArgb(255, 128, 0);

            else
                return Color.FromArgb(192, 0, 0);
        }