private void newReqReceived(Package receivedPackage) { Utils.Utils.Log("Event: newReqReceived reqId: " + receivedPackage.uuid); byte[] mcontentCache = new byte[receivedPackage.totalSize]; lock (mPackageCacheLock) { if (mPackageCache.ContainsKey(receivedPackage.uuid)) { mcontentCache = mPackageCache[receivedPackage.uuid]; mPackageCache.Remove(receivedPackage.uuid); } } receivedPackage.content.CopyTo(mcontentCache, receivedPackage.startIndex); // check if this is a response lock (mPendingReqLock) { if (mPendingReqList.ContainsKey(receivedPackage.uuid)) { Utils.Utils.Log("Event: newResponse Received reqId: " + receivedPackage.uuid); mPendingReqList[receivedPackage.uuid](ToxResponse.fromBytes(mcontentCache)); mPendingReqList.Remove(receivedPackage.uuid); return; } } ToxRequest newReq = ToxRequest.fromBytes(mcontentCache); if (newReq.method == "") { Console.WriteLine("this happends, this is an ugly hack"); return; } if (newReq == null) { Utils.Utils.Log("Event: Invalid Request Data: receivedPackage " + receivedPackage.uuid); return; } Utils.Utils.Log("Event: Start callbacks reqId: " + newReq.uuid); Utils.Utils.Log("Event: Begin Process MessageID: " + newReq.uuid); if (newReq.url == "/msg") { Utils.Utils.Log("Event: Message toNodeID: " + newReq.toNodeId + ", totoxid:" + newReq.toToxId); } lock (reqListnerLock) { if (reqCallbacks.Keys.Contains(newReq.toNodeId)) { reqCallbacks[newReq.toNodeId](newReq); } } Utils.Utils.Log("Event: End callbacks"); }
void newReqReceived(Package receivedPackage) { byte[] mcontentCache = new byte[receivedPackage.totalSize]; if (mPackageCache.ContainsKey(receivedPackage.uuid)) { mcontentCache = mPackageCache [receivedPackage.uuid]; mPackageCache.Remove(receivedPackage.uuid); } receivedPackage.content.CopyTo(mcontentCache, receivedPackage.startIndex); // check if this is a response lock (mPendingReqLock) { if (mPendingReqList.ContainsKey(receivedPackage.uuid)) { mPendingReqList [receivedPackage.uuid] (ToxResponse.fromBytes(mcontentCache)); mPendingReqList.Remove(receivedPackage.uuid); return; } } ToxRequest newReq = ToxRequest.fromBytes(mcontentCache); if (newReq == null) { Utils.Utils.LogUtils("Event: Invalid Request Data: receivedPackage " + receivedPackage.uuid); return; } List <Action <ToxRequest> > tempReqList; lock (reqListnerLock) { tempReqList = new List <Action <ToxRequest> > (reqCallbacks); } Utils.Utils.LogUtils("Event: Start callbacks"); foreach (var cb in tempReqList) { Utils.Utils.LogUtils("Event: Begin Process MessageID: " + newReq.uuid); if (newReq.url == "/msg") { Utils.Utils.LogUtils("Event: Message toNodeID: " + newReq.toNodeId + ", totoxid:" + newReq.toToxId); } cb(newReq); } Utils.Utils.LogUtils("Event: End callbacks"); }