From ed53316f4f10cc3b4af7ac758836ac5d1100db6c Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 11 May 2006 22:19:52 -0400 Subject: [PATCH] Include the sender in the message --- p2p/Group.py | 2 +- p2p/StreamReader.py | 15 +++++++-------- p2p/StreamWriter.py | 6 ++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/p2p/Group.py b/p2p/Group.py index 70b8ec95..0b3c2828 100644 --- a/p2p/Group.py +++ b/p2p/Group.py @@ -71,7 +71,7 @@ class LocalGroup(Group): return self._services[(name, stype)] def get_buddy(self, name): - return self._buddy[name] + return self._buddies[name] def _add_buddy(self, buddy): bid = buddy.get_nick_name() diff --git a/p2p/StreamReader.py b/p2p/StreamReader.py index fedafccb..f8a45cb9 100644 --- a/p2p/StreamReader.py +++ b/p2p/StreamReader.py @@ -4,9 +4,9 @@ class StreamReaderRequestHandler(object): def __init__(self, reader): self._reader = reader - def message(self, message): + def message(self, nick_name, message): address = network.get_authinfo() - self._reader.recv(address[0], message) + self._reader.recv(nick_name, message) return True class StreamReader: @@ -33,10 +33,9 @@ class StreamReader: p2p_server.register_instance(StreamReaderRequestHandler(self)) def _recv_multicast(self, msg): - self._recv(msg['addr'], msg['data']) + [ nick_name, data ] = msg['data'].split(" |**| ", 2) + self._recv(nick_name, data) - def _recv(self, address, data): - owner = self._group.get_owner() - if address != owner.get_service().get_address(): - buddy = self._group.get_buddy_from_address(address) - self._callback(buddy, data) + def _recv(self, nick_name, data): + if nick_name != self._group.get_owner().get_nick_name(): + self._callback(self._group.get_buddy(nick_name), data) diff --git a/p2p/StreamWriter.py b/p2p/StreamWriter.py index 11183cd4..f30801ea 100644 --- a/p2p/StreamWriter.py +++ b/p2p/StreamWriter.py @@ -28,7 +28,8 @@ class StreamWriter: def _unicast_write(self, data): try: - self._uclient.message(data) + nick_name = self._group.get_owner().get_nick_name() + self._uclient.message(nick_name, data) return True except (socket.error, xmlrpclib.Fault, xmlrpclib.ProtocolError), e: traceback.print_exc() @@ -38,4 +39,5 @@ class StreamWriter: self._mclient = network.GroupClient(self._address, self._port) def _multicast_write(self, data): - self._mclient.send_msg(data) + nick_name = self._group.get_owner().get_nick_name() + self._mclient.send_msg(nick_name + " |**| " + data)