// ============================================
        // PROTECTED (Methods) Event Handlers
        // ============================================
        protected void OnDragDataReceived(object sender, DragDataReceivedArgs args)
        {
            // Get Drop Paths
            object[] filesPath = Dnd.GetDragReceivedPaths(args);

            if (this.userInfo == MyInfo.GetInstance())
            {
                // Copy Selected Files Into Directory
                foreach (string filePath in filesPath)
                {
                    FileUtils.CopyAll(filePath, currentDirectory.FullName);
                }

                // Refresh Icon View
                Refresh();
            }
            else
            {
                // Send Files
                foreach (string filePath in filesPath)
                {
                    PeerSocket peer   = (PeerSocket)P2PManager.KnownPeers[userInfo];
                    bool       fisDir = FileUtils.IsDirectory(filePath);

                    Debug.Log("Send To '{0}' URI: '{1}'", userInfo.Name, filePath);
                    if (FileSend != null)
                    {
                        FileSend(peer, filePath, fisDir);
                    }
                }
            }

            Drag.Finish(args.Context, true, false, args.Time);
        }
        private void OnPeerLogin(PeerSocket peer, UserInfo userInfo)
        {
            Gtk.Application.Invoke(delegate {
                bool acceptUser = false;
                if (userInfo.SecureAuthentication == true)
                {
                    // Check if User is Present into Db else Ask Accept
//					if (Database.User.IsPresent(userInfo.Name) == false)
                    acceptUser = AcceptUser(peer);

                    // Add User To DB (Ask ?)
//					if (acceptUser == true)
//						Database.User.Add(userInfo.Name);
                }
                else
                {
                    acceptUser = AcceptUser(peer);
                }

                // Accept Peer (Add to NetworkViewer) or Remove Peer (P2PManager)
                if (acceptUser == true)
                {
                    AddUser(userInfo);
                }
                else
                {
                    P2PManager.RemovePeer(peer);
                }
            });
        }
Esempio n. 3
0
        /// Remove Upload
        public static void Remove(PeerSocket peer, string path)
        {
            UserInfo userInfo = peer.Info as UserInfo;

            ArrayList fileSenderList = uploads[peer] as ArrayList;

            if (fileSenderList == null)
            {
                throw(new UploadManagerException(userInfo.Name + " File '" + path + "' Not Found"));
            }

            FileSender fileSender = null;

            foreach (FileSender fs in fileSenderList)
            {
                if (fs.FileName == path)
                {
                    fileSender = fs;
                    break;
                }
            }

            if (fileSender != null)
            {
                Remove(fileSender);
            }
        }
 public void OnGetEvent(PeerSocket peer, XmlRequest xml)
 {
     if (xml.Attributes["what"].Equals("imgthumb"))
     {
         SendImageThumb(peer, xml.BodyText);
     }
 }
 protected void OnGetEvent(PeerSocket peer, XmlRequest xml)
 {
     if (xml.Attributes["what"].Equals("peerlist") == true)
     {
         SendPeerList(peer);
     }
 }
Esempio n. 6
0
        public void SendReceive()
        {
            using (var peer1 = new PeerSocket("@inproc://peertopeer"))
                using (var peer2 = new PeerSocket())
                {
                    var peer1Identity = peer2.ConnectPeer("inproc://peertopeer");

                    peer2.SendMoreFrame(peer1Identity);
                    peer2.SendFrame("Hello");

                    // peer2 identity
                    var peer2Identity = peer1.ReceiveFrameBytes();
                    var msg           = peer1.ReceiveFrameString();

                    Assert.Equal("Hello", msg);

                    peer1.SendMoreFrame(peer2Identity);
                    peer1.SendFrame("World");

                    peer2.ReceiveFrameBytes();
                    msg = peer2.ReceiveFrameString();

                    Assert.Equal("World", msg);

                    peer1.SendMoreFrame(peer2Identity);
                    peer1.SendFrame("World2");

                    peer2.ReceiveFrameBytes();
                    msg = peer2.ReceiveFrameString();

                    Assert.Equal("World2", msg);
                }
        }
Esempio n. 7
0
 // =================================================
 // PROTECTED (Methods) Network Viewer Event Handlers
 // =================================================
 private void OnSendFile(object obj, UserInfo userInfo, string path)
 {
     Gtk.Application.Invoke(delegate {
         PeerSocket peer = P2PManager.KnownPeers[userInfo] as PeerSocket;
         UploadManager.Add(peer, path);
     });
 }
        private void OnPeerLogin(PeerSocket peer, UserInfo userInfo)
        {
            Gtk.Application.Invoke(delegate {
                AcceptUserType acceptUser = AcceptUserType.Ask;

                // Raise Accept User Event
                if (UserAccept != null)
                {
                    acceptUser = UserAccept(peer, userInfo);
                }

                // Ask if Accept User
                if (acceptUser == AcceptUserType.Ask)
                {
                    acceptUser = AcceptUser(peer) ? AcceptUserType.Yes : AcceptUserType.No;
                }

                // Accept Peer (Add to NetworkViewer) or Remove Peer (P2PManager)
                if (acceptUser == AcceptUserType.Yes)
                {
                    AddUser(userInfo);
                }
                else
                {
                    P2PManager.RemovePeer(peer);
                }
            });
        }
