// parse the many hubs data there are in a ack packet private G2Packet HandlePacketQA(NodePeer p, G2PacketQA pack) { foreach (G2Packet child in pack.children) { if (child.type == G2PacketType.S) // search hubs data { G2PacketS s = child as G2PacketS; if (s == null) { continue; } if (s.Timestamp != -1) { DateTime lastSeen = BinaryUtils.UnixTimeStampToDateTime(s.Timestamp); cache.AddHub(new NodePeer(s.Node.ipv4, s.Node.port, lastSeen, true)); } else { cache.AddHub(new NodePeer(s.Node.ipv4, s.Node.port, DateTime.Now, true)); } } else if (child.type == G2PacketType.RA) { G2PacketRA ra = child as G2PacketRA; if (ra == null || ra.Seconds == 0) { continue; } p.DontQueryBefore(ra.Seconds * 1000); } else if (child.type == G2PacketType.D) { G2PacketD d = child as G2PacketD; if (d.Node != null) { cache.AddHub(new NodePeer(d.Node, true)); } } } return(null); }
/** * Take a search related packets i.e. QA (ack) or QH2 (hit) * and stores it into SearchResults class * */ public void EnqueueResultPacket(NodePeer p, G2Packet pack) { // a hub packet ACK a query if (pack.type == G2PacketType.QA) { G2PacketQA qa = pack as G2PacketQA; G2SearchResults res = null; bool exists = SearchResults.TryGetValue(qa.guid, out res); if (!exists) // no entry => not a search we initiated { G2Log.Write("G2SearchManager : Received ACK of non asked Query"); } else { res.SetAcknowledgement(qa); G2Log.Write("G2SearchManager Received ACK of search " + SearchDB[qa.guid].Keywords[0]); } } // Hit packet ! else if (pack.type == G2PacketType.QH2) { G2PacketQH2 qh2 = pack as G2PacketQH2; G2SearchResults res = null; bool exists = SearchResults.TryGetValue(qh2.searchGuid, out res); if (exists) { // a new result packet coming for a requested query res.PushResultPacket(qh2); //if (res.TotalFiles > MAX_RESULTS) // G2Network.Instance.StopNetwork(); } else // got a response for a query we did not ask ? { G2Log.Write("G2SearchManager : Received a Hit on a NON ASKED Query"); } } }
/** * Just store the resquest acknolwdgement received * */ public void SetAcknowledgement(G2PacketQA ack) { ACKPacket.Add(ack); }