protected virtual void DoInternalListenRecieveAccess() { try { tcpListener = new TcpConnectionListener(Port); tcpListener.Update += new FmdcEventHandler(DoInternalListenAccess_Update); tcpListener.Start(); try { // TODO: We shouldn't limit ourself to IPv4. Transfer transfer = new Transfer("127.0.0.1", Port); UserInfo me = new UserInfo(); me.DisplayName = "loopback"; me.TagInfo.Version = "FlowLibPowered"; transfer.Share = new Share("temp"); transfer.Me = me; // TODO: We shouldn't limit ourself to IPv4. transfer.Source = new Source("127.0.0.1", "loopback"); transferManager.AddTransferReq(new TransferRequest("loopback", null, new UserInfo())); transfer.Protocol = new TransferNmdcProtocol(transfer); transferManager.StartTransfer(transfer); Success |= Functions.InternalListenAccess; } catch { // We do not have InternalListenAccess. Success = Success & ~Functions.InternalListenAccess; } // Wait 10 seconds before continue int i = 0; do { Thread.Sleep(50); } while (((Functions.InternalRecieveAccess & Success) != Functions.InternalRecieveAccess) && i++ > 200); // clean; tcpListener.Update -= DoInternalListenAccess_Update; tcpListener.End(); tcpListener = null; } finally { Progress = Functions.ExternalIp; } }
protected virtual void DoUPnPExternalRecieveAccess() { try { tcpListener = new TcpConnectionListener(Port); tcpListener.Update += new FmdcEventHandler(DoUPnPExternalRecieveAccess_Update); tcpListener.Start(); // Don't do this if we don't have external ip if ( (Functions.UPnPDevices & Success) == Functions.UPnPDevices && (Functions.UPnPIGD & Success) == Functions.UPnPIGD && (Functions.UPnPExternalIp & Success) == Functions.UPnPExternalIp && (Functions.UPnPAddMapping & Success) == Functions.UPnPAddMapping && (Functions.UPnPGetMapping & Success) == Functions.UPnPGetMapping && (Functions.UPnPDeleteMapping & Success) == Functions.UPnPDeleteMapping ) { bool hasAddPortMapping = false; if (hasAddPortMapping = wanipService.AddPortMapping(this, mapping)) { //Transfer transfer = new Transfer(ExternalIPUPnP.ToString(), Port); Transfer transfer = new Transfer(ExternalIP.ToString(), Port); UserInfo me = new UserInfo(); me.DisplayName = "upnp"; me.TagInfo.Version = "FlowLibPowered"; transfer.Share = new Share("temp"); transfer.Me = me; transfer.Source = new Source(ExternalIP.ToString(), "upnp"); transferManager.AddTransferReq(new TransferRequest("upnp", null, new UserInfo())); transfer.Protocol = new TransferNmdcProtocol(transfer); transferManager.StartTransfer(transfer); // Wait 60 seconds before continue int i = 0; do { Thread.Sleep(50); } while (((Functions.UPnPExternalRecieveAccess & Success) != Functions.UPnPExternalRecieveAccess) && i++ > 1200); // clean; wanipService.DeletePortMapping(this, mapping); } } tcpListener.Update -= DoUPnPExternalRecieveAccess_Update; tcpListener.End(); tcpListener = null; } finally { Progress = Functions.End; } }
protected virtual void DoExternalRecieveAccess() { try { tcpListener = new TcpConnectionListener(Port); tcpListener.Update += new FmdcEventHandler(DoExternalRecieveAccess_Update); tcpListener.Start(); // Don't do this if we don't have external ip if ((Functions.ExternalIp & Success) == Functions.ExternalIp) { Transfer transfer = new Transfer(ExternalIP.ToString(), Port); UserInfo me = new UserInfo(); me.DisplayName = "external"; me.TagInfo.Version = "FlowLibPowered"; transfer.Share = new Share("temp"); transfer.Me = me; transfer.Source = new Source(ExternalIP.ToString(), "external"); transferManager.AddTransferReq(new TransferRequest("external", null, new UserInfo())); transfer.Protocol = new TransferNmdcProtocol(transfer); transferManager.StartTransfer(transfer); } // Wait 30 seconds before continue int i = 0; do { Thread.Sleep(50); } while (((Functions.ExternalRecieveAccess & Success) != Functions.ExternalRecieveAccess) && i++ > 600); // clean; tcpListener.Update -= DoExternalRecieveAccess_Update; tcpListener.End(); tcpListener = null; } finally { if ((Functions.ExternalRecieveAccess & Success) == Functions.ExternalRecieveAccess) { Progress = Functions.End; } else { Progress = Functions.UPnPDevices; } } }