Esempio n. 9
0
        private static void RemoveFileReceiver(PeerSocket peer, string fileName)
        {
            Hashtable peerList = recvFileList[peer] as Hashtable;

            peerList.Remove(fileName);
            recvFileList[peer] = peerList;
        }
Esempio n. 10
0
        /// Get File Part
        public static void GetFilePart(PeerSocket peer, XmlRequest xml)
        {
            FileReceiver fileRecv = LookupFileReceiver(peer, xml);

            if (fileRecv != null)
            {
                fileRecv.Append(xml);

                // Send Received Part Event
                if (Received != null)
                {
                    Received(fileRecv);
                }
            }
            else
            {
                string   fileName = (string)xml.Attributes["name"];
                UserInfo userInfo = peer.Info as UserInfo;

                string message = "What file is this ?" +
                                 "\nUser: "******"\nFileName: " + fileName;
                throw(new DownloadManagerException(message));
            }
        }
Esempio n. 11
0
        /// Create New Login Checker
        public Login(PeerSocket peer, XmlRequest xml)
        {
            // Get UserName
            string userName = (string)xml.Attributes["name"];

            if (userName == null)
            {
                return;
            }

            // Get SecureAuth
            bool   secureAuth  = false;
            string _secureAuth = (string)xml.Attributes["secure"];

            if (_secureAuth != null && _secureAuth == "True")
            {
                secureAuth = true;
            }

            // Get Magic
            string magic = (string)xml.Attributes["magic"];

            if (secureAuth == true && magic == null)
            {
                return;
            }

            // Initialize UserInfo
            this.userInfo = new UserInfo(userName, secureAuth, magic);
        }
Esempio n. 12
0
 public static void StartRecvAbortEvent(PeerSocket peer, XmlRequest xml)
 {
     if (RecvAbortEvent != null)
     {
         RecvAbortEvent(peer, xml);
     }
 }
Esempio n. 13
0
 public static void StartGetEvent(PeerSocket peer, XmlRequest xml)
 {
     if (GetEvent != null)
     {
         GetEvent(peer, xml);
     }
 }
Esempio n. 14
0
 public static void StartAcceptEvent(PeerSocket peer, XmlRequest xml)
 {
     if (AcceptEvent != null)
     {
         AcceptEvent(peer, xml);
     }
 }
Esempio n. 15
0
 // ============================================
 // PUBLIC STATIC Methods (Events)
 // ============================================
 public static void StartLoginEvent(PeerSocket peer, UserInfo info)
 {
     if (LoginEvent != null)
     {
         LoginEvent(peer, info);
     }
 }
Esempio n. 16
0
 public static void StartErrorEvent(PeerSocket peer, XmlRequest xml)
 {
     if (ErrorEvent != null)
     {
         ErrorEvent(peer, xml);
     }
 }
Esempio n. 17
0
        /// Remove file from Accept list and prepare to Receve it
        public static void InitFile(PeerSocket peer, XmlRequest xml)
        {
            FileReceiver fileRecv = LookupFileReceiver(peer, xml);

            string    path     = (string)xml.Attributes["name"];
            Hashtable peerList = acceptList[peer] as Hashtable;
            string    name     = (string)peerList[path];

            peerList.Remove(path);
            acceptList[peer] = peerList;

            if (fileRecv == null)
            {
                fileRecv = new FileReceiver(peer, xml, name);
                AddFileReceiver(peer, path, fileRecv);
            }

            numDownloads++;

            // Start New File Added
            if (Added != null)
            {
                Added(fileRecv);
            }
        }
Esempio n. 18
0
        /// Send Error
        public static void Error(PeerSocket peer, string f, params object[] objs)
        {
            StringBuilder message = new StringBuilder();

            message.AppendFormat(f, objs);
            Error(peer, message.ToString());
        }
Esempio n. 19
0
        // ============================================
        // PUBLIC Constructors
        // ============================================
        /// Create New Proxy Settings Dialog
        public AcceptUser(PeerSocket peer) :
            base("dialog", "AcceptUserDialog.glade")
        {
            // Get UserInfo
            UserInfo userInfo = peer.Info as UserInfo;

            // Initialize GUI
            this.labelTitle.Text = "<span size='x-large'><b>Accept User</b> (";
            if (userInfo.SecureAuthentication == true)
            {
                this.image.Pixbuf     = StockIcons.GetPixbuf("SecureAuth");
                this.labelTitle.Text += "Secure";
                this.Dialog.Title    += " (Secure Authentication)";
            }
            else
            {
                this.image.Pixbuf     = StockIcons.GetPixbuf("InsecureAuth");
                this.labelTitle.Text += "Insecure";
                this.Dialog.Title    += " (Insecure Authentication)";
            }
            this.labelTitle.Text     += ")</span>";
            this.labelTitle.UseMarkup = true;

            entryName.Text = userInfo.Name;
            entryIP.Text   = peer.GetRemoteIP().ToString();
        }
        private void OnPeerError(object sender, PeerEventArgs args)
        {
            PeerSocket peer     = sender as PeerSocket;
            UserInfo   userInfo = peer.Info as UserInfo;

            Debug.Log("Peer ({0}) Error: {1}", userInfo.Name, args.Message);
        }
