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())); transferManager.AddTransferReq(new TransferRequest(transfer.Source)); 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; } }
void hubConnection_Update(object sender, FmdcEventArgs e) { switch (e.Action) { case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; transferManager.AddTransferReq(req); } break; case Actions.TransferStarted: Transfer trans = e.Data as Transfer; if (trans != null) { #if !COMPACT_FRAMEWORK // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it. trans.SecureUpdate += new FmdcEventHandler(trans_SecureUpdate); #endif transferManager.StartTransfer(trans); trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem); trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer); } break; } }
void hubConnection_Update(object sender, FmdcEventArgs e) { Hub hub = (Hub)sender; switch (e.Action) { case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; if (transferManager.GetTransferReq(req.Key) == null) { transferManager.AddTransferReq(req); } } break; case Actions.TransferStarted: Transfer trans = e.Data as Transfer; if (trans != null) { transferManager.StartTransfer(trans); trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem); trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer); } break; case Actions.UserOnline: last = System.DateTime.Now.Ticks; break; } }
void hubConnection_Update(object sender, FmdcEventArgs e) { Hub hub = (Hub)sender; switch (e.Action) { case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; if (transferManager.GetTransferReq(req.Key) == null) { transferManager.AddTransferReq(req); } } break; case Actions.TransferStarted: Transfer trans = e.Data as Transfer; if (trans != null) { #if !COMPACT_FRAMEWORK // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it. trans.SecureUpdate += new FmdcEventHandler(trans_SecureUpdate); #endif transferManager.StartTransfer(trans); trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem); trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer); } break; case Actions.UserOnline: bool hasMe = (hub.GetUserById(hub.Me.ID) != null); if (!sentRequest && hasMe) { User usr = null; if ((usr = hub.GetUserByNick("FlowLibActiveTLS")) != null) { // Adding filelist of unknown type to download manager. // to the user FlowLibActiveTLS ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN); info.Set(ContentInfo.STORAGEPATH, currentDir + "Filelists\\" + usr.StoreID + ".filelist"); downloadManager.AddDownload(new DownloadItem(info), new Source(hub.RemoteAddress.ToString(), usr.StoreID)); // Start transfer to user UpdateBase(this, new FmdcEventArgs(Actions.StartTransfer, usr)); sentRequest = true; } } break; } }
void hubConnection_Update(object sender, FmdcEventArgs e) { Hub hub = (Hub)sender; switch (e.Action) { case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; if (transferManager.GetTransferReq(req.Key) == null) { transferManager.AddTransferReq(req); } } break; case Actions.TransferStarted: Transfer trans = e.Data as Transfer; if (trans != null) { // Here we bind transfer to our data collector stats = new GeneralProtocolDataCollector(trans); transferManager.StartTransfer(trans); trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem); trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer); } break; case Actions.UserOnline: bool hasMe = (hub.GetUserById(hub.Me.ID) != null); if (!sentRequest && hasMe) { User usr = null; if ((usr = hub.GetUserByNick("DCpp706")) != null) { // Adding filelist of unknown type to download manager. // to the user DCpp706 ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN); info.Set(ContentInfo.STORAGEPATH, currentDir + "Filelists\\" + usr.StoreID + ".filelist"); downloadManager.AddDownload(new DownloadItem(info), new Source(hub.RemoteAddress.ToString(), usr.StoreID)); // Start transfer to user UpdateBase(this, new FmdcEventArgs(Actions.StartTransfer, usr)); sentRequest = true; } } break; } }
void hubConnection_Update(object sender, FmdcEventArgs e) { switch (e.Action) { case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; transferManager.AddTransferReq(req); } break; case Actions.TransferStarted: Transfer trans = e.Data as Transfer; if (trans != null) { transferManager.StartTransfer(trans); } break; } }
void prot_Update(object sender, FmdcEventArgs e) { switch (e.Action) { case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; if (transferManager.GetTransferReq(req.Key) == null) { transferManager.AddTransferReq(req); } } break; case Actions.TransferStarted: Transfer trans = e.Data as Transfer; if (trans != null) { #if !COMPACT_FRAMEWORK // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it. trans.SecureUpdate += new FmdcEventHandler(trans_SecureUpdate); #endif transferManager.StartTransfer(trans); trans.ProtocolChange += new FmdcEventHandler(trans_ProtocolChange); trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem); trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer); trans.Protocol.Error += new FmdcEventHandler(Protocol_Error); if (Program.DEBUG) { trans.Protocol.MessageReceived += new FmdcEventHandler(Trans_Protocol_MessageReceived); trans.Protocol.MessageToSend += new FmdcEventHandler(Trans_Protocol_MessageToSend); } } break; case Actions.MainMessage: MainMessage msgMain = e.Data as MainMessage; if (CommandHandler.TryHandleMsg(this, msgMain.From, msgMain.Content, Actions.MainMessage)) { // message will here be converted to right format and then be sent. //UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.MainMessage, new MainMessage(hubConnection.Me.ID, msg))); } else { if (!Program.DEBUG) { Program.Write(string.Format("[{0}] <{1}> {2}\r\n", System.DateTime.Now.ToLongTimeString(), msgMain.From, msgMain.Content)); } } break; case Actions.PrivateMessage: PrivateMessage msgPriv = e.Data as PrivateMessage; if (CommandHandler.TryHandleMsg(this, msgPriv.From, msgPriv.Content.Replace("<" + msgPriv.From + "> ", string.Empty), Actions.PrivateMessage)) { // message will here be converted to right format and then be sent. //UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.PrivateMessage, new PrivateMessage(msgPriv.From, hubConnection.Me.ID, msgPM))); } else { if (!Program.DEBUG) { Program.Write(string.Format("[{0}] PM:{1}\r\n", System.DateTime.Now.ToLongTimeString(), msgPriv.Content)); } } break; } }
void prot_Update(object sender, FmdcEventArgs e) { Hub hubConnection = sender as Hub; if (hubConnection != null) { switch (e.Action) { case Actions.IsReady: bool isReady = (bool)e.Data; if (isReady) { // TODO: Start testing var usrlst = hubConnection.Userlist; User usr = null; // Find usable user. foreach (KeyValuePair <string, User> item in usrlst) { UserInfo me = hubConnection.Me; usr = item.Value; // Check so we are not trying to download from our self. if (me.ID == usr.ID) { continue; } if (me.TagInfo.Mode == FlowLib.Enums.ConnectionTypes.Passive) { if (usr.Tag.Mode == ConnectionTypes.Direct) { _hasFoundUser = true; break; } } else { if (usr.Tag.Mode == ConnectionTypes.Passive) { _hasFoundUser = true; break; } } } if (_hasFoundUser) { // Add filelist for a user ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN); _filelistPath = currentDir + "Filelists" + System.IO.Path.DirectorySeparatorChar + "downloading" + ".filelist"; info.Set(ContentInfo.STORAGEPATH, _filelistPath); info.Set("HubStoreId", hubConnection.StoreId); info.Set(UserInfo.STOREID, usr.StoreID); downloadManager.AddDownload(new DownloadItem(info), new Source(hubConnection.StoreId, usr.StoreID)); _testTimeoutLength += 10; } } break; case Actions.TransferRequest: if (e.Data is TransferRequest) { _hasTransferRequest = true; TransferRequest req = (TransferRequest)e.Data; if (transferManager.GetTransferReq(req.Key) == null) { transferManager.AddTransferReq(req); } } break; case Actions.TransferStarted: Transfer trans = e.Data as Transfer; _hasTransferStarted = true; if (trans != null) { // We could add a TransferRequest here if we wanted. transferManager.StartTransfer(trans); trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem); trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer); } break; } } }
public void Hub_Update(object sender, FlowLib.Events.FmdcEventArgs e) { Hub hub = (Hub)sender; this.hub = hub; string str = string.Empty; switch (e.Action) { case Actions.TransferStarted: if (e.Data is ITransfer) { ITransfer trans = (ITransfer)e.Data; transferManager.StartTransfer(trans); } break; case Actions.TransferRequest: if (e.Data is TransferRequest) { TransferRequest req = (TransferRequest)e.Data; transferManager.AddTransferReq(req); } break; #region MainMessage case Actions.MainMessage: if (e.Data is MainMessage) { MainMessage mainchat = (MainMessage)e.Data; if (mainchat.From == null) { str = mainchat.Content; } else { User u = hub.GetUserById(mainchat.From); if (u == null) { str = "<" + mainchat.From + "> " + mainchat.Content; } else { str = "<" + u.DisplayName + "> " + mainchat.Content; } } // Test : Start user = hub.GetUserById("DC++0.699"); //User user = hub.GetUserById("DCDM++0.0495"); if (user != null && hub.Share != null) { ContentInfo ci = new ContentInfo(ContentInfo.FILELIST, FlowLib.Utils.FileLists.BaseFilelist.UNKNOWN); ci.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\FileLists\" + user.ID + ".xml.bz2"); DownloadItem di = new DownloadItem(ci); downloadManager.AddDownload(di, new Source(null, user.ID)); downloadManager.DownloadCompleted += new FmdcEventHandler(DownloadManager_DownloadCompleted); this.Hub_Update(null, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(user.ID, hub, user.UserInfo))); //TransferManager.AddTransferReq(user.ID, hub, user.UserInfo); hub.Send(new FlowLib.Protocols.HubNmdc.ConnectToMe(user.ID, hub.Share.Port, hub)); } // Test : End } else { str = e.Data.ToString(); } Console.WriteLine(str); break; #endregion #region PrivateMessage case Actions.PrivateMessage: PrivateMessage to = (PrivateMessage)e.Data; Console.WriteLine("*** PM From: " + to.From + ", To: " + to.To + " " + to.Content); break; #endregion #region RegMode case Actions.RegMode: break; #endregion #region Status case Actions.StatusChange: HubStatus status = (HubStatus)e.Data; switch (status.Code) { case HubStatus.Codes.Disconnected: Console.WriteLine("*** Hub Disconnected"); if (status.Exception != null) { #if DEBUG if (status.Exception is System.Net.Sockets.SocketException) { System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)status.Exception; StringBuilder sb = new StringBuilder(); sb.Append("\r\n"); sb.Append("\tErrorCode: " + se.ErrorCode + "\r\n"); sb.Append("\tMessage: " + se.Message + "\r\n"); sb.Append("\tStackTrace: " + se.StackTrace); Console.WriteLine(sb.ToString()); } #else Console.WriteLine(" : " + status.Exception.Message); //richTextBox1.AppendText(status.Exception.StackTrace); #endif } Console.WriteLine("\r\n"); break; case HubStatus.Codes.Connected: Console.WriteLine("*** Hub Connected"); break; case HubStatus.Codes.Connecting: Console.WriteLine("*** Hub Connecting"); break; } break; #endregion default: Console.WriteLine(e.Data); break; } }