Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //OLD InitiateSendTransmission
- public bool InitiateSendTransmission(Transmission transmission, Contact contact)
- {
- //lets see if we can actually send it
- //try each IP
- string id = CreateNewID();
- ControlTransferRequest ctr = new ControlTransferRequest(id, CreateNewKeyForRequest(id), LocalIPAddress());
- for (int i = 0; i < 3; i++)
- {
- string ipToTry;
- if (i == 0)
- ipToTry = contact.IP_Primary;
- else
- ipToTry = contact.IP_Secondary ?? contact.IP_Primary;
- //if (SendMessage(ctr.GetBytes(), ipToTry, CONTROL_PORT) > 0)
- //return true;
- byte[] bytesToSend = ctr.GetBytes();
- int sentbytes = SendMessage(bytesToSend, ipToTry, CONTROL_PORT);
- //got these, just to compare numbers
- WriteToLog("Control message:\n# Of Bytes To Send = " + bytesToSend.Length + "\n# of Bytes Sent = " + sentbytes);
- if (sentbytes > 0)
- return true;
- }
- _sendingPublicKeysDictionary.Remove(id);
- return false;
- }
- //NEW InitiateSendTransmission
- private bool InitiateSendTransmission(Transmission transmission, Contact contact)
- {
- //lets see if we can actually send it
- //try each IP
- string id = CreateNewID();
- ControlTransferRequest ctr = new ControlTransferRequest(id, CreateNewKeyForRequest(id), LocalIPAddress());
- if (TryIPs(contact, delegate(string ip)
- {
- byte[] bytesToSend = ctr.GetBytes();
- int sentbytes = SendMessage(bytesToSend, ip, CONTROL_PORT);
- //got these, just to compare numbers
- WriteToLog("Control message:\n# Of Bytes To Send = " + bytesToSend.Length + "\n# of Bytes Sent = " + sentbytes);
- if (sentbytes > 0)
- return true;
- else return false;
- }))
- return true;
- else
- {
- _sendingPublicKeysDictionary.Remove(id);
- return false;
- }
- }
- private bool TryIPs(Contact contact, Func<string, bool> doThis)
- {
- for (int i = 0; i < 2; i++)
- {
- if (i == 0 && contact.IP_Primary != null && !string.IsNullOrEmpty(contact.IP_Primary.Trim()))
- {
- if (doThis(contact.IP_Primary)) return true;
- }
- else if (contact.IP_Secondary != null && !string.IsNullOrEmpty(contact.IP_Secondary.Trim()))
- if (doThis(contact.IP_Secondary)) return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment