Commit c8dabbff authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove 'address' argument from AcceptIdentification packet.

This argument is useless as the peer who receive this packet is the one who starts the connection, so it already knows the peer remote address.
Remove related (useless) checks and update unit tests.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1521 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 6445101c
......@@ -109,7 +109,7 @@ class BootstrapManager(EventHandler):
self.uuid, self.server, self.name))
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
"""
The primary master has accepted the node.
"""
......
......@@ -31,21 +31,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app.setNodeNotReady()
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
app = self.app
node = app.nm.getByAddress(conn.getAddress())
# this must be a master node
if node_type != NodeTypes.MASTER:
conn.close()
return
if conn.getAddress() != address:
# The server address is different! Then why was
# the connection successful?
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node)
conn.close()
return
conn.setUUID(uuid)
node.setUUID(uuid)
......
......@@ -53,21 +53,13 @@ class StorageBootstrapHandler(AnswerBaseHandler):
app.setNodeNotReady()
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
app = self.app
node = app.nm.getByAddress(conn.getAddress())
# this must be a storage node
if node_type != NodeTypes.STORAGE:
conn.close()
return
if conn.getAddress() != address:
# The server address is different! Then why was
# the connection successful?
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node)
conn.close()
return
conn.setUUID(uuid)
node.setUUID(uuid)
......
......@@ -142,11 +142,11 @@ class EventHandler(object):
# Packet handlers.
def requestIdentification(self, conn, packet, node_type,
uuid, address, name):
uuid, name):
raise UnexpectedPacketError
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
raise UnexpectedPacketError
def askPrimary(self, conn, packet):
......
......@@ -60,7 +60,7 @@ class PacketLogger(EventHandler):
pass
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
pass
def askPrimary(self, conn, packet):
......
......@@ -111,22 +111,12 @@ class ClientElectionHandler(ElectionHandler):
MasterHandler.peerBroken(self, conn)
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions,
num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
app = self.app
node = app.nm.getByAddress(conn.getAddress())
if node_type != NodeTypes.MASTER:
# The peer is not a master node!
logging.error('%s:%d is not a master node', *address)
app.nm.remove(node)
app.negotiating_master_node_set.discard(node.getAddress())
conn.close()
return
if conn.getAddress() != address:
# The server address is different! Then why was
# the connection successful?
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
logging.error('%s:%d is not a master node', conn.getAddress())
app.nm.remove(node)
app.negotiating_master_node_set.discard(node.getAddress())
conn.close()
......@@ -250,7 +240,6 @@ class ServerElectionHandler(ElectionHandler):
p = Packets.AcceptIdentification(
NodeTypes.MASTER,
app.uuid,
app.server,
app.pt.getPartitions(),
app.pt.getReplicas(),
uuid
......
......@@ -75,8 +75,8 @@ class IdentificationHandler(MasterHandler):
conn.setUUID(uuid)
conn.setHandler(handler)
# answer
args = (NodeTypes.MASTER, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid)
args = (NodeTypes.MASTER, app.uuid, app.pt.getPartitions(),
app.pt.getReplicas(), uuid)
conn.answer(Packets.AcceptIdentification(*args), packet.getId())
# trigger the event
handler.connectionCompleted(conn)
......
......@@ -84,12 +84,11 @@ class PrimaryHandler(MasterHandler):
n.setUUID(uuid)
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions,
uuid, num_partitions,
num_replicas, your_uuid):
app = self.app
node = app.nm.getByAddress(conn.getAddress())
assert node_type == NodeTypes.MASTER
assert conn.getAddress() == address
if your_uuid != app.uuid:
# uuid conflict happened, accept the new one
......
......@@ -321,23 +321,20 @@ class AcceptIdentification(Packet):
Accept a node identification. This should be a reply to Request Node
Identification. Any -> Any.
"""
def _encode(self, node_type, uuid, address,
def _encode(self, node_type, uuid,
num_partitions, num_replicas, your_uuid):
uuid = _encodeUUID(uuid)
your_uuid = _encodeUUID(your_uuid)
address = _encodeAddress(address)
return pack('!H16s6sLL16s', node_type, uuid, address,
return pack('!H16sLL16s', node_type, uuid,
num_partitions, num_replicas, your_uuid)
def _decode(self, body):
r = unpack('!H16s6sLL16s', body)
node_type, uuid, address, num_partitions, num_replicas, your_uuid = r
address = _decodeAddress(address)
r = unpack('!H16sLL16s', body)
node_type, uuid, num_partitions, num_replicas, your_uuid = r
node_type = _decodeNodeType(node_type)
uuid = _decodeUUID(uuid)
your_uuid == _decodeUUID(uuid)
return (node_type, uuid, address, num_partitions, num_replicas,
your_uuid)
return (node_type, uuid, num_partitions, num_replicas, your_uuid)
class AskPrimary(Packet):
"""
......
......@@ -47,7 +47,7 @@ class HiddenHandler(BaseMasterHandler):
pass
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
pass
def answerPrimary(self, conn, packet, primary_uuid,
......
......@@ -58,8 +58,8 @@ class IdentificationHandler(BaseStorageHandler):
conn.setHandler(handler)
conn.setUUID(uuid)
node.setUUID(uuid)
args = (NodeTypes.STORAGE, app.uuid, app.server,
app.pt.getPartitions(), app.pt.getReplicas(), uuid)
args = (NodeTypes.STORAGE, app.uuid, app.pt.getPartitions(),
app.pt.getReplicas(), uuid)
# accept the identification and trigger an event
conn.answer(Packets.AcceptIdentification(*args), packet.getId())
handler.connectionCompleted(conn)
......
......@@ -37,7 +37,7 @@ class ReplicationHandler(BaseStorageHandler):
self.app.replicator.reset()
def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid):
uuid, num_partitions, num_replicas, your_uuid):
# set the UUID on the connection
conn.setUUID(uuid)
......
......@@ -84,12 +84,10 @@ class ProtocolTests(NeoTestBase):
def test_12_AcceptIdentification(self):
uuid1, uuid2 = self.getNewUUID(), self.getNewUUID()
p = Packets.AcceptIdentification(NodeTypes.CLIENT, uuid1,
("127.0.0.1", 9080), 10, 20, uuid2)
node, p_uuid, (ip, port), nb_partitions, nb_replicas, your_uuid = p.decode()
10, 20, uuid2)
node, p_uuid, nb_partitions, nb_replicas, your_uuid = p.decode()
self.assertEqual(node, NodeTypes.CLIENT)
self.assertEqual(p_uuid, uuid1)
self.assertEqual(ip, "127.0.0.1")
self.assertEqual(port, 9080)
self.assertEqual(nb_partitions, 10)
self.assertEqual(nb_replicas, 20)
self.assertEqual(your_uuid, uuid2)
......
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