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

quick fix for socket-inputBackend

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