public override void HandlePacket(ecProto.ecPacket packet) { ECOpCodes op = packet.Opcode(); switch (op) { case ECOpCodes.EC_OP_STATS: m_owner.StatsReplyInvoke(packet); break; case ECOpCodes.EC_OP_DLOAD_QUEUE: m_owner.DloadQueueReply(packet); break; case ECOpCodes.EC_OP_SHARED_FILES: m_owner.SharedFilesReply(packet); break; case ECOpCodes.EC_OP_NOOP: break; default: throw new Exception("Unhandled EC reply"); } }
public ecProto.ecPacket HandlePacket(ecProto.ecPacket p) { ecProto.ecPacket reply = null; switch (m_state) { case REQ_STATE.IDLE: throw new Exception("Should not get packet in IDLE state"); case REQ_STATE.REQ_SENT: m_state = REQ_STATE.IDLE; if (!Phase1Done()) { break; } ecProto.ecPacket full_request = new ecProto.ecPacket(m_req_cmd); ProcessUpdate(p, full_request); // // Phase 3: request full info about files we don't have yet if (!m_inc_tags && (full_request.SubtagCount() != 0)) { reply = full_request; m_state = REQ_STATE.FULL_REQ_SENT; } break; case REQ_STATE.FULL_REQ_SENT: m_state = REQ_STATE.IDLE; break; } return(reply); }
public void SharedFilesReply(ecProto.ecPacket packet) { ecProto.ecPacket reply = m_shared_info.HandlePacket(packet); if (reply != null) { m_amuleRemote.SendPacket(reply); } }
public void DloadQueueReply(ecProto.ecPacket packet) { ecProto.ecPacket reply = m_dload_info.HandlePacket(packet); if (reply != null) { m_amuleRemote.SendPacket(reply); } }
public IAsyncResult SendPacket(ecProto.ecPacket packet) { m_tx_mem_stream.Seek(0, SeekOrigin.Begin); packet.Write(m_sock_writer); return(m_s.BeginSend(m_tx_buffer, 0, packet.PacketSize(), SocketFlags.None, new AsyncCallback(TxCallback), this)); }
public void SelectedItemsToCommand(ecProto.ecPacket cmd) { foreach (ListViewItem i in SelectedItems) { DownloadQueueItem it = i.Tag as DownloadQueueItem; ecProto.ecTagMD5 tag = new ecProto.ecTagMD5(ECTagNames.EC_TAG_PARTFILE, it.ID); cmd.AddSubtag(tag); } }
public void StatsReplyInvoke(ecProto.ecPacket packet) { if (InvokeRequired) { StatsReplyCallback d = new StatsReplyCallback(StatsReply); Invoke(d, packet); } else { StatsReply(packet); } }
private void buttonAddLink_Click(object sender, EventArgs e) { AddLinkDialog dlg = new AddLinkDialog(); if (dlg.ShowDialog() == DialogResult.OK) { string link = dlg.textBoxLink.Text; ecProto.ecPacket cmd = new ecProto.ecPacket(ECOpCodes.EC_OP_ADD_LINK); ecProto.ecTagString linktag = new ecProto.ecTagString(ECTagNames.EC_TAG_STRING, link); cmd.AddSubtag(linktag); m_amuleRemote.SendPacket(cmd); } }
public override void HandlePacket(ecProto.ecPacket packet) { if (packet.Opcode() == ECOpCodes.EC_OP_AUTH_OK) { Console.WriteLine("amuleLogicHandler : Authenticated OK"); m_auth_result = true; m_owner.m_packet_op_Done.Set(); } else { Console.WriteLine("amuleLogicHandler : Authentication failed. Core reply was {0}", packet.Opcode()); } }
public ecProto.ecPacket ReQuery() { // can not issue new query until previous one is replied if (m_state != REQ_STATE.IDLE) { return(null); } ecProto.ecPacket request = new ecProto.ecPacket(m_req_cmd, m_inc_tags ? EC_DETAIL_LEVEL.EC_DETAIL_INC_UPDATE : EC_DETAIL_LEVEL.EC_DETAIL_UPDATE); m_state = REQ_STATE.REQ_SENT; return(request); }
void ProcessUpdate(ecProto.ecPacket packet, ecProto.ecPacket full_req) { m_owner.MyBeginUpdate(); LinkedList <ecProto.ecTag> .Enumerator i = packet.GetTagIterator(); while (i.MoveNext()) { ecProto.ecTag t = i.Current; // sometimes reply contains additional tags if (t.Name() != m_item_tagname) { continue; } ecProto.ecMD5 item_id = ((ecProto.ecTagMD5)t).ValueMD5(); if (m_items_hash.ContainsKey(item_id)) { T item = m_items_hash[item_id]; ProcessItemUpdate(item, t); if (m_owner != null) { m_owner.UpdateItem(item); } } else { if (m_inc_tags) { T item = CreateItem(t); m_items.AddLast(item); m_items_hash[item_id] = item; if (m_owner != null) { m_owner.InsertItem(item); } } else { full_req.AddSubtag(CreateItemTag(item_id)); } } // // now process item deletion // // TODO } m_owner.MyEndUpdate(); }
void m_download_status_ctrl_OnCancelItem() { string msg = "Following files will be cancelled:\n"; foreach (ListViewItem i in m_download_status_ctrl.SelectedItems) { msg += i.Text + "\n"; } if (MessageBox.Show(msg, "Cancel files", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { ecProto.ecPacket cmd = new ecProto.ecPacket(ECOpCodes.EC_OP_PARTFILE_DELETE); m_download_status_ctrl.SelectedItemsToCommand(cmd); m_amuleRemote.SendPacket(cmd); } }
void StatsReply(ecProto.ecPacket packet) { ecProto.ecTag t = null; t = packet.SubTag(ECTagNames.EC_TAG_STATS_DL_SPEED); int dl_speed = ((ecProto.ecTagInt)t).ValueInt(); t = packet.SubTag(ECTagNames.EC_TAG_STATS_UL_SPEED); int ul_speed = ((ecProto.ecTagInt)t).ValueInt(); //string server = ((ecProto.ecTagString)t).ToString(); ecProto.ecConnStateTag connState = new ecProto.ecConnStateTag((ecProto.ecTagInt)packet.SubTag(ECTagNames.EC_TAG_CONNSTATE)); textBoxDownSpeed.Text = "Down:" + ValueToPrefix(dl_speed) + "/s"; textBoxUpSpeed.Text = "Up:" + ValueToPrefix(ul_speed) + "/s"; if (connState.IsConnected()) { if (connState.IsConnectedED2K()) { textLinktatus.Text = "ED2K: connected"; //ecProto.ecTagString server_name = (ecProto.ecTagString)server.SubTag(ECTagNames.EC_TAG_SERVER_NAME); //toolStripStatusServer.Text = server_name.StringValue(); } else { //toolStripStatusServer.Text = ""; if (connState.IsConnectingED2K()) { textLinktatus.Text = "ED2K: connecting ..."; } else { textLinktatus.Text = "ED2K: disconnected"; } } if (connState.IsConnectedKademlia()) { //textLinktatus.Text = "KAD: connected"; } } }
ecProto.ecPacket GetFullInfoRequest() { ecProto.ecPacket req = null; Control current_ctrl = panelMain.Controls[0]; if (current_ctrl == m_download_status_ctrl) { req = m_dload_info.ReQuery(); } else if (current_ctrl == m_shared_list_ctrl) { req = m_shared_info.ReQuery(); } if (req == null) { throw new Exception("unhandled GUI state"); } return(req); }
private static void UpdateTimerProc(Object myObject, EventArgs myEventArgs) { MainWindow w = (MainWindow)((Timer)myObject).Tag; // TODO: for testing 1 request is enough w.m_updateTimer.Stop(); ecProto.ecPacket req = null; switch (w.m_req_state) { case UpdateRequestState.Stats: req = new ecProto.ecPacket(ECOpCodes.EC_OP_STAT_REQ); w.m_req_state = UpdateRequestState.MainInfo; break; case UpdateRequestState.MainInfo: req = w.GetFullInfoRequest(); w.m_req_state = UpdateRequestState.Stats; break; } w.m_amuleRemote.SendPacket(req); }
static void RxCallback(IAsyncResult ar) { amuleRemote o = (amuleRemote)ar.AsyncState; Console.WriteLine("RxCallback signalled, calling EndReceive"); int bytesRead = o.m_s.EndReceive(ar); if (bytesRead == 0) { // remote side closed connection. // indicate error to caller o.m_rx_byte_count = -1; return; } o.m_rx_remaining_count -= bytesRead; Console.WriteLine("RxCallback: got {0} bytes, waiting for {1}", bytesRead, o.m_rx_remaining_count); // are we still waiting for flags and size? if (o.m_rx_byte_count < 8) { if ((o.m_rx_byte_count + bytesRead) >= 8) { // got flags and packet size - may proceed. Int32 flags = o.m_sock_reader.ReadInt32(); Int32 val32 = o.m_sock_reader.ReadInt32(); o.m_rx_remaining_count = (int)IPAddress.NetworkToHostOrder(val32) - (bytesRead - 8); Console.WriteLine("RxCallback: expecting packet size={0}", o.m_rx_remaining_count); if (o.m_rx_buffer.Length <= (o.m_rx_remaining_count + o.m_rx_byte_count)) { byte [] new_buffer = new byte[o.m_rx_remaining_count + o.m_rx_buffer.Length + 1]; o.m_rx_buffer.CopyTo(new_buffer, 0); o.m_rx_buffer = new_buffer; // // update stream reader with new buffer // o.m_rx_mem_stream = new MemoryStream(o.m_rx_buffer); o.m_sock_reader = new BinaryReader(o.m_rx_mem_stream); } } } else { if (o.m_rx_remaining_count == 0) { // // Packet received - call handler // if (o.m_handler != null) { o.m_rx_mem_stream.Seek(0, SeekOrigin.Begin); Console.WriteLine("Packet received - call handler"); ecProto.ecPacket p = new ecProto.ecPacket(o.m_sock_reader); //m_packet_op_Done.Set(); o.m_handler.HandlePacket(p); Console.WriteLine("Handler done"); } Console.WriteLine("Signalling event"); //m_packet_op_Done.Set(); // // Keep waiting for more packets // o.StartReceive(); return; } } o.m_rx_byte_count += bytesRead; // not just yet - keep waiting o.m_s.BeginReceive(o.m_rx_buffer, o.m_rx_byte_count, o.m_rx_remaining_count, SocketFlags.None, new AsyncCallback(RxCallback), o); }
public abstract void HandlePacket(ecProto.ecPacket packet);
void m_download_status_ctrl_OnPauseItem() { ecProto.ecPacket cmd = new ecProto.ecPacket(ECOpCodes.EC_OP_PARTFILE_PAUSE); m_download_status_ctrl.SelectedItemsToCommand(cmd); m_amuleRemote.SendPacket(cmd); }