Beispiel #1
0
        public static G2Packet getPacketByHeader(Header h)
        {
            G2Packet packet = null;
            switch(h.type) {
            case G2PacketType.PVU:
                packet = new G2PacketPVU (h);
                break;
            case G2PacketType.COM:
                packet = new G2PacketCOM (h);
                break;
            case G2PacketType.PART:
                packet = new G2PacketPART(h);
                break;
            case G2PacketType.SZ:
                packet = new G2PacketSZ (h);
                break;
            case G2PacketType.Q2:
                packet = new G2PacketQ2 (h);
                break;
            case G2PacketType.DN:
                packet = new G2PacketDN (h);
                break;
            case G2PacketType.KHL:
                packet = new G2PacketKHL (h);
                break;
            case G2PacketType.QA:
                packet = new G2PacketQA (h);
                break;
            case G2PacketType.SS:
                packet = new G2PacketSS (h);
                break;
            case G2PacketType.QH2:
                packet = new G2PacketQH2 (h);
                break;
            case G2PacketType.HG:
                packet = new G2PacketHG (h);
                break;
            case G2PacketType.PI:
                packet = new G2PacketPI (h);
                break;
            case G2PacketType.UDP:
                packet = new G2PacketUDP (h);
                break;
            case G2PacketType.PO:
                packet = new G2PacketPO (h);
                break;
            case G2PacketType.S:
                packet = new G2PacketS(h);
                break;
            case G2PacketType.D:
                packet = new G2PacketD(h);
                break;
            case G2PacketType.LNI:
                packet = new G2PacketLNI (h);
                break;
            case G2PacketType.GU:
                packet = new G2PacketGU (h);
                break;
            case G2PacketType.NA:
                packet = new G2PacketNA (h);
                break;
            case G2PacketType.QKR:
                packet = new G2PacketQKR (h);
                break;
            case G2PacketType.QKA:
                packet = new G2PacketQKA (h);
                break;
            case G2PacketType.SNA:
                packet = new G2PacketSNA (h);
                break;
            case G2PacketType.QNA:
                packet = new G2PacketQNA (h);
                break;
            case G2PacketType.V:
                packet = new G2PacketV (h);
                break;
            case G2PacketType.LS:
                packet = new G2PacketLS (h);
                break;
            case G2PacketType.HS:
                packet = new G2PacketHS (h);
                break;
            case G2PacketType.TLS:
                packet = new G2PacketTLS (h);
                break;
            case G2PacketType.TS:
                packet = new G2PacketTS (h);
                break;
            case G2PacketType.NH:
                packet = new G2PacketNH (h);
                break;
            case G2PacketType.RA:
                packet = new G2PacketRA (h);
                break;
            case G2PacketType.BUP:
                packet = new G2PacketBUP (h);
                break;
            case G2PacketType.H:
                packet = new G2PacketH (h);
                break;
            case G2PacketType.URL:
                packet = new G2PacketURL (h);
                break;
            case G2PacketType.URN:
                packet = new G2PacketURN (h);
                break;
            case G2PacketType.UPRO:
                packet = new G2PacketUPRO (h);
                break;
            case G2PacketType.NICK:
                packet = new G2PacketNICK (h);
                break;
            case G2PacketType.BH:
                packet = new G2PacketBH (h);
                break;
            case G2PacketType.FW:
                packet = new G2PacketFW (h);
                break;
            case G2PacketType.MD:
                packet = new G2PacketMD (h);
                break;
            case G2PacketType.UPROC:
               packet = new G2PacketUPROC(h);
               break;
            case G2PacketType.UPROD :
               packet = new G2PacketUPROD(h);
               break;
               case G2PacketType.XML:
               packet = new G2PacketXML(h);
               break;
            default :
                packet = new G2PacketDefault (h);
                break;

            }
            return packet;
        }
Beispiel #2
0
 /**
  * Just store the resquest acknolwdgement received
  * */
 public void SetAcknowledgement(G2PacketQA ack)
 {
     ACKPacket.Add(ack);
 }
