Commit 101d86b9 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[buckets] Send buckets config from server

Send the config when the client connects
parent a096137b
import struct
import plugin
class BucketsPlugin(plugin.Plugin):
Counterpart of the "buckets" plugin in the client. It does
analysis by hashing data into buckets by several statistics.
def __init__(self, plugins):
plugin.Plugin.__init__(self, plugins)
self.__bucket_count = 16
self.__hash_count = 4
self.__criteria_count = 1
self.__history_size = 1
# Just an arbitrary number
self.__seed = 872945724987
def name(self):
return "Buckets"
def client_connected(self, client):
Client has connected. Send the initial settings to
self.send('I' + self.__config(), client.cid())
def __config(self):
header = struct.pack('!4LQ', self.__bucket_count, self.__hash_count, self.__criteria_count, self.__history_sizet , self.__seed)
# TODO: Describe the criteria to gather
return header
......@@ -4,9 +4,11 @@ from twisted.internet.endpoints import TCP6ServerEndpoint
from client import ClientFactory
from plugin import Plugins
import count_plugin
import buckets_plugin
plugins = Plugins()
# Some configuration, to load the port from?
endpoint = TCP6ServerEndpoint(reactor, 5678)
......@@ -48,7 +48,16 @@ class Plugin:
Broadcast a message from this plugin to all the connected
self.__plugins.broadcast('R' + format_string( + message)
def send(self, message, to):
Send a message from this plugin to the client given by name.
self.__plugins.send(self.__routed_message(message), to)
def __routed_message(self, message):
return 'R' + format_string( + message
class Plugins:
......@@ -94,6 +103,13 @@ class Plugins:
for c in self.__clients.values():
def send(self, message, to):
Send a message to the named client.
# TODO: Client of that name might not exist
def route_to_plugin(self, name, message, client):
Forward a message to plugin of given name. Pass the name
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