Commit 686bfb78 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[master] Skeleton of the count plugin

Create the plugin and let it ask for data from time to time. The data
aren't parsed yet, nor processed.
parent cc00088a
......@@ -14,7 +14,7 @@ class ClientConn(twisted.protocols.basic.Int32StringReceiver):
self.__addr = addr
self.__pings_outstanding = 0
def ping(self):
def __ping(self):
Send a ping every now and then, to see the client is
still alive. If it didn't answer many times, drop the
......@@ -27,7 +27,7 @@ class ClientConn(twisted.protocols.basic.Int32StringReceiver):
def connectionMade(self):
print("Connection made from " + str(self.__addr))
self.__pinger = LoopingCall(
self.__pinger = LoopingCall(self.__ping)
self.__pinger.start(5, False)
......@@ -3,8 +3,10 @@ from twisted.internet import reactor
from twisted.internet.endpoints import TCP6ServerEndpoint
from client import ClientFactory
from plugin import Plugins
import count_plugin
plugins = Plugins() # Just a placeholder for now
plugins = Plugins()
# Some configuration, to load the port from?
endpoint = TCP6ServerEndpoint(reactor, 5678)
from twisted.internet.task import LoopingCall
from twisted.internet import reactor
import plugin
class CountPlugin(plugin.Plugin):
The plugin providing basic statisticts, like speed, number of
dropped packets, etc.
def __init__(self, plugins):
plugin.Plugin.__init__(self, plugins)
self.__downloader = LoopingCall(self.__init_download)
self.__downloader.start(5, False)
self.__data = {}
self.__stats = {}
def __init_download(self):
Ask all the clients to send their statistics.
# Wait a short time, so they can send us some data and process it after that.
self.__data = {}
self.__stats = {}
reactor.callLater(1, self.__process)
def __process(self):
def name(self):
return 'Count'
from protocol import format_string
class Plugin:
Base class of a plugin. Use this when writing new plugins. Provides
......@@ -39,6 +41,12 @@ class Plugin:
def broadcast(self, message):
Broadcast a message from this plugin to all the connected
self.__plugins.broadcast('R' + format_string( + message)
class Plugins:
......@@ -76,3 +84,10 @@ class Plugins:
for p in self.__plugins.values():
del self.__clients[client.cid()]
def broadcast(self, message):
Send a message to all the connected clients.
for c in self.__clients.values():
import struct
def format_string(string):
length = len(string)
return struct.pack('!L' + str(length) + 's', length, string)
Supports Markdown
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