public void Connect() { #if VERBOSE CKernel.LogClient.AddLog("Connect",m_ID); #endif m_ConexionTries++; if (m_ID>Protocol.LowIDLimit) { if (connection==null) { connection=new CConnection(m_ID,m_Port,this); } else { connection.ReOpenConnection(); } MemoryStream packet=new MemoryStream(); #if VERBOSE CKernel.LogClient.AddLog("Connect-send hello",m_ID); #endif bool allowPartner=((this.m_DownloadState!=Protocol.DownloadState.NoNeededParts)&& (CKernel.Queue.AllowNewParner())); CSendHello sendHello=new CSendHello(false,packet,CKernel.ServersList.ActiveServer,true,allowPartner); if (connection!=null) { connection.SendPacket(packet); connection.Connect(); } } else { m_CallBackTime=DateTime.Now; if (m_DownloadState==Protocol.DownloadState.Connecting) { m_DownloadState=Protocol.DownloadState.WaitCallBack; } if (m_UploadState==Protocol.UploadState.Connecting) { m_UploadState=Protocol.UploadState.WaitCallBack; } if (CKernel.ServersList.IsTheActiveServer(m_ServerIP,m_ServerPort)) { CKernel.ServersList.ActiveServer.RequestCallBack(m_ID); #if VERBOSE CKernel.LogClient.AddLog("Connect-RequestCallBack",m_ID); #endif } else { #if VERBOSE CKernel.LogClient.AddLog("LowID other server-Connect-RequestCallBack",m_ID); #endif //don't request udp callbacks to save servers bandwidth //this source will be deleted later //CKernel.ServersList.RequestCallBackUDP(m_ServerIP,m_ServerPort,m_ID); } } #if VERBOSE CKernel.LogClient.AddLog("Connect-connected ",m_ID); #endif }
public void ResponseHello() { #if VERBOSE CKernel.LogClient.AddLog("ResponseHello",m_ID); #endif MemoryStream packet=new MemoryStream(); bool allowPartner=((m_SupportsPartner)&& (this.m_DownloadState!=Protocol.DownloadState.NoNeededParts)&& (CKernel.Queue.AllowNewParner())); CSendHello helloResponse=new CSendHello(true,packet,CKernel.ServersList.ActiveServer,m_SupportsPartner,allowPartner); if (connection!=null) { connection.SendPacket(packet); } m_OnConnetionReady(); }