Esempio n. 21
0
 public static void StartUnknownEvent(PeerSocket peer, XmlRequest xml)
 {
     if (UnknownEvent != null)
     {
         UnknownEvent(peer, xml);
     }
 }
 // TODO: Add OnAddUser
 protected void OnPeerLogin(PeerSocket peer, UserInfo userInfo)
 {
     // Waiting Peer Initialization Time, Bad Bad Bad!!!
     Thread.Sleep(6000);
     // Request Peer List
     RequestPeerList(peer);
 }
Esempio n. 23
0
 public static void StartSndAbortEvent(PeerSocket peer, XmlRequest xml)
 {
     if (SndAbortEvent != null)
     {
         SndAbortEvent(peer, xml);
     }
 }
Esempio n. 24
0
        // =================================================
        // PROTECTED (Methods) Protocol Cmds Event Handlers
        // =================================================
        /// <get what='file' id='10' />
        private void OnGetEvent(PeerSocket peer, XmlRequest xml)
        {
            Gtk.Application.Invoke(delegate {
                string what = (string)xml.Attributes["what"];

                switch (what)
                {
                case "file-id":
                    try {
                        ulong id = ulong.Parse((string)xml.Attributes["id"]);
                        UploadManager.Send(peer, id);
                        // TODO: Manage ID Not Found
                    } catch (Exception e) {
                        Base.Dialogs.MessageError("File Not Found", e.Message);
                    }
                    break;

                case "file":
                    string filePath = (string)xml.Attributes["path"];
                    filePath        = Path.Combine(Paths.UserSharedDirectory(MyInfo.Name), filePath.Substring(1));
                    UploadManager.Send(peer, filePath);
                    break;

                case "file-list":
                    string folderPath = (string)xml.Attributes["path"];
                    Cmd.SendFileList(peer, folderPath);
                    break;
                }
            });
        }
Esempio n. 25
0
        /// Send Error
        public static void Error(PeerSocket peer, string message)
        {
            XmlRequest xmlRequest = new XmlRequest();

            xmlRequest.FirstTag = "error";
            xmlRequest.BodyText = message;
            peer.Send(xmlRequest.GenerateXml());
        }
        private void SendPeerList(PeerSocket peer)
        {
            XmlRequest xml = new XmlRequest();

            xml.FirstTag = "peerlist";
            xml.BodyText = GeneratePeerList();
            peer.Send(xml.GenerateXml());
        }
        // ============================================
        // PRIVATE Methods
        // ============================================
        private void RequestPeerList(PeerSocket peer)
        {
            XmlRequest xml = new XmlRequest();

            xml.FirstTag = "get";
            xml.Attributes.Add("what", "peerlist");
            peer.Send(xml.GenerateXml());
        }
Esempio n. 28
0
 private void OnFolderRefresh(object obj, string path)
 {
     Gtk.Application.Invoke(delegate {
         FolderViewer folderViewer = obj as FolderViewer;
         PeerSocket peer           = P2PManager.KnownPeers[folderViewer.UserInfo] as PeerSocket;
         Cmd.RequestFolder(peer, path);
     });
 }
Esempio n. 29
0
        private static void SendMessage(PeerSocket peer, string message)
        {
            XmlRequest xmlRequest = new XmlRequest();

            xmlRequest.FirstTag = "msg";
            xmlRequest.BodyText = message;
            peer.Send(xmlRequest.GenerateXml());
        }
Esempio n. 30
0
        // ============================================
        // PUBLIC STATIC Methods
        // ============================================
        /// Generate Peer's Magic
        public static string GenerateMagic(PeerSocket peer)
        {
            UserInfo myInfo    = MyInfo.GetInstance();
            string   userIp    = CryptoUtils.SHA1String(peer.GetRemoteIP().ToString());
            string   userMagic = CryptoUtils.SHA1String((string)myInfo.Informations["magic"]);

            return(CryptoUtils.MD5String(userIp + userMagic));
        }
Esempio n. 31
0
        public CmdParse(PeerSocket peer, ArrayList xmlCmds)
        {
            this.xmlCmds = xmlCmds;
            this.peer = peer;

            // Start Command Parser Thread
            thread = new Thread(new ThreadStart(ParseXml));
            thread.Start();
        }