Beispiel #3
0
        public static G2Packet getPacketByHeader(Header h)
        {
            G2Packet packet = null;

            switch (h.type)
            {
            case G2PacketType.PVU:
                packet = new G2PacketPVU(h);
                break;

            case G2PacketType.COM:
                packet = new G2PacketCOM(h);
                break;

            case G2PacketType.PART:
                packet = new G2PacketPART(h);
                break;

            case G2PacketType.SZ:
                packet = new G2PacketSZ(h);
                break;

            case G2PacketType.Q2:
                packet = new G2PacketQ2(h);
                break;

            case G2PacketType.DN:
                packet = new G2PacketDN(h);
                break;

            case G2PacketType.KHL:
                packet = new G2PacketKHL(h);
                break;

            case G2PacketType.QA:
                packet = new G2PacketQA(h);
                break;

            case G2PacketType.SS:
                packet = new G2PacketSS(h);
                break;

            case G2PacketType.QH2:
                packet = new G2PacketQH2(h);
                break;

            case G2PacketType.HG:
                packet = new G2PacketHG(h);
                break;

            case G2PacketType.PI:
                packet = new G2PacketPI(h);
                break;

            case G2PacketType.UDP:
                packet = new G2PacketUDP(h);
                break;

            case G2PacketType.PO:
                packet = new G2PacketPO(h);
                break;

            case G2PacketType.S:
                packet = new G2PacketS(h);
                break;

            case G2PacketType.D:
                packet = new G2PacketD(h);
                break;

            case G2PacketType.LNI:
                packet = new G2PacketLNI(h);
                break;

            case G2PacketType.GU:
                packet = new G2PacketGU(h);
                break;

            case G2PacketType.NA:
                packet = new G2PacketNA(h);
                break;

            case G2PacketType.QKR:
                packet = new G2PacketQKR(h);
                break;

            case G2PacketType.QKA:
                packet = new G2PacketQKA(h);
                break;

            case G2PacketType.SNA:
                packet = new G2PacketSNA(h);
                break;

            case G2PacketType.QNA:
                packet = new G2PacketQNA(h);
                break;

            case G2PacketType.V:
                packet = new G2PacketV(h);
                break;

            case G2PacketType.LS:
                packet = new G2PacketLS(h);
                break;

            case G2PacketType.HS:
                packet = new G2PacketHS(h);
                break;

            case G2PacketType.TLS:
                packet = new G2PacketTLS(h);
                break;

            case G2PacketType.TS:
                packet = new G2PacketTS(h);
                break;

            case G2PacketType.NH:
                packet = new G2PacketNH(h);
                break;

            case G2PacketType.RA:
                packet = new G2PacketRA(h);
                break;

            case G2PacketType.BUP:
                packet = new G2PacketBUP(h);
                break;

            case G2PacketType.H:
                packet = new G2PacketH(h);
                break;

            case G2PacketType.URL:
                packet = new G2PacketURL(h);
                break;

            case G2PacketType.URN:
                packet = new G2PacketURN(h);
                break;

            case G2PacketType.UPRO:
                packet = new G2PacketUPRO(h);
                break;

            case G2PacketType.NICK:
                packet = new G2PacketNICK(h);
                break;

            case G2PacketType.BH:
                packet = new G2PacketBH(h);
                break;

            case G2PacketType.FW:
                packet = new G2PacketFW(h);
                break;

            case G2PacketType.MD:
                packet = new G2PacketMD(h);
                break;

            case G2PacketType.UPROC:
                packet = new G2PacketUPROC(h);
                break;

            case G2PacketType.UPROD:
                packet = new G2PacketUPROD(h);
                break;

            case G2PacketType.XML:
                packet = new G2PacketXML(h);
                break;

            default:
                packet = new G2PacketDefault(h);
                break;
            }
            return(packet);
        }
        // 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;
        }