private void bgwNetwork_DoWork(object sender, DoWorkEventArgs e) { //bgwNetwork. Command command = e.Argument as Command; //CommandQueue queue = sender as CommandQueue; //for (int i = 0; i < command.Counter; i++) //{ // Logger.Log.Info(" bgwNetwork_DoWork Test " + command.Message + " " + Convert.ToString(i)); // Thread.Sleep(10000); // Sleep 10 sec //} if (Vault.Peers.Count > 0) { int random = new Random().Next(0, Vault.Peers.Count - 1); PeerEntry entry = Vault.Peers.ElementAt(random); if (entry != null && entry.ServiceProxy != null) { entry.ServiceProxy.SendCommand(command, Convert.ToString(config.Port)); entry.ServiceProxy.SendMessage(command.Message, Convert.ToString(config.Port)); } } //foreach ( PeerEntry item in Vault.Peers) //{ // item.ServiceProxy.SendCommand(command, user.GetName()); //} //ResolveP2P(); }
public void resolver_ResolveProgressChanged(object sender, ResolveProgressChangedEventArgs e) { PeerNameRecord peer = e.PeerNameRecord; foreach (IPEndPoint ep in peer.EndPointCollection) { //if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { try { string endpointUrl = string.Format(endpointuriformat, ep.Address, ep.Port); NetTcpBinding binding = new NetTcpBinding(); //binding.Security.Mode = SecurityMode.None; binding.Security.Mode = SecurityMode.None; ///// ///// // Stream add //// //// binding.TransferMode = TransferMode.Streamed; binding.MaxReceivedMessageSize = 20134217728; // 20 GB binding.MaxBufferPoolSize = 1024 * 1024; // 1 MB //// //// //// //// IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel( binding, new EndpointAddress(endpointUrl)); PeerEntry entry = new PeerEntry { PeerName = peer.PeerName, ServiceProxy = serviceProxy, DisplayString = serviceProxy.GetName(), }; //Vault.Peers.Add(peer); Logger.Log.Info(endpointUrl); Logger.Log.Info(entry.PeerName); Logger.Log.Info(entry.Comment); Logger.Log.Info("\t Endpoint:{0}", ep); Vault.Peers.Add(entry); } catch (EndpointNotFoundException) { //Vault.Peers.Add( // new PeerEntry // { // PeerName = peer.PeerName, // DisplayString = "Unknown Peer", // }); } } } }
private void lbPeers_SelectedIndexChanged(object sender, EventArgs e) { PeerEntry entry = (PeerEntry)lbPeers.SelectedItem; Command com = new Command(CommandType.TestConnect, new string[] { entry.Comment, entry.DisplayString }); com.Message = "TestConnect command added."; entry.ServiceProxy.SendCommand(com, Vault.LocalInfo.MachineName); }
private void btnCommandTester_Click(object sender, EventArgs e) { if (tbCommand.Text.Length > 0) { // create command from string try { switch (tbCommand.Text) { case "SendFile": { string sendfile = file.GetFileName(); send(sendfile); break; } case "GetList": { getlist(); break; } default: break; } if (tbCommand.Text == "SendFile") { } else { // parse command string int peernum = new Random().Next(0, Vault.Peers.Count - 1); PeerEntry peerEntry = Vault.Peers.ElementAt(peernum); if (peerEntry != null && peerEntry.ServiceProxy != null) { try { peerEntry.ServiceProxy.SendMessage(tbCommand.Text, network.Username); Command com = new Command(tbCommand.Text, Convert.ToInt32(network.Port)); com.xmltest(); peerEntry.ServiceProxy.SendCommand(com, network.Username); } catch (CommunicationException) { } } } } catch (Exception) { // if } } }
internal void Resolve2() { Logger.Log.Info("Start P2P resolver..."); // create a resolver object to resolve a peername resolver = new PeerNameResolver(); string endpointUrl = null; // resolve the PeerName - this is a network operation and will block until the resolve completes //PeerNameRecordCollection results = resolver.Resolve(peerName, 100); // Max 100 records PeerNameRecordCollection results = resolver.Resolve(peerName, Cloud.Available, 100); // Max 100 records foreach (PeerNameRecord record in results) { foreach (IPEndPoint ep in record.EndPointCollection) { if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { endpointUrl = string.Format(endpointuriformat4, ep.Address, ep.Port); } else if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) //if ((ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) && !ep.Address.IsIPv6LinkLocal) { endpointUrl = string.Format(endpointuriformat6, ep.Address, ep.Port); } try { NetTcpBinding binding = Helper.GetStreamBinding(); IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel( binding, new EndpointAddress(endpointUrl)); PeerEntry peer = new PeerEntry(); peer.PeerName = record.PeerName; peer.ServiceProxy = serviceProxy; peer.DisplayString = serviceProxy.GetName(); if (record.Comment != null) { peer.Comment = record.Comment; } if (record.Data != null) { peer.Data = System.Text.Encoding.ASCII.GetString(record.Data); } Logger.Log.Info(string.Format("SUCCESS Connect:{0} \t\t {1} ", endpointUrl, peer.Comment)); Vault.Peers.Add(peer); } catch (EndpointNotFoundException e) { Logger.Log.Debug(e.Message); } } } }
private void getlist() { int peernum = new Random().Next(0, Vault.Peers.Count - 1); PeerEntry peerEntry = Vault.Peers.ElementAt(peernum); RemoteListInfo list = peerEntry.ServiceProxy.RequestList(); //List<StorageFileInfo> storage = new List<StorageFileInfo>(); ShowFiles form = new ShowFiles(); form.files = list; form.peer = peerEntry; form.ShowDialog(this); }
internal void Resolve() { Logger.Log.Info("Start P2P resolver..."); // create a resolver object to resolve a peername resolver = new PeerNameResolver(); // resolve the PeerName - this is a network operation and will block until the resolve completes PeerNameRecordCollection results = resolver.Resolve(peerName); foreach (PeerNameRecord record in results) { PeerEntry peer = new PeerEntry(); if (record.Comment != null) { peer.Comment = record.Comment; } if (record.Data != null) { peer.Data = System.Text.Encoding.ASCII.GetString(record.Data); } //peer.Endpoints = record.EndPointCollection; //foreach (IPEndPoint endpoint in record.EndPointCollection) //{ // Console.WriteLine("\t Endpoint:{0}", endpoint); // Console.WriteLine(); //} Vault.Peers.Add(peer); Logger.Log.Info("Peers Resolver"); Logger.Log.Info(peer.PeerName); Logger.Log.Info(peer.Comment); foreach (IPEndPoint endpoint in record.EndPointCollection) { Logger.Log.Info("\t Endpoint:{0}", endpoint); } Logger.Log.Info("End P2P resolver..."); } }
private void send(string fileName) { //var client = new FileTransferClient.FileTransferServiceClient(); //var client = int peernum = new Random().Next(0, Vault.Peers.Count - 1); PeerEntry peerEntry = Vault.Peers.ElementAt(peernum); DownloadRequest dr = new DownloadRequest(); dr.FileName = fileName; RemoteFileInfo info = peerEntry.ServiceProxy.DownloadFile(dr); Stream inputStream = info.FileByteStream; //using (var writeStream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write)) //string outfile = Path.GetFileName(fileName); string outfile = Path.GetFileName(fileName); using (var writeStream = new FileStream(outfile, FileMode.CreateNew, FileAccess.Write)) { const int bufferSize = 2048; var buffer = new byte[bufferSize]; do { int bytesRead = inputStream.Read(buffer, 0, bufferSize); if (bytesRead == 0) { break; } writeStream.Write(buffer, 0, bytesRead); //progressBar1.Value = (int)(writeStream.Position * 100 / length); }while (true); writeStream.Close(); } inputStream.Dispose(); }
internal void Resolve2_old() { Logger.Log.Info("Start P2P resolver..."); // create a resolver object to resolve a peername resolver = new PeerNameResolver(); // resolve the PeerName - this is a network operation and will block until the resolve completes PeerNameRecordCollection results = resolver.Resolve(peerName, 100); // Max 100 records foreach (PeerNameRecord record in results) { foreach (IPEndPoint ep in record.EndPointCollection) { //if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 && !ep.Address.IsIPv6LinkLocal) { try { string endpointUrl = string.Format(endpointuriformat, ep.Address, ep.Port); NetTcpBinding binding = Helper.GetStreamBinding(); //NetTcpBinding binding = new NetTcpBinding(); ////binding.Security.Mode = SecurityMode.None; //binding.Security.Mode = SecurityMode.None; ////EndpointAddress epa = new EndpointAddress() /////// /////// //// Stream add ////// ////// //binding.TransferMode = TransferMode.Streamed; //binding.MaxReceivedMessageSize = 20134217728; // 20 GB //binding.MaxBufferPoolSize = 1024 * 1024; // 1 MB ////// ////// ////// ////// IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel( binding, new EndpointAddress(endpointUrl)); //IP2PService serviceProxy = ChannelFactory<IP2PService>.CreateChannel( // binding, new EndpointAddress(ep.Address.ToString() + ":" + Port.ToString())); //PeerEntry entry = new PeerEntry //{ // PeerName = record.PeerName, // ServiceProxy = serviceProxy, // DisplayString = serviceProxy.GetName(), //}; PeerEntry peer = new PeerEntry(); peer.PeerName = record.PeerName; peer.ServiceProxy = serviceProxy; peer.DisplayString = serviceProxy.GetName(); if (record.Comment != null) { peer.Comment = record.Comment; } if (record.Data != null) { peer.Data = System.Text.Encoding.ASCII.GetString(record.Data); } //Vault.Peers.Add(peer); Logger.Log.Info(endpointUrl); Logger.Log.Info(peer.PeerName); Logger.Log.Info(peer.Comment); Logger.Log.Info("\t Endpoint:{0}", ep); Vault.Peers.Add(peer); } catch (EndpointNotFoundException e) { //Vault.Peers.Add( // new PeerEntry // { // PeerName = peer.PeerName, // DisplayString = "Unknown Peer", // }); Logger.Log.Info(e.Message); } } } } }