public override MemoryStream reportBack() { //Dictionary<string, int> metricSinners = new Dictionary<string, int>(); string metricName = this.GetType().Name; //--------------------------// // calculate metrc value // //--------------------------// //lock (sinnerList) { // //We do register if a connection happens only once or more often, but we ignore that.. // foreach (KeyValuePair<string, Hashtable> sourceEntry in sinnerList) { // System.Console.WriteLine(sourceEntry.Key + " talked to " + sourceEntry.Value.Count + " trackers"); // metricSinners.Add(sourceEntry.Key, sourceEntry.Value.Count); // } //} MemoryStream stream = new MemoryStream(); lock (sinnerList) { CSF_metric metric = new CSF_metric(metricName, sinnerList); DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(CSF_metric)); js.WriteObject(stream, metric); } return(stream); }
public override MemoryStream reportBack() { //Dictionary<string, int> sinners = new Dictionary<string, int>(); string metricName = "CSF_HighDataDiffPeers"; //lock (connections){ // foreach(KeyValuePair<string, Hashtable> sourceEntry in connections) { // string ip = sourceEntry.Key; // Hashtable table = sourceEntry.Value; // int bigConnectionsCount = 0; // foreach (DictionaryEntry pair in table) { // if((int)pair.Value > minimumDataConnection) { // bigConnectionsCount++; // } // } // if( bigConnectionsCount > 0 ){ // System.Console.WriteLine ( ip + " talked to " + bigConnectionsCount + " IPs with more than " + minimumDataConnection + " of MB of data exchanged"); // sinners.Add(ip, bigConnectionsCount); // } // } //} MemoryStream stream = new MemoryStream(); lock (connections) { CSF_metric metric = new CSF_metric(metricName, connections); DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(CSF_metric)); js.WriteObject(stream, metric); } return(stream); }
private CSF_metric correctMetric(CSF_metric metric) { string strMetric = metric.Metric; CSF_metric toReturn = metric; switch (strMetric) { case "CSF_HighDataDiffPeers" : toReturn = new CSF_metricHighDataDiffPeers(strMetric, metric.RawValues); break; case "CSF_ProtocolUPnP": toReturn = new CSF_metricProtocolUPnP(strMetric, metric.Sinners); break; case "CSF_LocalPeerDiscovery": toReturn = new CSF_metricLocalPeerDiscovery(strMetric, metric.Sinners); break; case "CSF_KnownTrackers": toReturn = new CSF_metricKnownTrackers(strMetric, metric.RawValues); break; case "CSF_IpInName": toReturn = new CSF_metricIpInName(strMetric, metric.RawValues); break; case "CSF_HighUpload": toReturn = new CSF_metricHighUpload(strMetric, metric.RawValues); break; case "CSF_HighDownload": toReturn = new CSF_metricHighDownload(strMetric, metric.RawValues); break; default: System.Console.WriteLine("\n\nNOT FOUND!!!\n\n" + strMetric + "\n\n"); break; } return toReturn; }
public override MemoryStream reportBack() { //Dictionary<string, int> metricSinners = new Dictionary<string, int>(); string metricName = this.GetType().Name; //--------------------------// // calculate metrc value // //--------------------------// //lock(connections){ // foreach(KeyValuePair<string, Hashtable> sourceEntry in connections) { // string ip = sourceEntry.Key; // Hashtable table = sourceEntry.Value; // int downloadSize = 0; // foreach (DictionaryEntry pair in table) { // downloadSize += (int)pair.Value; // } // if( downloadSize > minimumHighDownload ){ // System.Console.WriteLine ( ip + " uploaded " + downloadSize + ", triggered when more than " + minimumHighDownload + " MB of data uploaded"); // metricSinners.Add(ip, downloadSize); // } // } //} MemoryStream stream = new MemoryStream(); lock (connections) { CSF_metric metric = new CSF_metric(metricName, this.connections); DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(CSF_metric)); js.WriteObject(stream, metric); } return(stream); }
private void mergeIpInName(CSF_metric other) { Dictionary <string, Hashtable> originalList = this.original.RawValues; Dictionary <string, Hashtable> otherList = other.RawValues; if (otherList == null) { // nothing to be merged.. if (originalList == null) { originalList = new Dictionary <string, Hashtable>(); } return; } else if (originalList == null) { if (otherList != null) //it is always true { originalList = otherList; } else { originalList = new Dictionary <string, Hashtable>(); } return; } //Go through every entry in the otherList foreach (KeyValuePair <string, Hashtable> othersEntry in otherList) { Hashtable existingCommunications; //Check if the original's list has this sinner already if (originalList.TryGetValue(othersEntry.Key, out existingCommunications)) { //Lets increase the sin then.. foreach (DictionaryEntry connection in othersEntry.Value) { //check if it is the first time they talk if (existingCommunications.ContainsKey(connection.Key)) { //More talks to the same guy existingCommunications [connection.Key] = (int)existingCommunications [connection.Key] + (int)connection.Value; } else { //Oh new guy added existingCommunications [connection.Key] = connection.Value; } } } else //it does not have, simple we will add this sinner to the list { originalList [othersEntry.Key] = othersEntry.Value; } } //Update the table original.RawValues = originalList; }
private void doOperation(string operation, ConnectionPack cp) { DADStormProcess.ClientProcess process = new DADStormProcess.ClientProcess(cp); if(operation.Equals("report", StringComparison.OrdinalIgnoreCase)) { MemoryStream stream = process.reportBack(); if(stream != null) { stream.Position = 0; CSF_metric metric = correctMetric((CSF_metric)js.ReadObject(stream)); metrics.Add(metric); } } if (operation.Equals("reset", StringComparison.OrdinalIgnoreCase)) { process.reset(); } }
private void mergeMetrics(){ for(int index = 0 ; index < ( metrics.Count - 1) ; index++) { CSF_metric original = metrics[index]; MergingVisitor visitor = new MergingVisitor(original); for(int endIndex = index+1 ; endIndex < metrics.Count; ) { CSF_metric toBeMerged = metrics[endIndex]; if(toBeMerged.aceptWithBool(visitor)) { metrics.RemoveAt(endIndex); } else { endIndex++; } } } }
public override MemoryStream reportBack() { Dictionary <string, int> metricSinners = new Dictionary <string, int>(); string metricName = this.GetType().Name; //--------------------------// // calculate metrc value // //--------------------------// CSF_metric metric = new CSF_metric(metricName, metricSinners); DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(CSF_metric)); MemoryStream stream = new MemoryStream(); js.WriteObject(stream, metric); return(stream); }
public override MemoryStream reportBack() { //Dictionary<string, int> metricSinners = sinnerList; string metricName = this.GetType().Name; //--------------------------// // calculate metrc value // //--------------------------// //the sinnerList already has value MemoryStream stream = new MemoryStream(); lock (sinnerList) { CSF_metric metric = new CSF_metric(metricName, sinnerList); DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(CSF_metric)); js.WriteObject(stream, metric); } return(stream); }
private void mergeLocalPeerDiscovery(CSF_metric other) { Dictionary <string, int> originalList = original.Sinners; Dictionary <string, int> otherList = other.Sinners; if (otherList == null) { // nothing to be merged.. if (originalList == null) { originalList = new Dictionary <string, int>(); } return; } else if (originalList == null) { if (otherList != null) //it is always true { originalList = otherList; } else { originalList = new Dictionary <string, int>(); } return; } //else there is something to merge //Go through every entry in the otherList foreach (KeyValuePair <string, int> othersEntry in otherList) { if (originalList.ContainsKey(othersEntry.Key)) { originalList[othersEntry.Key] = originalList[othersEntry.Key] + othersEntry.Value; } else { originalList[othersEntry.Key] = othersEntry.Value; } } }
private void mergeHighDataDiffPeers(CSF_metric other) { this.mergeIpInName(other); }
bool sameType(CSF_metric other) { return(this.original.Metric.Equals(other.Metric)); }
public MergingVisitor(CSF_metric original) { this.original = original; }
private void mergeProtocolUPnP(CSF_metric other) { this.mergeLocalPeerDiscovery(other); }
private void processMetric(MetricCalculatorVisitor visitor, CSF_metric metric) { metric.acept(visitor); }
public void visit(CSF_metric metric) { throw new Exception("Merging does not do the general ABSTRACT type.."); }
private void mergeHighDownload(CSF_metric other) { this.mergeIpInName(other); }
public bool visitWithBool(CSF_metric metric) { throw new Exception("Merging does not do the general ABSTRACT type.."); }
private void mergeKnownTrackers(CSF_metric other) { this.mergeIpInName(other); }