示例#1
0
        private static void ___AddOrUpdate_PeerProfile(PeerDataMessage pdm)
        {
            try
            {
                PeerProfile pp = JsonConvert.DeserializeObject <PeerProfile>((string)pdm.hData[KW.Params]);
                pp.IpAddress = pdm.packet.IpAddress;    // Get Real IP Address
                PeerProfile pp_now = null;

                lock (hPeerProfile.SyncRoot)
                {
                    if (hPeerProfile.Contains(pp.PeerID))
                    {
                        pp_now = (PeerProfile)hPeerProfile[pp.PeerID];

                        pp_now.TotalProfile = pp.TotalProfile;
                        pp_now.Version      = pp.Version;
                        pp_now.UpdateTime   = pp.UpdateTime;

                        that.DebugAndLog("Update Existing PeerProfile ID=" + pp.PeerID);
                        pp = null;      // Dispose Memory
                    }
                    else
                    {
                        hPeerProfile[pp.PeerID] = pp;   // Link this memory to hPeerProfile
                        that.DebugAndLog("Add New PeerProfile ID=" + pp.PeerID);
                    }
                }
            }
            catch (Exception ex)
            {
                that.DebugAndLog("Invalid JSON->PeerProfile: " + ex.Message);
            }
        }
示例#2
0
        private static void _ThreadProcess_DataMessage()
        {
            zLog.Write("Starting ... Thread");

            int             countMessage = 0;
            PeerDataMessage pdm          = null;

            while (!P2P.IsTerminate)
            {
                lock (P2P.queDataMessage.SyncRoot) { countMessage = P2P.queDataMessage.Count; }
                if (countMessage < 1)
                {
                    P2P.trickDataMessage.WaitOne(100, true);
                    P2P.trickDataMessage.Reset();
                    continue;
                }

                lock (P2P.queDataMessage.SyncRoot) { pdm = (PeerDataMessage)P2P.queDataMessage.Dequeue(); }
                if (pdm.isResponse)
                {
                    __Process_DataMessage_Response(pdm);
                }
                else
                {
                    __Process_DataMessage_Request(pdm);
                }
            }

            zLog.Write("Terminate ... Thread");
        }
示例#3
0
        private static void __Process_DataMessage_Request(PeerDataMessage pdm)
        {
            string method = ((string)pdm.hData[KW.Method]).Trim().ToLower();

            switch (method)
            {
            case KW.NotifyPeerProfile: ___AddOrUpdate_PeerProfile(pdm); break;
            }
        }
示例#4
0
 private static void __Process_DataMessage_Response(PeerDataMessage pdm)
 {
 }