Commit 97145194 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added support for counting server bytes.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4078 b35dd754-fafc-0310-a699-88a17e54d16e
parent dfad9ae2
......@@ -45,8 +45,8 @@ class BlockingReadingMode extends SocketReadingMode {
*/
public void run() {
try {
socketReader.reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(),
CHARSET));
socketReader.reader.getXPPParser().setInput(new InputStreamReader(
ServerTrafficCounter.wrapInputStream(socket.getInputStream()), CHARSET));
// Read in the opening tag and prepare for packet stream
try {
......@@ -188,7 +188,8 @@ class BlockingReadingMode extends SocketReadingMode {
XmlPullParser xpp = socketReader.reader.getXPPParser();
// Reset the parser since a new stream header has been sent from the client
if (socketReader.connection.getTLSStreamHandler() == null) {
ZInputStream in = new ZInputStream(socket.getInputStream());
ZInputStream in = new ZInputStream(
ServerTrafficCounter.wrapInputStream(socket.getInputStream()));
in.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
xpp.setInput(new InputStreamReader(in, CHARSET));
}
......
......@@ -147,6 +147,7 @@ class NonBlockingReadingMode extends SocketReadingMode {
else {
is = socket.getInputStream();
}
is = ServerTrafficCounter.wrapInputStream(is);
ZInputStream in = new ZInputStream(is);
in.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
......
......@@ -125,10 +125,12 @@ public class SocketConnection implements Connection {
this.socket = socket;
// DANIELE: Modify socket to use channel
if (socket.getChannel() != null) {
writer = Channels.newWriter(socket.getChannel(), CHARSET);
writer = Channels.newWriter(
ServerTrafficCounter.wrapWritableChannel(socket.getChannel()), CHARSET);
}
else {
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), CHARSET));
writer = new BufferedWriter(new OutputStreamWriter(
ServerTrafficCounter.wrapOutputStream(socket.getOutputStream()), CHARSET));
}
this.backupDeliverer = backupDeliverer;
xmlSerializer = new XMLSocketWriter(writer, this);
......@@ -186,7 +188,9 @@ public class SocketConnection implements Connection {
compressed = true;
if (tlsStreamHandler == null) {
ZOutputStream out = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_COMPRESSION);
ZOutputStream out = new ZOutputStream(
ServerTrafficCounter.wrapOutputStream(socket.getOutputStream()),
JZlib.Z_BEST_COMPRESSION);
out.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
writer = new BufferedWriter(new OutputStreamWriter(out, CHARSET));
xmlSerializer = new XMLSocketWriter(writer, this);
......
......@@ -49,10 +49,11 @@ public class TLSStreamReader {
wrapper = tlsWrapper;
// DANIELE: Add code to use directly the socket channel
if (socket.getChannel() != null) {
rbc = socket.getChannel();
rbc = ServerTrafficCounter.wrapReadableChannel(socket.getChannel());
}
else {
rbc = Channels.newChannel(socket.getInputStream());
rbc = Channels.newChannel(
ServerTrafficCounter.wrapInputStream(socket.getInputStream()));
}
inNetBB = ByteBuffer.allocate(wrapper.getNetBuffSize());
inAppBB = ByteBuffer.allocate(wrapper.getAppBuffSize());
......
......@@ -40,10 +40,11 @@ public class TLSStreamWriter {
wrapper = tlsWrapper;
// DANIELE: Add code to use directly the socket channel
if (socket.getChannel() != null) {
wbc = socket.getChannel();
wbc = ServerTrafficCounter.wrapWritableChannel(socket.getChannel());
}
else {
wbc = Channels.newChannel(socket.getOutputStream());
wbc = Channels.newChannel(
ServerTrafficCounter.wrapOutputStream(socket.getOutputStream()));
}
outAppData = ByteBuffer.allocate(tlsWrapper.getAppBuffSize());
}
......@@ -63,8 +64,8 @@ public class TLSStreamWriter {
}
private void tlsWrite(ByteBuffer buf) throws IOException {
ByteBuffer tlsBuffer = null;
ByteBuffer tlsOutput = null;
ByteBuffer tlsBuffer;
ByteBuffer tlsOutput;
do {
// TODO Consider optimizing by not creating new instances each time
tlsBuffer = ByteBuffer.allocate(Math.min(buf.remaining(), wrapper.getAppBuffSize()));
......
......@@ -21,6 +21,7 @@ import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.auth.AuthFactory;
import org.jivesoftware.wildfire.net.DNSUtil;
import org.jivesoftware.wildfire.net.MXParser;
import org.jivesoftware.wildfire.net.ServerTrafficCounter;
import org.jivesoftware.wildfire.net.SocketConnection;
import org.jivesoftware.wildfire.spi.BasicStreamIDFactory;
import org.xmlpull.v1.XmlPullParser;
......@@ -168,8 +169,8 @@ class ServerDialback {
XMPPPacketReader reader = new XMPPPacketReader();
reader.setXPPFactory(FACTORY);
reader.getXPPParser().setInput(new InputStreamReader(socket.getInputStream(),
CHARSET));
reader.getXPPParser().setInput(new InputStreamReader(
ServerTrafficCounter.wrapInputStream(socket.getInputStream()), CHARSET));
// Get the answer from the Receiving Server
XmlPullParser xpp = reader.getXPPParser();
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG;) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment