Commit 853f5264 authored by Michael König's avatar Michael König

quick fix for socket-inputBackend

parent f5f05487
requirements.txt
tags
venv/
build/
dist/
__pycache__/
......
......@@ -3,21 +3,25 @@
from setuptools import setup
version = 0.1.0
# keep in sync with main.py (!)
version = "0.2.0"
desc = "Realtime-visualization of TCP flows logged by TCPlog."
setup(
name = "tcpliveplot",
packages = [
"tcpliveplot",
"tcpliveplot.input"
"tcpliveplot.utils",
"tcpliveplot.backends",
"tcpliveplot.backends.gui",
"tcpliveplot.backends.input"
],
entry_points = {
"console_scripts": [
'tcpliveplot = tcpliveplot.tcpliveplot:main'
'tcpliveplot = tcpliveplot.main:main'
],
"gui_scripts": [
'tcpliveplot = tcpliveplot.tcpliveplot:main'
'tcpliveplot = tcpliveplot.main:main'
]
},
......@@ -33,14 +37,9 @@ setup(
platforms = "Linux",
zip_safe = False,
install_requires = [
# TODO
# numpy
# matplotlib
#
'matplotlib==1.4.0',
'tcplog>=0.2'
],
extras_require = {
'Logging': ["tcplog"]
},
keywords = ['tcp', 'flow', 'plot', 'visualize', 'graph', 'live', 'analyze', 'network', 'traffic'],
classifiers = [
'Development Status :: 4 - Beta',
......
......@@ -9,6 +9,7 @@
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import matplotlib.animation as animation
from matplotlib.widgets import Button, RadioButtons
import numpy as np
......@@ -40,6 +41,10 @@ class LiveGui(GuiBase):
self.infoRegistry = infoRegistry
self.__stopped = threading.Event()
self.timestampOfLastGuiRefresh = 0
if(self.options.debug):
print("matplotlib-version: " + matplotlib.__version__)
print("available matplotlib-styles:" + str(plt.style.available))
def setConnectionBuffer(self, connectionBuffer):
self.__connectionBuffer = connectionBuffer
......@@ -133,6 +138,7 @@ class LiveGui(GuiBase):
fig = plt.figure(FIGURE_TITLE)
fig.canvas.mpl_connect('key_press_event', self.plotKeyPressCallback)
self.__ax = plt.axes()
# self.__ax2 = self.__ax.twinx()
self.__ax.set_autoscaley_on(False)
self.__ax.set_xlim(0, self.options.xDelta)
self.__ax.set_title(PLOT_TITLE + " :" + ', :'.join(map(str, self.options.filterPorts)))
......@@ -155,6 +161,10 @@ class LiveGui(GuiBase):
self.__plotValues[port][val] = deque(maxlen=(int(self.options.xDelta / self.options.plotResolution * 10)))
index = 1
for val in VALUES_TO_PLOT:
# if(val == "rtt"):
# print("bla")
# self.__plotLines[port][val], = self.__ax2.plot([])
# else:
self.__plotLines[port][val], = self.__ax.plot([])
self.__plotLines[port][val].set_label("[" + str(index) + "] " + val + " - " + str(port) + "")
self.__plotLineConfigs[port][val] = True
......@@ -198,7 +208,6 @@ class LiveGui(GuiBase):
self.__apsFixFactor = 1
# call update-routine
print("foo")
# self.plotInit()
# self.__plotLine = self.plotGraphUpdate(0)
animation.FuncAnimation(fig, self.plotGraphUpdate, init_func=self.plotInit, frames=self.options.drawFps, interval=self.options.drawIntervall, blit=self.options.blitting, repeat=True)
......
......@@ -3,6 +3,7 @@
import time
import socket
from ipaddress import ip_address
from collections import deque
from .input_base import InputBase
......@@ -19,6 +20,8 @@ class SocketInput(InputBase):
def __init__(self, options, infoRegistry):
self.options = options
self.infoRegistry = infoRegistry
self.__incomeBuffer = deque();
self.incomeBuffer = deque();
ip, separator, port = self.options.logServer.rpartition(':')
if(':' not in self.options.logServer or port is ''):
......@@ -62,6 +65,20 @@ class SocketInput(InputBase):
Reads data (in blocks) from a socket and adds the received data to an temporaray income buffer.
"""
self.retrieveDataFromSocket();
self.processDataFromSocket();
data = []
while(True):
try:
dataLine = self.incomeBuffer.popleft()
except IndexError:
return data
else:
data.append(dataLine)
def retrieveDataFromSocket(self):
try:
data = self.socket.recv(4096)
except socket.timeout:
......@@ -76,30 +93,29 @@ class SocketInput(InputBase):
if(len(data) == 0):
print("Connection closed by foreign host.")
self.socket.close()
return data
self.tmpBuffer.append(data)
else:
self.__incomeBuffer.append(data)
def processSocketLogData(self):
def processDataFromSocket(self):
"""Reads data from the income buffer and tries to reassemble splitted data."""
tmpBuffer = ""
while(True):
try:
line = self.__incomeBuffer.popleft()
line = line.decode("UTF-8")
lines = line.split("\n")
except IndexError:
time.sleep(0.00001)
else:
for i in lines:
data = i.split(" ")
if(tmpBuffer != ""):
tmpBuffer += i
self.incomeBuffer.append(tmpBuffer)
tmpBuffer = ""
continue
if(len(data) < NUMBER_OF_VALUES):
tmpBuffer += i
else:
self.incomeBuffer.append(i)
try:
line = self.__incomeBuffer.popleft()
line = line.decode("UTF-8")
lines = line.split("\n")
except IndexError:
time.sleep(0.00001)
else:
for i in lines:
data = i.split(" ")
if(tmpBuffer != ""):
tmpBuffer += i
self.incomeBuffer.append(tmpBuffer)
tmpBuffer = ""
continue
if(len(data) < NUMBER_OF_VALUES):
tmpBuffer += i
else:
self.incomeBuffer.append(i)
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