Carnivore Throttling
in
Contributed Library Questions
•
2 years ago
What's the best way, or what are some ways, to implement throttling of the packets processed by carnivore? I'm asking this question here because I am unable to login to the carnivore forum -- the activation link sent in e-mail doesn't seem to work. I'm running a modified version of the code below that needs to analyze packet data (obtain hostip address substrings, etc..). This event 'synchronized void packetEvent (CarnivorePacket paket' in the following code runs each time a packet is received. I've noticed that when there is a lot of network traffic, i.e. simultaneous video and audio downloads, etc., that I am getting exception errors. One method I can think of would be to wrap a 'try' 'catch' expression around void packetEvent and use the 'c.setVolumeLimit' command to throttle to a reasonable number of bits per second.
I can't tell for certain, but, it looks like the packetEvent function is called whenever carnivore detects a packet and there's no way to tell carnivore not to call a packetEvent based on contents of the packet, like packet size or port, without calling the packetEvent first to determine the packet size, port, or other variables.
I need to be able to calculate the bits per second in order to compare it to the x in setVolumeLimit(x) and increase or decrease the bits per second appropriately. Does anyone know how to calculate the bits per second. Ideally, I want to dynamically adjust the bits per second to the highest possible amount without skipping packets, throttle when the bits per second is too fast for processing to be able to display the contents of the packet as text (or search for substrings with packets of certain ports, e.g. hosts in packets to/from port 138 (netbios), and then remove the throttle when traffic levels are low enough for processing. I need to be able to keep track of the throttling so I can display whether packets are being throttled or not. Calculations need to be as efficient as possible or they will slow things down and require more throttling.
Isn't it a lot better if I throttle based upon a measured value than if I throttle based upon whether exceptions are being thrown due to too much traffic?
Surely, folks that have used carnivore with processing would have had some experience with throttling and/or have noticed exceptions being thrown with heavy (or even moderate to light) traffic?
This is the 'official' carnivore example #1, unedited:
I can't tell for certain, but, it looks like the packetEvent function is called whenever carnivore detects a packet and there's no way to tell carnivore not to call a packetEvent based on contents of the packet, like packet size or port, without calling the packetEvent first to determine the packet size, port, or other variables.
I need to be able to calculate the bits per second in order to compare it to the x in setVolumeLimit(x) and increase or decrease the bits per second appropriately. Does anyone know how to calculate the bits per second. Ideally, I want to dynamically adjust the bits per second to the highest possible amount without skipping packets, throttle when the bits per second is too fast for processing to be able to display the contents of the packet as text (or search for substrings with packets of certain ports, e.g. hosts in packets to/from port 138 (netbios), and then remove the throttle when traffic levels are low enough for processing. I need to be able to keep track of the throttling so I can display whether packets are being throttled or not. Calculations need to be as efficient as possible or they will slow things down and require more throttling.
Isn't it a lot better if I throttle based upon a measured value than if I throttle based upon whether exceptions are being thrown due to too much traffic?
Surely, folks that have used carnivore with processing would have had some experience with throttling and/or have noticed exceptions being thrown with heavy (or even moderate to light) traffic?
This is the 'official' carnivore example #1, unedited:
import java.util.Iterator;
import org.rsg.carnivore.*;
import org.rsg.carnivore.net.*;
HashMap nodes = new HashMap();
float startDiameter = 100.0;
float shrinkSpeed = 0.97;
int splitter, x, y;
PFont font;
void setup()
{
size(800, 600);
background(255);
frameRate(10);
Log.setDebug(true); // Uncomment this for verbose mode
CarnivoreP5 c = new CarnivoreP5(this);
//c.setVolumeLimit(4);
// Use the "Create Font" tool to add a 12 point font to your sketch,
// then use its name as the parameter to loadFont().
font = loadFont("CourierNew-12.vlw");
textFont(font);
}
void draw()
{
background(255);
drawNodes();
}
// Iterate through each node
synchronized void drawNodes() {
Iterator it = nodes.keySet().iterator();
while (it.hasNext()) {
String ip = (String)it.next();
float d = float(nodes.get(ip).toString());
// Use last two IP address bytes for x/y coords
splitter = ip.lastIndexOf(".");
y = int(ip.substring(splitter + 1)) * height / 255; // Scale to applet size
String tmp = ip.substring(0, splitter);
splitter = tmp.lastIndexOf(".");
x = int(tmp.substring(splitter + 1)) * width / 255; // Scale to applet size
// Draw the node
stroke(0);
fill(color(100, 200)); // Rim
ellipse(x, y, d, d); // Node circle
noStroke();
fill(color(100, 50)); // Halo
ellipse(x, y, d + 20, d + 20);
// Draw the text
fill(0);
text(ip, x, y);
// Shrink the nodes a little
nodes.put(ip, str(d * shrinkSpeed));
}
}
// Called each time a new packet arrives
synchronized void packetEvent(CarnivorePacket packet)
{
println("[PDE] packetEvent: " + packet);
// Remember these nodes in our hash map
nodes.put(packet.receiverAddress.toString(), str(startDiameter));
nodes.put(packet.senderAddress.toString(), str(startDiameter));
}
1