private void sendLeaveRequest(PeerInfo pInfo) { listener.closeSocket(); IPEndPoint remotePoint = new IPEndPoint(IPAddress.Parse(pInfo.getIP()), pInfo.getPORT()); UDPResponder responder = new UDPResponder(remotePoint, myInfo.getPORT()); responder.sendRequestLeave(myInfo.getGUID); }
private void btnSendFile_Click(object sender, EventArgs e) { string guid; guid = listRoutingTable.SelectedValue.ToString(); Console.WriteLine(guid); OpenFileDialog ofd = new OpenFileDialog(); DialogResult dr = ofd.ShowDialog(); if (dr != DialogResult.OK) { // no file was selected return; } string fileFullPath = ofd.FileName; string fileName = Path.GetFileName(fileFullPath); // get ip and port from selected peer in listbox int index = listRoutingTable.SelectedIndex; // find the guid of the peer selected //string selectedPeer = listRoutingTable.Items[index].ToString(); if (index == -1) { toolStatus.Text = "Error: No peer selected!"; return; } Dictionary <int, PeerInfo> peerDictionary = peer.getRoutingTable.getPeers(); // FIX FOR MONDAY // Will loop through peerDictonary and send to the first one it finds.. for (int i = 0; i < 12; i++) { if (peerDictionary.ContainsKey(i) && peer.getGUID != i) { PeerInfo receivingPeer = peerDictionary[i]; toolStatus.Text = String.Format("Sending file \"{0}\" to peer guid {1}, ip {2}:{3}", fileName, receivingPeer.getGUID, receivingPeer.getIP(), receivingPeer.getPORT()); IPAddress RecevingIp = IPAddress.Parse(receivingPeer.getIP()); //// Send file info //// create end point IPEndPoint remotePoint = new IPEndPoint(RecevingIp, receivingPeer.getPORT()); UDPResponder udpResponse = new UDPResponder(remotePoint, listenPort); udpResponse.sendFileInfo(fileFullPath); return; } } }
public void addPeerInfo(PeerInfo pInfo) { List <int> targets = routingTable.getTargetGUIDs(myInfo.getGUID); if (targets.Contains(pInfo.getGUID)) { routingTable.add(pInfo); IPEndPoint remotePoint = new IPEndPoint(IPAddress.Parse(pInfo.getIP()), pInfo.getPORT()); UDPResponder responder = new UDPResponder(remotePoint, myInfo.getPORT()); responder.sendRequestJoin(1, myInfo); } else if (!routingTable.containsValue(pInfo)) { bool added = routingTable.addIfCloser(pInfo); if (added) { IPEndPoint remotePoint = new IPEndPoint(IPAddress.Parse(pInfo.getIP()), pInfo.getPORT()); UDPResponder responder = new UDPResponder(remotePoint, myInfo.getPORT()); responder.sendRequestJoin(1, myInfo); } } routingTable.cleanTable(myInfo.getGUID); updateTable(); }
public void init(int guid, string ip, int port) { myInfo = new PeerInfo(guid, ip, port); // Create UDP listen and add events listener = new UDPListener(port); subscribeToListener(listener); // Create Routing Table and adding boot peer routingTable = new RoutingTable(myInfo); routingTable.add(bootPeer); listener.setRoutingtable = routingTable; // Create EndPoint IPEndPoint remotePoint = new IPEndPoint(IPAddress.Parse(bootPeer.getIP()), bootPeer.getPORT()); // Sending routing table request UDPResponder responder = new UDPResponder(remotePoint, port); responder.sendRequestRoutingTable(); }